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: import java.util.logging.Logger;
016: import java.util.logging.Level;
017:
018: import javax.management.MBeanServerConnection;
019: import javax.management.ObjectName;
020: import javax.management.InstanceNotFoundException;
021: import javax.management.MBeanException;
022: import javax.management.ReflectionException;
023:
024: import com.sun.enterprise.cli.framework.*;
025:
026: import com.sun.portal.admin.cli.commands.GenericCommand;
027: import com.sun.portal.admin.common.util.AdminUtil;
028:
029: /**
030: * This class implements the psadmin run-autoclassify subcommand.
031: * The run-autoclassify subcommand calls the PortalDomainMBean
032: * and performs the following tasks:
033: * <UL>
034: * <LI>Run search autoclassify
035: * <UL>
036: */
037:
038: public class RunAutoclassifyCommand extends GenericCommand {
039:
040: //public Logger logger = super.getLogger();
041:
042: //command error messages
043:
044: //command options
045:
046: String database = null;
047: String locale = null;
048: String startDate = null;
049:
050: public void runCommand() throws CommandException,
051: CommandValidationException {
052: validateOptions();
053: validateSearchServerID();
054:
055: database = getOption("database");
056: //locale = getOption("locale");
057: //if (locale == null || locale.equals(""))
058: locale = Locale.getDefault().toString();
059: startDate = getOption("startdate");
060:
061: String result = null;
062: try {
063: LinkedList path = new LinkedList();
064: //path.addFirst(AdminClientUtil.DEFAULT_DOMAIN);
065: path.addFirst(getDomainId());
066: path.addFirst(getSearchServerId());
067: path.addFirst("autoclassify");
068: ObjectName objName = AdminUtil.getResourceMBeanObjectName(
069: AdminUtil.SEARCH_AUTOCLASSIFY_MBEAN_TYPE, path);
070:
071: Object[] params = { database, locale, startDate };
072: String[] signature = { "java.lang.String",
073: "java.lang.String", "java.lang.String" };
074:
075: MBeanServerConnection msc = getMBeanServerConnection(
076: getUserId(), getPassword(), getHost());
077:
078: result = (String) msc.invoke(objName, "runAutoclassify",
079: params, signature);
080:
081: handleReturnValue(result);
082: } catch (InstanceNotFoundException ie) {
083: //logger.logp(Level.SEVERE, "RunAutoclassifyCommand",
084: // "runCommand()", ie.getMessage(), ie);
085: logger.log(Level.SEVERE, "PSALI_CSPACCSH0003", ie);
086: throw new CommandException(getLocalizedString(
087: ERROR_MBEAN_INSTANCE_NOT_FOUND,
088: new Object[] { "runAutoclassify" }), ie);
089: } catch (MBeanException me) {
090: me.printStackTrace();
091: //logger.logp(Level.SEVERE, "RunAutoclassifyCommand",
092: // "runCommand()", me.getMessage(), me);
093: logger.log(Level.SEVERE, "PSALI_CSPACCSH0003", me);
094: throw new CommandException(getLocalizedString(
095: ERROR_JMX_INVOKE,
096: new Object[] { "runAutoclassify" }), me);
097: } catch (ReflectionException re) {
098: re.printStackTrace();
099: //logger.logp(Level.SEVERE, "RunAutoclassifyCommand",
100: // "runCommand()", re.getMessage(), re);
101: logger.log(Level.SEVERE, "PSALI_CSPACCSH0003", re);
102: throw new CommandException(getLocalizedString(
103: ERROR_MBEAN_REFLECTION_ERROR,
104: new Object[] { "runAutoclassify" }), re);
105: } catch (CommandException ce) {
106: //logger.logp(Level.SEVERE, "RunAutoclassifyCommand",
107: // "runCommand()", ce.getMessage(), ce);
108: logger.log(Level.SEVERE, "PSALI_CSPACCSH0003", ce);
109: throw ce;
110: } catch (Exception ex) {
111: ex.printStackTrace();
112: //logger.logp(Level.SEVERE, "RunAutoclassifyCommand",
113: // "runCommand()", ex.getMessage(), ex);
114: logger.log(Level.SEVERE, "PSALI_CSPACCSH0003", ex);
115: throw new CommandException(
116: getLocalizedString(COMMAND_FAILED), ex);
117: } finally {
118: closeMBeanServerConnection();
119: }
120:
121: }
122:
123: /**
124: * handles return value from mbean
125: * @param config
126: */
127: protected void handleReturnValue(String result) {
128:
129: if (result == null) {
130: CLILogger.getInstance().printMessage(
131: getLocalizedString(COMMAND_FAILED));
132: } else {
133: //StringBuffer sb = new StringBuffer();
134:
135: //sb.append(getLocalizedString("autoclassify.logpath", new Object[] {(String)config.get("LogPath")}) + "\n");
136: //sb.append(getLocalizedString("autoclassify.dbpath", new Object[] {(String)config.get("DbPath")}) + "\n");
137: //sb.append(getLocalizedString("autoclassify.cachesize", new Object[] {(String)config.get("HashSize")}) + "\n");
138:
139: //CLILogger.getInstance().printMessage(sb.toString());
140: CLILogger.getInstance().printMessage(result);
141: }
142:
143: }
144:
145: }
|