01: /**
02: * Copyright 2005 Sun Microsystems, Inc. All
03: * rights reserved. Use of this product is subject
04: * to license terms. Federal Acquisitions:
05: * Commercial Software -- Government Users
06: * Subject to Standard License Terms and
07: * Conditions.
08: *
09: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
10: * are trademarks or registered trademarks of Sun Microsystems,
11: * Inc. in the United States and other countries.
12: */package com.sun.portal.admin.cli.commands.logging;
13:
14: import com.sun.enterprise.cli.framework.CLILogger;
15: import com.sun.enterprise.cli.framework.CommandException;
16: import com.sun.enterprise.cli.framework.CommandValidationException;
17: import com.sun.portal.admin.common.util.AdminClientUtil;
18:
19: import javax.management.ObjectName;
20: import javax.management.MalformedObjectNameException;
21: import javax.management.InstanceNotFoundException;
22: import javax.management.MBeanException;
23: import javax.management.MBeanServerConnection;
24: import java.util.LinkedList;
25: import java.util.logging.Level;
26:
27: public class ResetLoggerCommand extends LoggingBaseCommand {
28:
29: public void runCommand() throws CommandValidationException,
30: CommandException {
31:
32: try {
33: validateOptions();
34:
35: //get Mbean Server Connection based on uid/pwd
36: MBeanServerConnection msc = getMBeanServerConnection(
37: getUserId(), getPassword(), getHost());
38:
39: LinkedList path = new LinkedList();
40: path.addFirst(getDomainId());
41: path.addFirst("portalLogConfigurator");
42:
43: ObjectName objName = AdminClientUtil
44: .getResourceMBeanObjectName(
45: "PortalDomain.PortalLogConfigurator", path);
46:
47: Object[] params = { getComponent(), getComponentId(),
48: getInstance(), getLoggerName() };
49:
50: String[] signature = { "java.lang.String",
51: "java.lang.String", "java.lang.String",
52: "java.lang.String" };
53:
54: //does not go to parent
55: if (isVerbose()) {
56: StringBuffer sb = new StringBuffer(
57: "Resetting the logger: ");
58: sb.append(getLoggerName());
59: sb.append(LINE_SEPARATOR);
60: sb.append("The content is logged to the parent log");
61: sb.append(LINE_SEPARATOR);
62: sb
63: .append("The level is same as that of the parent logger");
64: CLILogger.getInstance().printMessage(sb.toString());
65: }
66: msc.invoke(objName, "reset", params, signature);
67:
68: } catch (InstanceNotFoundException ie) {
69: logger.log(Level.SEVERE, "PSALI_CSPACCL0001", ie);
70: throw new CommandException(getLocalizedString(
71: ERROR_MBEAN_REFLECTION_ERROR,
72: new Object[] { "reset" }), null);
73: } catch (MBeanException me) {
74: logger.log(Level.SEVERE, "PSALI_CSPACCL0001", me);
75: throwError(me);
76: } catch (MalformedObjectNameException mle) {
77: logger.log(Level.SEVERE, "PSALI_CSPACCL0001", mle);
78: throw new CommandException(
79: getLocalizedString(ERROR_OBJECT_NAME), null);
80: } catch (CommandException ce) {
81: logger.log(Level.SEVERE, "PSALI_CSPACCL0001", ce);
82: throw ce;
83: } catch (CommandValidationException cve) {
84: logger.log(Level.SEVERE, "PSALI_CSPACCL0001", cve);
85: throw cve;
86: } catch (Exception ex) {
87: logger.log(Level.SEVERE, "PSALI_CSPACCL0001", ex);
88: throw new CommandException(
89: getLocalizedString(COMMAND_FAILED), null);
90: } finally {
91: closeMBeanServerConnection();
92: }
93: }
94: }
|