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 list-community-users
038: * subcommand. The list-community-users subcommand calls
039: * the CommunityManagerMBean and lists users for a community.
040: */
041: public class ListCommunityUsersCommand extends GenericCommand {
042:
043: private String method = "getCommunityUsers";
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: ArrayList data = (ArrayList) mbsc.invoke(on, method,
073: params, signatures);
074: for (int index = 0; index < data.size(); index++) {
075: Properties p = (Properties) data.get(index);
076: sb.append(p.getProperty("dn") + " - "
077: + p.getProperty("roles") + "\n");
078: }
079: } catch (InstanceNotFoundException ie) {
080: throw new CommandException(getLocalizedString(
081: ERROR_MBEAN_INSTANCE_NOT_FOUND,
082: new Object[] { method }), ie);
083: } catch (MBeanException me) {
084: throw new CommandException(getLocalizedString(
085: ERROR_JMX_INVOKE, new Object[] { method }), me);
086: } catch (ReflectionException re) {
087: throw new CommandException(getLocalizedString(
088: ERROR_MBEAN_REFLECTION_ERROR,
089: new Object[] { method }), re);
090: } catch (CommandException ce) {
091: throw ce;
092: } catch (Exception e) {
093: throw new CommandException(
094: getLocalizedString(COMMAND_FAILED), e);
095: } finally {
096: closeMBeanServerConnection();
097: }
098:
099: CLILogger.getInstance().printMessage(sb.toString());
100: }
101:
102: }
|