001: /**
002: * $Id: UpdateServiceDescriptionCommand.java,v 1.3 2005/11/07 17:40:31 cathywu 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:
039: public class UpdateServiceDescriptionCommand extends GenericCommand {
040:
041: public static final String OPT_DN = "dn";
042: public static final String OPT_PRODUCER = "producer";
043: public static final String NO_PRODUCER_LABEL = "wsrp.consumer.error.update-service-description.noproducer";
044:
045: //param to be passed to mbean
046: private String dn = null;
047: private String producerId = null;
048:
049: public boolean validateOptions() throws CommandValidationException {
050: return super .validateOptions();
051: }
052:
053: public void runCommand() throws CommandException,
054: CommandValidationException {
055: if (!validateOptions()) {
056: throw new CommandValidationException(
057: getLocalizedString(ERROR_OPTION_VALIDATION_FAILED));
058: }
059:
060: String portalId = getOption(OPT_PORTAL_ID);
061: if (portalId != null) {
062: validatePortalId();
063: }
064:
065: MBeanServerConnection mbsc = getMBeanServerConnection(
066: getUserId(), getPassword(), getHost());
067:
068: try {
069:
070: dn = getOption(OPT_DN);
071: producerId = getOption(OPT_PRODUCER);
072:
073: // Setting the params and signature
074: Object[] params = { dn, producerId };
075: String[] signature = { "java.lang.String",
076: "java.lang.String" };
077:
078: LinkedList path = new LinkedList();
079: path.addFirst(getDomainId());
080: path.addFirst(getPortalId());
081: path.addFirst("Consumer");
082: path.addFirst(producerId);
083:
084: ObjectName objectName = AdminClientUtil
085: .getResourceMBeanObjectName(
086: "PortalDomain.Portal.Consumer.ConfiguredProducer",
087: path);
088:
089: mbsc.invoke(objectName, "updateServiceDescription", params,
090: signature);
091:
092: } catch (InstanceNotFoundException ie) {
093: throw new CommandException(getLocalizedString(
094: ERROR_MBEAN_INSTANCE_NOT_FOUND,
095: new Object[] { "updateServiceDescription" }), ie);
096: } catch (MBeanException me) {
097: boolean psmbe = me.getCause() instanceof PSMBeanException;
098: if (getBooleanOption(OPT_DEBUG)) {
099: if (psmbe) {
100: String dbgMsg = me.getCause().getMessage();
101: if (dbgMsg != null) {
102: CLILogger.getInstance().printMessage(dbgMsg);
103: }
104: }
105: }
106: if ((psmbe)
107: && ((PSMBeanException) me.getCause()).getErrorKey()
108: .equals(NO_PRODUCER_LABEL)) {
109: String msg = me.getCause().getMessage();
110: if (msg != null) {
111: CLILogger.getInstance().printMessage(msg);
112: }
113: }
114: if (psmbe) {
115: throw new CommandException(
116: getLocalizedString(((PSMBeanException) me
117: .getCause()).getErrorKey()), me);
118: } else {
119: throw new CommandException(getLocalizedString(
120: ERROR_JMX_INVOKE,
121: new Object[] { "updateServiceDescription" }),
122: me);
123: }
124: } catch (ReflectionException re) {
125: throw new CommandException(getLocalizedString(
126: ERROR_MBEAN_REFLECTION_ERROR,
127: new Object[] { "updateServiceDescription" }), re);
128: } catch (Exception ex) {
129: throw new CommandException(
130: getLocalizedString(COMMAND_FAILED), ex);
131: } finally {
132: closeMBeanServerConnection();
133: }
134: }
135:
136: }
|