/**
* Copyright 2004 Sun Microsystems, Inc. All
* rights reserved. Use of this product is subject
* to license terms. Federal Acquisitions:
* Commercial Software -- Government Users
* Subject to Standard License Terms and
* Conditions.
*
* Sun, Sun Microsystems, the Sun logo, and Sun ONE
* are trademarks or registered trademarks of Sun Microsystems,
* Inc. in the United States and other countries.
*/
package com.sun.portal.admin.cli.commands.communities;
import java.io.*;
import java.lang.*;
import java.util.*;
import java.text.*;
// JMX
import javax.management.MBeanServerConnection;
import javax.management.ObjectName;
import javax.management.InstanceNotFoundException;
import javax.management.MBeanException;
import javax.management.ReflectionException;
import javax.management.MalformedObjectNameException;
// PS Admin Common
import com.sun.portal.admin.common.util.AdminClientUtil;
// CLI framework
import com.sun.enterprise.cli.framework.*;
// Base Class
import com.sun.portal.admin.cli.commands.GenericCommand;
/**
* This class implements the psadmin modify-community
* subcommand. The modify-community subcommand calls
* the CommunityManagerMBean and modifies a community.
*/
public class ModifyCommunityCommand extends GenericCommand {
private String method = "";
/**
* An abstract method that executes the command
* @throws CommandException
* @throws CommandValidationException
*/
public void runCommand() throws CommandException, CommandValidationException {
validateOptions();
validatePortalId();
try {
String name = getOption("name");
LinkedList path = new LinkedList();
path.addFirst(AdminClientUtil.DEFAULT_DOMAIN);
path.addFirst(getPortalId());
path.addFirst("CommunityManager");
ObjectName on = AdminClientUtil.getResourceMBeanObjectName(AdminClientUtil.COMMUNITYMANAGER_MBEAN_TYPE, path);
MBeanServerConnection mbsc = getMBeanServerConnection(getUserId(), getPassword(), getHost());
method = "getCommunity";
Object[] params1 = {name};
String[] signatures1 = {"java.lang.String"};
Properties p = (Properties)mbsc.invoke(on, method, params1, signatures1);
String newDescription = getOption("newdescription");
if (newDescription != null) {
p.setProperty("description", newDescription);
}
String newCategory = getOption("newcategory");
if (newCategory != null) {
p.setProperty("category", newCategory);
}
String newUnlisted = getOption("newunlisted");
if (newUnlisted != null) {
p.setProperty("unlisted", newUnlisted);
}
String newMembershipRestricted = getOption("newmembershiprestricted");
if (newMembershipRestricted != null) {
p.setProperty("membershiprestricted", newMembershipRestricted);
}
String newSecure = getOption("newsecured");
if (newSecure != null) {
p.setProperty("secured", newSecure);
}
method = "setCommunity";
Object[] params2 = {name, p};
String[] signatures2 = {"java.lang.String", "java.util.Properties"};
mbsc.invoke(on, method, params2, signatures2);
} catch (InstanceNotFoundException ie) {
throw new CommandException(getLocalizedString(ERROR_MBEAN_INSTANCE_NOT_FOUND, new Object[] {method}), ie);
} catch (MBeanException me) {
throw new CommandException(getLocalizedString(ERROR_JMX_INVOKE, new Object[] {method}), me);
} catch (ReflectionException re) {
throw new CommandException(getLocalizedString(ERROR_MBEAN_REFLECTION_ERROR, new Object[] {method}), re);
} catch (CommandException ce) {
throw ce;
} catch (Exception e) {
throw new CommandException(getLocalizedString(COMMAND_FAILED), e);
} finally {
closeMBeanServerConnection();
}
}
}
|