001: /**
002: * Copyright 2004 Sun Microsystems, Inc. All
003: * rights reserved. Use of this product is subject
004: * to license terms. Federal Acquisitions:
005: * Commercial Software -- Government Users
006: * Subject to Standard License Terms and
007: * Conditions.
008: *
009: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
010: * are trademarks or registered trademarks of Sun Microsystems,
011: * Inc. in the United States and other countries.
012: */package com.sun.portal.admin.cli.commands.communities;
013:
014: import java.io.*;
015: import java.lang.*;
016: import java.util.*;
017: import java.text.*;
018:
019: // JMX
020: import javax.management.MBeanServerConnection;
021: import javax.management.ObjectName;
022: import javax.management.InstanceNotFoundException;
023: import javax.management.MBeanException;
024: import javax.management.ReflectionException;
025: import javax.management.MalformedObjectNameException;
026:
027: // PS Admin Common
028: import com.sun.portal.admin.common.util.AdminClientUtil;
029:
030: // CLI framework
031: import com.sun.enterprise.cli.framework.*;
032:
033: // Base Class
034: import com.sun.portal.admin.cli.commands.GenericCommand;
035:
036: /**
037: * This class implements the psadmin modify-community
038: * subcommand. The modify-community subcommand calls
039: * the CommunityManagerMBean and modifies a community.
040: */
041: public class ModifyCommunityCommand extends GenericCommand {
042:
043: private String method = "";
044:
045: /**
046: * An abstract method that executes the command
047: * @throws CommandException
048: * @throws CommandValidationException
049: */
050: public void runCommand() throws CommandException,
051: CommandValidationException {
052: validateOptions();
053: validatePortalId();
054:
055: try {
056: String name = getOption("name");
057:
058: LinkedList path = new LinkedList();
059: path.addFirst(AdminClientUtil.DEFAULT_DOMAIN);
060: path.addFirst(getPortalId());
061: path.addFirst("CommunityManager");
062: ObjectName on = AdminClientUtil.getResourceMBeanObjectName(
063: AdminClientUtil.COMMUNITYMANAGER_MBEAN_TYPE, path);
064:
065: MBeanServerConnection mbsc = getMBeanServerConnection(
066: getUserId(), getPassword(), getHost());
067:
068: method = "getCommunity";
069: Object[] params1 = { name };
070: String[] signatures1 = { "java.lang.String" };
071: Properties p = (Properties) mbsc.invoke(on, method,
072: params1, signatures1);
073:
074: String newDescription = getOption("newdescription");
075: if (newDescription != null) {
076: p.setProperty("description", newDescription);
077: }
078: String newCategory = getOption("newcategory");
079: if (newCategory != null) {
080: p.setProperty("category", newCategory);
081: }
082: String newUnlisted = getOption("newunlisted");
083: if (newUnlisted != null) {
084: p.setProperty("unlisted", newUnlisted);
085: }
086: String newMembershipRestricted = getOption("newmembershiprestricted");
087: if (newMembershipRestricted != null) {
088: p.setProperty("membershiprestricted",
089: newMembershipRestricted);
090: }
091: String newSecure = getOption("newsecured");
092: if (newSecure != null) {
093: p.setProperty("secured", newSecure);
094: }
095:
096: method = "setCommunity";
097: Object[] params2 = { name, p };
098: String[] signatures2 = { "java.lang.String",
099: "java.util.Properties" };
100: mbsc.invoke(on, method, params2, signatures2);
101: } catch (InstanceNotFoundException ie) {
102: throw new CommandException(getLocalizedString(
103: ERROR_MBEAN_INSTANCE_NOT_FOUND,
104: new Object[] { method }), ie);
105: } catch (MBeanException me) {
106: throw new CommandException(getLocalizedString(
107: ERROR_JMX_INVOKE, new Object[] { method }), me);
108: } catch (ReflectionException re) {
109: throw new CommandException(getLocalizedString(
110: ERROR_MBEAN_REFLECTION_ERROR,
111: new Object[] { method }), re);
112: } catch (CommandException ce) {
113: throw ce;
114: } catch (Exception e) {
115: throw new CommandException(
116: getLocalizedString(COMMAND_FAILED), e);
117: } finally {
118: closeMBeanServerConnection();
119: }
120: }
121:
122: }
|