001: /**
002: * Copyright 2004 Sun Microsystems, Inc. All
003: * rights reserved. Use of this product is subject
004: * to license terms. Federal Acquisitions:
005: * Commercial Software -- Government Users
006: * Subject to Standard License Terms and
007: * Conditions.
008: *
009: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
010: * are trademarks or registered trademarks of Sun Microsystems,
011: * Inc. in the United States and other countries.
012: */package com.sun.portal.admin.cli.commands.search;
013:
014: import java.text.MessageFormat;
015: import java.util.*;
016: import java.util.logging.Logger;
017: import java.util.logging.Level;
018:
019: import javax.management.MBeanServerConnection;
020: import javax.management.ObjectName;
021: import javax.management.InstanceNotFoundException;
022: import javax.management.MBeanException;
023: import javax.management.ReflectionException;
024:
025: import com.sun.enterprise.cli.framework.*;
026:
027: import com.sun.portal.admin.cli.commands.GenericCommand;
028: import com.sun.portal.admin.common.util.AdminUtil;
029:
030: /**
031: * This class implements the psadmin list-robot-converters subcommand.
032: * The list-robot-converters subcommand calls the PortalDomainMBean
033: * and performs the following tasks:
034: * <UL>
035: * <LI>List the search robot converter properties
036: * <UL>
037: */
038:
039: public class ListRobotConvertersCommand extends GenericCommand {
040:
041: //public Logger logger = super.getLogger();
042:
043: //command error messages
044:
045: //command options
046:
047: public void runCommand() throws CommandException,
048: CommandValidationException {
049:
050: validateOptions();
051: validateSearchServerID();
052:
053: ArrayList converters = null;
054: String timeout;
055: String method = "";
056:
057: try {
058: LinkedList path = new LinkedList();
059: path.addFirst(getDomainId());
060: path.addFirst(getSearchServerId());
061: path.addFirst("robot");
062: ObjectName objName = AdminUtil.getResourceMBeanObjectName(
063: AdminUtil.SEARCH_ROBOT_MBEAN_TYPE, path);
064:
065: Object[] params = {};
066: String[] signature = {};
067:
068: MBeanServerConnection msc = getMBeanServerConnection(
069: getUserId(), getPassword(), getHost());
070: method = "listConverters";
071: converters = (ArrayList) msc.invoke(objName,
072: "listConverters", params, signature);
073: method = "getAttribute:ConverterTimeout";
074: timeout = (String) msc.invoke(objName,
075: "retrieveConverterTimeout", params, signature);
076:
077: handleReturnValue(converters, timeout);
078: } catch (InstanceNotFoundException ie) {
079: //logger.logp(Level.SEVERE, "ListRobotConvertersCommand",
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[] { method }), ie);
085: } catch (MBeanException me) {
086: //logger.logp(Level.SEVERE, "ListRobotConvertersCommand",
087: // "runCommand()", me.getMessage(), me);
088: logger.log(Level.SEVERE, "PSALI_CSPACCSH0003", me);
089: throw new CommandException(getLocalizedString(
090: ERROR_JMX_INVOKE, new Object[] { method }), me);
091: } catch (ReflectionException re) {
092: //logger.logp(Level.SEVERE, "ListRobotConvertersCommand",
093: // "runCommand()", re.getMessage(), re);
094: logger.log(Level.SEVERE, "PSALI_CSPACCSH0003", re);
095: throw new CommandException(getLocalizedString(
096: ERROR_MBEAN_REFLECTION_ERROR,
097: new Object[] { method }), re);
098: } catch (CommandException ce) {
099: //logger.logp(Level.SEVERE, "ListRobotConvertersCommand",
100: // "runCommand()", ce.getMessage(), ce);
101: logger.log(Level.SEVERE, "PSALI_CSPACCSH0003", ce);
102: throw ce;
103: } catch (Exception ex) {
104: ex.printStackTrace();
105: //logger.logp(Level.SEVERE, "ListRobotConvertersCommand",
106: // "runCommand()", ex.getMessage(), ex);
107: logger.log(Level.SEVERE, "PSALI_CSPACCSH0003", ex);
108: throw new CommandException(
109: getLocalizedString(COMMAND_FAILED), ex);
110: } finally {
111: closeMBeanServerConnection();
112: }
113:
114: }
115:
116: /**
117: * handles return value from mbean
118: * @param converters
119: * @param timeout
120: */
121: protected void handleReturnValue(ArrayList converters,
122: String timeout) {
123:
124: if (converters == null) {
125: CLILogger.getInstance().printMessage(
126: getLocalizedString(COMMAND_FAILED));
127: } else {
128: int converterID;
129: StringBuffer sb = new StringBuffer();
130:
131: for (int i = 0; i < converters.size(); i++) {
132: converterID = i + 1;
133: LinkedList converter = (LinkedList) converters.get(i);
134:
135: sb.append(getLocalizedString("robot.converter.id",
136: new Object[] { Integer.toString(converterID) })
137: + ", ");
138: sb.append(getLocalizedString("robot.converter.label",
139: new Object[] { (String) converter.get(0) })
140: + ", ");
141:
142: if (((Boolean) converter.get(1)).booleanValue()) {
143: sb
144: .append(getLocalizedString("robot.converter.state")
145: + " "
146: + getLocalizedString("robot.converter.enabled")
147: + "\n");
148: } else {
149: sb
150: .append(getLocalizedString("robot.converter.state")
151: + " "
152: + getLocalizedString("robot.converter.disabled")
153: + "\n");
154: }
155: } // end of for
156:
157: sb.append("\n");
158: sb.append(getLocalizedString("robot.converter.timeout",
159: new Object[] { timeout })
160: + "\n");
161:
162: CLILogger.getInstance().printMessage(sb.toString());
163: }
164:
165: }
166:
167: }
|