001: /**
002: * $Id: CreateConfiguredProducerCommand.java,v 1.5 2006/02/14 21:20:28 pa157442 Exp $
003: * Copyright 2004 Sun Microsystems, Inc. All
004: * rights reserved. Use of this product is subject
005: * to license terms. Federal Acquisitions:
006: * Commercial Software -- Government Users
007: * Subject to Standard License Terms and
008: * Conditions.
009: *
010: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
011: * are trademarks or registered trademarks of Sun Microsystems,
012: * Inc. in the United States and other countries.
013: */package com.sun.portal.admin.cli.commands.wsrp;
014:
015: //CLI framework
016: import com.sun.enterprise.cli.framework.*;
017:
018: //JMX
019: import javax.management.MBeanServerConnection;
020: import javax.management.ObjectName;
021: import javax.management.MBeanException;
022: import javax.management.ReflectionException;
023: import javax.management.MalformedObjectNameException;
024: import javax.management.InstanceNotFoundException;
025:
026: //PS Admin Common
027: import com.sun.portal.admin.common.PSMBeanException;
028: import com.sun.portal.admin.common.util.AdminClientUtil;
029:
030: import com.sun.portal.admin.cli.commands.GenericCommand;
031:
032: import java.util.List;
033: import java.util.Set;
034: import java.util.SortedSet;
035: import java.util.TreeSet;
036: import java.util.Iterator;
037: import java.util.LinkedList;
038: import java.util.Properties;
039: import java.util.logging.Level;
040:
041: import java.io.FileInputStream;
042:
043: import java.util.logging.Logger;
044: import java.util.logging.Level;
045:
046: public class CreateConfiguredProducerCommand extends GenericCommand {
047:
048: public static final String OPT_DN = "dn";
049: public static final String OPT_PRODUCER = "producer";
050: public static final String OPT_URL = "url";
051: public static final String OPT_REGISTRATIONDATA = "registrationdata";
052: public static final String OPT_REGISTRATIONHANDLE = "registrationhandle";
053: // public static final String PRODUCER_EXISTS_LABEL = "wsrp.consumer.error.create-configured-producer.producer.exists";
054:
055: //param to be passed to mbean
056: private String dn = null;
057: private String producerName = null;
058: private String producerUrl = null;
059: private String registrationData = null;
060: private String registrationHandle = null;
061:
062: public boolean validateOptions() throws CommandValidationException {
063: return super .validateOptions();
064: }
065:
066: public void runCommand() throws CommandException,
067: CommandValidationException {
068: Properties regData = null;
069: Object[] params = null;
070: String[] signature = null;
071:
072: if (!validateOptions()) {
073: throw new CommandValidationException(
074: getLocalizedString(ERROR_OPTION_VALIDATION_FAILED));
075: }
076:
077: String portalId = getOption(OPT_PORTAL_ID);
078: if (portalId != null) {
079: validatePortalId();
080: }
081:
082: MBeanServerConnection mbsc = getMBeanServerConnection(
083: getUserId(), getPassword(), getHost());
084:
085: try {
086:
087: dn = getOption(OPT_DN);
088: producerName = getOption(OPT_PRODUCER);
089: producerUrl = getOption(OPT_URL);
090: registrationData = getOption(OPT_REGISTRATIONDATA);
091: registrationHandle = getOption(OPT_REGISTRATIONHANDLE);
092:
093: if (registrationData != null
094: && registrationData.length() > 0) {
095: regData = new Properties();
096: regData.load(new FileInputStream(registrationData));
097: }
098:
099: LinkedList path = new LinkedList();
100: path.addFirst(getDomainId());
101: path.addFirst(getPortalId());
102: path.addFirst("Consumer");
103:
104: ObjectName objectName = AdminClientUtil
105: .getResourceMBeanObjectName(
106: "PortalDomain.Portal.Consumer", path);
107:
108: if (registrationHandle != null
109: && registrationHandle.length() > 0) {
110: // Setting the params and signature
111: params = new Object[] { dn, producerName, producerUrl,
112: registrationHandle };
113: signature = new String[] { "java.lang.String",
114: "java.lang.String", "java.lang.String",
115: "java.lang.String" };
116: } else {
117: // Setting the params and signature
118: params = new Object[] { dn, producerName, producerUrl,
119: regData };
120: signature = new String[] { "java.lang.String",
121: "java.lang.String", "java.lang.String",
122: "java.util.Properties" };
123: }
124:
125: mbsc.invoke(objectName, "createConfiguredProducer", params,
126: signature);
127:
128: } catch (InstanceNotFoundException ie) {
129: throw new CommandException(getLocalizedString(
130: ERROR_MBEAN_INSTANCE_NOT_FOUND,
131: new Object[] { "createConfiguredProducer" }), ie);
132: } catch (MBeanException me) {
133: boolean psmbe = me.getCause() instanceof PSMBeanException;
134: if (getBooleanOption(OPT_DEBUG)) {
135: if (psmbe) {
136: String dbgMsg = me.getCause().getMessage();
137: if (dbgMsg != null) {
138: CLILogger.getInstance().printMessage(dbgMsg);
139: }
140: }
141: }
142: if (psmbe) {
143: PSMBeanException pme = (PSMBeanException) me.getCause();
144: if (((PSMBeanException) me.getCause()).getTokens() != null) {
145: throw new CommandException(getLocalizedString(pme
146: .getErrorKey(), pme.getTokens()), pme);
147: } else {
148: throw new CommandException(getLocalizedString(pme
149: .getErrorKey()), me);
150: }
151: } else {
152: throw new CommandException(getLocalizedString(
153: ERROR_JMX_INVOKE,
154: new Object[] { "createConfiguredProducer" }),
155: me);
156: }
157: } catch (ReflectionException re) {
158: throw new CommandException(getLocalizedString(
159: ERROR_MBEAN_REFLECTION_ERROR,
160: new Object[] { "createConfiguredProducer" }), re);
161: } catch (Exception ex) {
162:
163: logger.log(Level.SEVERE, "PSALI_CSPACCW0001", ex);
164:
165: throw new CommandException(getLocalizedString(
166: COMMAND_FAILED, new Object[] { name }), ex);
167: } finally {
168: closeMBeanServerConnection();
169: }
170: }
171:
172: }
|