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 create-community
038: * subcommand. The create-community subcommand calls
039: * the CommunityManagerMBean and creates a community.
040: */
041: public class CreateCommunityCommand 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: LinkedList path = new LinkedList();
057: path.addFirst(AdminClientUtil.DEFAULT_DOMAIN);
058: path.addFirst(getPortalId());
059: path.addFirst("CommunityManager");
060: ObjectName on = AdminClientUtil.getResourceMBeanObjectName(
061: AdminClientUtil.COMMUNITYMANAGER_MBEAN_TYPE, path);
062:
063: MBeanServerConnection mbsc = getMBeanServerConnection(
064: getUserId(), getPassword(), getHost());
065:
066: String name = getOption("name");
067:
068: String description = getOption("description");
069: if (description == null) {
070: description = "";
071: }
072:
073: String owner = getOption("owner");
074:
075: String category = getOption("category");
076: if (category == null) {
077: category = "";
078: }
079:
080: String template = getOption("template");
081:
082: String unlisted = getOption("unlisted");
083: if (unlisted == null) {
084: unlisted = "false";
085: }
086:
087: String membershipRestricted = getOption("membershiprestricted");
088: if (membershipRestricted == null) {
089: membershipRestricted = "false";
090: }
091:
092: String secure = getOption("secured");
093: if (secure == null) {
094: secure = "false";
095: }
096:
097: method = "createCommunity";
098: Object[] params = { name, description, owner, category,
099: template, unlisted, membershipRestricted, secure };
100: String[] signatures = { "java.lang.String",
101: "java.lang.String", "java.lang.String",
102: "java.lang.String", "java.lang.String",
103: "java.lang.String", "java.lang.String",
104: "java.lang.String" };
105: mbsc.invoke(on, method, params, signatures);
106: } catch (InstanceNotFoundException ie) {
107: throw new CommandException(getLocalizedString(
108: ERROR_MBEAN_INSTANCE_NOT_FOUND,
109: new Object[] { method }), ie);
110: } catch (MBeanException me) {
111: throw new CommandException(getLocalizedString(
112: ERROR_JMX_INVOKE, new Object[] { method }), me);
113: } catch (ReflectionException re) {
114: throw new CommandException(getLocalizedString(
115: ERROR_MBEAN_REFLECTION_ERROR,
116: new Object[] { method }), re);
117: } catch (CommandException ce) {
118: throw ce;
119: } catch (Exception e) {
120: throw new CommandException(
121: getLocalizedString(COMMAND_FAILED), e);
122: } finally {
123: closeMBeanServerConnection();
124: }
125: }
126:
127: }
|