01: /**
02: * Copyright 2004 Sun Microsystems, Inc. All
03: * rights reserved. Use of this product is subject
04: * to license terms. Federal Acquisitions:
05: * Commercial Software -- Government Users
06: * Subject to Standard License Terms and
07: * Conditions.
08: *
09: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
10: * are trademarks or registered trademarks of Sun Microsystems,
11: * Inc. in the United States and other countries.
12: */package com.sun.portal.admin.cli.commands.communities;
13:
14: import java.io.*;
15: import java.lang.*;
16: import java.util.*;
17: import java.text.*;
18:
19: // JMX
20: import javax.management.MBeanServerConnection;
21: import javax.management.ObjectName;
22: import javax.management.InstanceNotFoundException;
23: import javax.management.MBeanException;
24: import javax.management.ReflectionException;
25: import javax.management.MalformedObjectNameException;
26:
27: // PS Admin Common
28: import com.sun.portal.admin.common.util.AdminClientUtil;
29:
30: // CLI framework
31: import com.sun.enterprise.cli.framework.*;
32:
33: // Base Class
34: import com.sun.portal.admin.cli.commands.GenericCommand;
35:
36: /**
37: * This class implements the psadmin list-community-dps
38: * subcommand. The list-community-dps subcommand calls
39: * the CommunityManagerMBean and lists all community dps.
40: */
41: public class ListCommunityDPsCommand extends GenericCommand {
42:
43: private String method = "retrieveAvailableCommunityDPs";
44:
45: /**
46: * An abstract method that executes the command
47: * @throws CommandException
48: * @throws CommandValidationException
49: */
50: public void runCommand() throws CommandException,
51: CommandValidationException {
52: validateOptions();
53: validatePortalId();
54:
55: StringBuffer sb = new StringBuffer();
56:
57: try {
58: LinkedList path = new LinkedList();
59: path.addFirst(AdminClientUtil.DEFAULT_DOMAIN);
60: path.addFirst(getPortalId());
61: path.addFirst("CommunityManager");
62: ObjectName on = AdminClientUtil.getResourceMBeanObjectName(
63: AdminClientUtil.COMMUNITYMANAGER_MBEAN_TYPE, path);
64:
65: MBeanServerConnection mbsc = getMBeanServerConnection(
66: getUserId(), getPassword(), getHost());
67:
68: Object[] params = {};
69: String[] signatures = {};
70: ArrayList data = (ArrayList) mbsc.invoke(on, method,
71: params, signatures);
72: sb.append("\n");
73: for (int index = 0; index < data.size(); index++) {
74: sb.append((String) data.get(index) + "\n");
75: }
76: } catch (InstanceNotFoundException ie) {
77: throw new CommandException(getLocalizedString(
78: ERROR_MBEAN_INSTANCE_NOT_FOUND,
79: new Object[] { method }), ie);
80: } catch (MBeanException me) {
81: throw new CommandException(getLocalizedString(
82: ERROR_JMX_INVOKE, new Object[] { method }), me);
83: } catch (ReflectionException re) {
84: throw new CommandException(getLocalizedString(
85: ERROR_MBEAN_REFLECTION_ERROR,
86: new Object[] { method }), re);
87: } catch (CommandException ce) {
88: throw ce;
89: } catch (Exception e) {
90: throw new CommandException(
91: getLocalizedString(COMMAND_FAILED), e);
92: } finally {
93: closeMBeanServerConnection();
94: }
95:
96: CLILogger.getInstance().printMessage(sb.toString());
97: }
98:
99: }
|