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.util.*;
015:
016: // JMX
017: import javax.management.MBeanServerConnection;
018: import javax.management.ObjectName;
019: import javax.management.InstanceNotFoundException;
020: import javax.management.MBeanException;
021: import javax.management.ReflectionException;
022: import javax.management.MalformedObjectNameException;
023: import javax.management.RuntimeOperationsException;
024:
025: // PS Admin Common
026: import com.sun.portal.admin.common.util.AdminClientUtil;
027:
028: // CLI framework
029: import com.sun.enterprise.cli.framework.*;
030:
031: // Base Class
032: import com.sun.portal.admin.cli.commands.GenericCommand;
033:
034: /**
035: * This class implements the psadmin list-search-importagents subcommand.
036: * The list-search-importagents subcommand calls the SearchServerMBean
037: * and shows a list of import agents.
038: */
039: public class ListImportAgentsCommand extends GenericCommand {
040:
041: /**
042: * An abstract method that executes the command
043: * @throws CommandException
044: * @throws CommandValidationException
045: */
046: public void runCommand() throws CommandException,
047: CommandValidationException {
048: validateOptions();
049: validateSearchServerID();
050:
051: StringBuffer sb = new StringBuffer();
052: try {
053: LinkedList path = new LinkedList();
054: path.addFirst(AdminClientUtil.DEFAULT_DOMAIN);
055: path.addFirst(getSearchServerId());
056: ObjectName on = AdminClientUtil.getResourceMBeanObjectName(
057: AdminClientUtil.SEARCHSERVER_MBEAN_TYPE, path);
058:
059: MBeanServerConnection msc = getMBeanServerConnection(
060: getUserId(), getPassword(), getHost());
061:
062: ArrayList al = new ArrayList();
063: al.add("id");
064: al.add("input-file");
065: al.add("nickname");
066: Object[] params = { al };
067: String[] signatures = { "java.util.List" };
068: ArrayList data = (ArrayList) msc.invoke(on,
069: "getAllImportAgents", params, signatures);
070:
071: for (int index = 0; index < data.size(); index++) {
072: Properties p = (Properties) data.get(index);
073:
074: String id = getStringValue(p, "id");
075: String inputFile = getStringValue(p, "input-file");
076: String nickName = getStringValue(p, "nickname");
077: String agent = (!nickName.equals("")) ? nickName
078: : inputFile;
079: sb.append(id + "\t" + agent + "\n");
080: }
081: } catch (InstanceNotFoundException ie) {
082: throw new CommandException(getLocalizedString(
083: ERROR_MBEAN_INSTANCE_NOT_FOUND,
084: new Object[] { "getAllImportAgents" }), ie);
085: } catch (MBeanException me) {
086: throw new CommandException(getLocalizedString(
087: ERROR_JMX_INVOKE,
088: new Object[] { "getAllImportAgents" }), me);
089: } catch (ReflectionException re) {
090: throw new CommandException(getLocalizedString(
091: ERROR_MBEAN_REFLECTION_ERROR,
092: new Object[] { "getAllImportAgents" }), re);
093: } catch (CommandException ce) {
094: throw ce;
095: } catch (Exception e) {
096: throw new CommandException(
097: getLocalizedString(COMMAND_FAILED), e);
098: } finally {
099: closeMBeanServerConnection();
100: }
101:
102: CLILogger.getInstance().printMessage(sb.toString());
103: }
104:
105: private String getStringValue(Properties p, String key) {
106: if (p.containsKey(key)) {
107: return p.getProperty(key);
108: } else {
109: return "";
110: }
111: }
112:
113: }
|