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