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