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