001: package com.sun.portal.admin.cli.commands.logging;
002:
003: import com.sun.enterprise.cli.framework.CLILogger;
004: import com.sun.enterprise.cli.framework.CommandException;
005: import com.sun.enterprise.cli.framework.CommandValidationException;
006: import com.sun.portal.admin.common.util.AdminClientUtil;
007:
008: import javax.management.ObjectName;
009: import javax.management.MalformedObjectNameException;
010: import javax.management.InstanceNotFoundException;
011: import javax.management.MBeanException;
012: import javax.management.MBeanServerConnection;
013: import java.util.Iterator;
014: import java.util.Vector;
015: import java.util.logging.Level;
016:
017: /**
018: * Copyright 2004 Sun Microsystems, Inc. All
019: * rights reserved. Use of this product is subject
020: * to license terms. Federal Acquisitions:
021: * Commercial Software -- Government Users
022: * Subject to Standard License Terms and
023: * Conditions.
024: * <p/>
025: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
026: * are trademarks or registered trademarks of Sun Microsystems,
027: * Inc. in the United States and other countries.
028: */
029: public class ListLoggersCommand extends LoggingBaseCommand {
030:
031: // Options specific to list-loggers
032: protected static final String OPT_DETAIL = "detail";
033:
034: protected boolean getDetail() {
035: return getBooleanOption(OPT_DETAIL);
036: }
037:
038: public void runCommand() throws CommandValidationException,
039: CommandException {
040:
041: try {
042:
043: validateOptions();
044: //get Mbean Server Connection based on uid/pwd
045: MBeanServerConnection msc = getMBeanServerConnection(
046: getUserId(), getPassword(), getHost());
047:
048: ObjectName objName = AdminClientUtil
049: .getResourceMBeanObjectName(PORTAL_LOG_OBJECT_NAME,
050: getPath());
051:
052: if (isVerbose()) {
053: if (getDetail())
054: CLILogger
055: .getInstance()
056: .printMessage(
057: "Getting a list of loggers names along with the detail");
058: else
059: CLILogger.getInstance().printMessage(
060: "Getting a list of loggers names");
061: }
062:
063: Object[] params = { getComponent(), getComponentId(),
064: getInstance(), new Boolean(getDetail()) };
065:
066: String[] signature = { "java.lang.String",
067: "java.lang.String", "java.lang.String",
068: "java.lang.Boolean" };
069:
070: Vector result = (Vector) msc.invoke(objName,
071: "listPSLoggers", params, signature);
072:
073: StringBuffer outputBuffer = new StringBuffer();
074: Iterator itr = result.iterator();
075: while (itr.hasNext()) {
076: outputBuffer.append(itr.next());
077: outputBuffer.append(LINE_SEPARATOR);
078: if (getDetail())
079: outputBuffer.append(LINE_SEPARATOR);
080: }
081:
082: if (isVerbose()) {
083: if (getDetail())
084: CLILogger
085: .getInstance()
086: .printMessage(
087: "Printing the list of loggers names along with the detail");
088: else
089: CLILogger.getInstance().printMessage(
090: "Printing the list of loggers names");
091: }
092: CLILogger.getInstance().printMessage(
093: outputBuffer.toString());
094:
095: } catch (InstanceNotFoundException ie) {
096: logger.log(Level.SEVERE, "PSALI_CSPACCL0001", ie);
097: throw new CommandException(getLocalizedString(
098: ERROR_MBEAN_INSTANCE_NOT_FOUND,
099: new Object[] { "listPSLoggers" }), null);
100: } catch (MBeanException me) {
101: logger.log(Level.SEVERE, "PSALI_CSPACCL0001", me);
102: throwError(me);
103: } catch (MalformedObjectNameException mle) {
104: logger.log(Level.SEVERE, "PSALI_CSPACCL0001", mle);
105: throw new CommandException(
106: getLocalizedString(ERROR_OBJECT_NAME), null);
107: } catch (CommandException ce) {
108: logger.log(Level.SEVERE, "PSALI_CSPACCL0001", ce);
109: throw ce;
110: } catch (CommandValidationException cve) {
111: logger.log(Level.SEVERE, "PSALI_CSPACCL0001", cve);
112: throw cve;
113: } catch (Exception ex) {
114: logger.log(Level.SEVERE, "PSALI_CSPACCL0001", ex);
115: throw new CommandException(
116: getLocalizedString(COMMAND_FAILED), null);
117: } finally {
118: closeMBeanServerConnection();
119: }
120: }
121: }
|