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-converters subcommand. The
026: * disable-robot-converters subcommand calls the PortalDomainMBean and performs
027: * the following tasks:
028: * <UL>
029: * <LI>disable robot converters properties
030: * <UL>
031: */
032:
033: public class DisableRobotConvertersCommand extends GenericCommand {
034:
035: //command error messages
036:
037: //command options
038:
039: List converterIDs;
040:
041: public void runCommand() throws CommandException,
042: CommandValidationException {
043: validateOptions();
044: validateSearchServerID();
045:
046: converterIDs = getMultiValueOption("converters");
047:
048: try {
049: LinkedList path = new LinkedList();
050: path.addFirst(getDomainId());
051: path.addFirst(getSearchServerId());
052: path.addFirst("robot");
053: ObjectName objName = AdminUtil.getResourceMBeanObjectName(
054: AdminUtil.SEARCH_ROBOT_MBEAN_TYPE, path);
055:
056: MBeanServerConnection msc = getMBeanServerConnection(
057: getUserId(), getPassword(), getHost());
058:
059: for (int i = 0; i < converterIDs.size(); i++) {
060: int cid = Integer
061: .parseInt((String) converterIDs.get(i)) - 1;
062: String converterID = Integer.toString(cid);
063: Object[] params = { converterID, "no" };
064: String[] signature = { "java.lang.String",
065: "java.lang.String" };
066: msc.invoke(objName, "setConverter", params, signature);
067: }
068:
069: } catch (InstanceNotFoundException ie) {
070: //logger.logp(Level.SEVERE, "DisableRobotConvertersCommand",
071: // "runCommand()", ie.getMessage(), ie);
072: logger.log(Level.SEVERE, "PSALI_CSPACCSH0003", ie);
073: throw new CommandException(getLocalizedString(
074: ERROR_MBEAN_INSTANCE_NOT_FOUND,
075: new Object[] { "setConverter" }), ie);
076: } catch (MBeanException me) {
077: //logger.logp(Level.SEVERE, "DisableRobotConvertersCommand",
078: // "runCommand()", me.getMessage(), me);
079: logger.log(Level.SEVERE, "PSALI_CSPACCSH0003", me);
080: throw new CommandException(getLocalizedString(
081: ERROR_JMX_INVOKE, new Object[] { "setConverter" }),
082: me);
083: } catch (ReflectionException re) {
084: //logger.logp(Level.SEVERE, "DisableRobotConvertersCommand",
085: // "runCommand()", re.getMessage(), re);
086: logger.log(Level.SEVERE, "PSALI_CSPACCSH0003", re);
087: throw new CommandException(getLocalizedString(
088: ERROR_MBEAN_REFLECTION_ERROR,
089: new Object[] { "setConverter" }), re);
090: } catch (CommandException ce) {
091: //logger.logp(Level.SEVERE, "DisableRobotConvertersCommand",
092: // "runCommand()", ce.getMessage(), ce);
093: logger.log(Level.SEVERE, "PSALI_CSPACCSH0003", ce);
094: throw ce;
095: } catch (Exception ex) {
096: ex.printStackTrace();
097: //logger.logp(Level.SEVERE, "DisableRobotConvertersCommand",
098: // "runCommand()", ex.getMessage(), ex);
099: logger.log(Level.SEVERE, "PSALI_CSPACCSH0003", ex);
100: throw new CommandException(
101: getLocalizedString(COMMAND_FAILED), ex);
102: } finally {
103: closeMBeanServerConnection();
104: }
105: }
106:
107: }
|