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 get-community
038: * subcommand. The get-community subcommand calls
039: * the CommunityManagerMBean and lists community attributes.
040: */
041: public class GetCommunityCommand extends GenericCommand {
042:
043: private String method = "getCommunity";
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: StringBuffer sb = new StringBuffer();
056:
057: try {
058: String name = getOption("name");
059:
060: LinkedList path = new LinkedList();
061: path.addFirst(AdminClientUtil.DEFAULT_DOMAIN);
062: path.addFirst(getPortalId());
063: path.addFirst("CommunityManager");
064: ObjectName on = AdminClientUtil.getResourceMBeanObjectName(
065: AdminClientUtil.COMMUNITYMANAGER_MBEAN_TYPE, path);
066:
067: MBeanServerConnection mbsc = getMBeanServerConnection(
068: getUserId(), getPassword(), getHost());
069:
070: Object[] params = { name };
071: String[] signatures = { "java.lang.String" };
072: Properties p = (Properties) mbsc.invoke(on, method, params,
073: signatures);
074:
075: sb.append(getLocalizedString("communities.name",
076: new Object[] { p.getProperty("name") }));
077: sb.append(getLocalizedString("communities.description",
078: new Object[] { p.getProperty("description") }));
079: sb.append(getLocalizedString("communities.category",
080: new Object[] { p.getProperty("category") }));
081: if (p.getProperty("unlisted").equals("true")) {
082: sb.append(getLocalizedString("communities.unlisted"));
083: }
084: if (p.getProperty("membershiprestricted").equals("true")) {
085: sb
086: .append(getLocalizedString("communities.membershiprestricted"));
087: }
088: if (p.getProperty("secured").equals("true")) {
089: sb.append(getLocalizedString("communities.secured"));
090: }
091: if (p.getProperty("disabled").equals("true")) {
092: sb.append(getLocalizedString("communities.disabled"));
093: }
094: if (p.getProperty("deleted").equals("true")) {
095: sb.append(getLocalizedString("communities.deleted"));
096: }
097: sb.append(getLocalizedString("communities.users",
098: new Object[] { p.getProperty("users") }));
099: } catch (InstanceNotFoundException ie) {
100: throw new CommandException(getLocalizedString(
101: ERROR_MBEAN_INSTANCE_NOT_FOUND,
102: new Object[] { method }), ie);
103: } catch (MBeanException me) {
104: throw new CommandException(getLocalizedString(
105: ERROR_JMX_INVOKE, new Object[] { method }), me);
106: } catch (ReflectionException re) {
107: throw new CommandException(getLocalizedString(
108: ERROR_MBEAN_REFLECTION_ERROR,
109: new Object[] { method }), re);
110: } catch (CommandException ce) {
111: throw ce;
112: } catch (Exception e) {
113: throw new CommandException(
114: getLocalizedString(COMMAND_FAILED), e);
115: } finally {
116: closeMBeanServerConnection();
117: }
118:
119: CLILogger.getInstance().printMessage(sb.toString());
120: }
121:
122: }
|