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