001: /*
002: * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
003: * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
004: */
005: package com.sun.portal.admin.cli.commands.search;
006:
007: import java.util.*;
008: import java.util.logging.Logger;
009: import java.util.logging.Level;
010:
011: import javax.management.MBeanServerConnection;
012: import javax.management.ObjectName;
013: import javax.management.InstanceNotFoundException;
014: import javax.management.MBeanException;
015: import javax.management.ReflectionException;
016: import javax.management.MalformedObjectNameException;
017: import javax.management.Attribute;
018:
019: import com.sun.enterprise.cli.framework.*;
020:
021: import com.sun.portal.admin.cli.commands.GenericCommand;
022: import com.sun.portal.admin.common.util.AdminUtil;
023:
024: /**
025: * This class implements the psadmin disable-robot-converter subcommand. The
026: * disable-robot-converter subcommand calls the PortalDomainMBean and performs
027: * the following tasks:
028: * <UL>
029: * <LI>disable robot converter properties
030: * <UL>
031: */
032:
033: public class DisableRobotConverterCommand extends GenericCommand {
034:
035: //public Logger logger = super.getLogger();
036:
037: //command error messages
038: public static final String ERROR_OPTION_NOT_FOUND = "error.psadmin.robot.converter.option.not.found";
039: public static final String ERROR_ID_INVALID = "error.psadmin.robot.option.id.invalid";
040:
041: //command options
042: private static final String CONVERTER = "converter";
043:
044: String converterID;
045:
046: public void runCommand() throws CommandException,
047: CommandValidationException {
048: validateOptions();
049: validateSearchServerID();
050:
051: converterID = getOption(CONVERTER);
052:
053: if (converterID.equals("0")) {
054: throw new CommandValidationException(
055: getLocalizedString(ERROR_ID_INVALID));
056: }
057:
058: try {
059: LinkedList path = new LinkedList();
060: path.addFirst(getDomainId());
061: path.addFirst(getSearchServerId());
062: path.addFirst("robot");
063: ObjectName objName = AdminUtil.getResourceMBeanObjectName(
064: AdminUtil.SEARCH_ROBOT_MBEAN_TYPE, path);
065:
066: MBeanServerConnection msc = getMBeanServerConnection(
067: getUserId(), getPassword(), getHost());
068:
069: if (!converterID.equals("")) {
070: int cid = Integer.parseInt(converterID) - 1;
071: converterID = Integer.toString(cid);
072: Object[] params = { converterID, "no" };
073: String[] signature = { "java.lang.String",
074: "java.lang.String" };
075: msc.invoke(objName, "setConverter", params, signature);
076: }
077:
078: } catch (InstanceNotFoundException ie) {
079: //logger.logp(Level.SEVERE, "DisableRobotConverterCommand",
080: // "runCommand()", ie.getMessage(), ie);
081: logger.log(Level.SEVERE, "PSALI_CSPACCSH0003", ie);
082: throw new CommandException(getLocalizedString(
083: ERROR_MBEAN_INSTANCE_NOT_FOUND,
084: new Object[] { "setConverter" }), ie);
085: } catch (MBeanException me) {
086: //logger.logp(Level.SEVERE, "DisableRobotConverterCommand",
087: // "runCommand()", me.getMessage(), me);
088: logger.log(Level.SEVERE, "PSALI_CSPACCSH0003", me);
089: throw new CommandException(getLocalizedString(
090: ERROR_JMX_INVOKE, new Object[] { "setConverter" }),
091: me);
092: } catch (ReflectionException re) {
093: //logger.logp(Level.SEVERE, "DisableRobotConverterCommand",
094: // "runCommand()", re.getMessage(), re);
095: logger.log(Level.SEVERE, "PSALI_CSPACCSH0003", re);
096: throw new CommandException(getLocalizedString(
097: ERROR_MBEAN_REFLECTION_ERROR,
098: new Object[] { "setConverter" }), re);
099: } catch (CommandException ce) {
100: //logger.logp(Level.SEVERE, "DisableRobotConverterCommand",
101: // "runCommand()", ce.getMessage(), ce);
102: logger.log(Level.SEVERE, "PSALI_CSPACCSH0003", ce);
103: throw ce;
104: } catch (Exception ex) {
105: ex.printStackTrace();
106: //logger.logp(Level.SEVERE, "DisableRobotConverterCommand",
107: // "runCommand()", ex.getMessage(), ex);
108: logger.log(Level.SEVERE, "PSALI_CSPACCSH0003", ex);
109: throw new CommandException(
110: getLocalizedString(COMMAND_FAILED), ex);
111: } finally {
112: closeMBeanServerConnection();
113: }
114: }
115:
116: }
|