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.io.*;
015: import java.lang.*;
016: import java.util.*;
017: import java.text.*;
018:
019: // JMX
020: import javax.management.MBeanServerConnection;
021: import javax.management.ObjectName;
022: import javax.management.InstanceNotFoundException;
023: import javax.management.MBeanException;
024: import javax.management.ReflectionException;
025: import javax.management.MalformedObjectNameException;
026:
027: // PS Admin Common
028: import com.sun.portal.admin.common.util.AdminClientUtil;
029:
030: // CLI framework
031: import com.sun.enterprise.cli.framework.*;
032:
033: // Base Class
034: import com.sun.portal.admin.cli.commands.GenericCommand;
035:
036: /**
037: * This class implements the psadmin run-search-rdmanager subcommand.
038: */
039: public class RunRDManagerCommand 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: String result = "";
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: Object[] params = { getArguments() };
060: String[] signatures = { "java.lang.String" };
061: MBeanServerConnection msc = getMBeanServerConnection(
062: getUserId(), getPassword(), getHost());
063: result = (String) msc.invoke(on, "runRDManager", params,
064: signatures);
065: } catch (InstanceNotFoundException ie) {
066: throw new CommandException(getLocalizedString(
067: ERROR_MBEAN_INSTANCE_NOT_FOUND,
068: new Object[] { "runRDManager" }), ie);
069: } catch (MBeanException me) {
070: throw new CommandException(getLocalizedString(
071: ERROR_JMX_INVOKE, new Object[] { "runRDManager" }),
072: me);
073: } catch (ReflectionException re) {
074: throw new CommandException(getLocalizedString(
075: ERROR_MBEAN_REFLECTION_ERROR,
076: new Object[] { "runRDManager" }), re);
077:
078: } catch (CommandException ce) {
079: throw ce;
080: } catch (Exception e) {
081: throw new CommandException(
082: getLocalizedString(COMMAND_FAILED), e);
083: } finally {
084: closeMBeanServerConnection();
085: }
086:
087: CLILogger.getInstance().printMessage(result);
088: }
089:
090: private String getArguments() {
091: StringBuffer sb = new StringBuffer();
092: try {
093: String fileName = getOption("file");
094: if (fileName != null) {
095: BufferedReader br = new BufferedReader(new FileReader(
096: fileName));
097: String line;
098: while ((line = br.readLine()) != null) {
099: sb.append(" " + line);
100: }
101: br.close();
102: }
103: } catch (Exception e) {
104: }
105: return sb.toString().trim();
106: }
107:
108: }
|