001: /*
002: * BEGIN_HEADER - DO NOT EDIT
003: *
004: * The contents of this file are subject to the terms
005: * of the Common Development and Distribution License
006: * (the "License"). You may not use this file except
007: * in compliance with the License.
008: *
009: * You can obtain a copy of the license at
010: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
011: * See the License for the specific language governing
012: * permissions and limitations under the License.
013: *
014: * When distributing Covered Code, include this CDDL
015: * HEADER in each file and include the License file at
016: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
017: * If applicable add the following below this CDDL HEADER,
018: * with the fields enclosed by brackets "[]" replaced with
019: * your own identifying information: Portions Copyright
020: * [year] [name of copyright owner]
021: */
022:
023: /*
024: * @(#)DefaultLoggerMBeanImpl.java
025: * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026: *
027: * END_HEADER - DO NOT EDIT
028: */
029: package com.sun.jbi.management.support;
030:
031: import com.sun.jbi.management.common.LoggerMBean;
032: import com.sun.jbi.management.support.MBeanHelper;
033:
034: import java.util.logging.Logger;
035: import java.util.logging.Level;
036:
037: /**
038: * LoggerMBean defines standard controls for setting the properties of a
039: * single JBI Framework service or JBI Installable Component logger.
040: *
041: * @author Sun Microsystems, Inc.
042: */
043: public class DefaultLoggerMBeanImpl extends
044: javax.management.StandardMBean implements LoggerMBean {
045: /** Copy of Logger handle managed by this LoggerMBean implementation. */
046: protected Logger mLogger;
047:
048: /** Display name to be used for this logger in the UI. */
049: protected String mDisplayName;
050:
051: /** Constructs a <CODE>DefaultLoggerMBeanImpl</CODE>. */
052: public DefaultLoggerMBeanImpl(Logger aLogger) throws Exception {
053:
054: //allocate a logger:
055: this (aLogger, aLogger.getName());
056: }
057:
058: /** Constructs a <CODE>DefaultLoggerMBeanImpl</CODE>. */
059: public DefaultLoggerMBeanImpl(Logger aLogger, String aDisplayName)
060: throws Exception {
061: super (com.sun.jbi.management.common.LoggerMBean.class);
062: //allocate a logger:
063: mLogger = aLogger;
064: mDisplayName = aDisplayName;
065: }
066:
067: /**
068: * Get the localized display name of this logger.
069: * @return String representing the localized display name.
070: */
071: public String getDisplayName() {
072: return mDisplayName;
073: }
074:
075: /**
076: * Get the log level of this logger. If the level is not set, search the
077: * parent logger chain until a logger is found with a level set.
078: * @return String representing log level or null if no level is set.
079: */
080: public String getLogLevel() {
081: Logger log = mLogger;
082: Level level = log.getLevel();
083:
084: while (null == level) {
085: log = log.getParent();
086: if (null != log) {
087: level = log.getLevel();
088: } else {
089: break;
090: }
091: }
092: if (null != level) {
093: return level.getLocalizedName();
094: } else {
095: return null;
096: }
097: }
098:
099: /**
100: * Get the name of this logger.
101: * @return String representing the logger name.
102: */
103: public String getLoggerName() {
104: return mLogger.getName();
105: }
106:
107: /**
108: * Set the log level of this logger to ALL.
109: * @return 0 if operation is successful, otherwise non-zero.
110: */
111: public int setAll() {
112: mLogger.setLevel(Level.ALL);
113: return 0;
114: }
115:
116: /**
117: * Set the log level of this logger to CONFIG.
118: * @return 0 if operation is successful, otherwise non-zero.
119: */
120: public int setConfig() {
121: mLogger.setLevel(Level.CONFIG);
122: return 0;
123: }
124:
125: /**
126: * Set the log level of this logger to null to inherit from its parent.
127: * @return 0 if operation is successful, otherwise non-zero.
128: */
129: public int setDefault() {
130: mLogger.setLevel(null);
131: return 0;
132: }
133:
134: /**
135: * Set the log level of this logger to FINE.
136: * @return 0 if operation is successful, otherwise non-zero.
137: */
138: public int setFine() {
139: mLogger.setLevel(Level.FINE);
140: return 0;
141: }
142:
143: /**
144: * Set the log level of this logger to FINER.
145: * @return 0 if operation is successful, otherwise non-zero.
146: */
147: public int setFiner() {
148: mLogger.setLevel(Level.FINER);
149: return 0;
150: }
151:
152: /**
153: * Set the log level of this logger to FINEST.
154: * @return 0 if operation is successful, otherwise non-zero.
155: */
156: public int setFinest() {
157: mLogger.setLevel(Level.FINEST);
158: return 0;
159: }
160:
161: /**
162: * Set the log level of this logger to INFO.
163: * @return 0 if operation is successful, otherwise non-zero.
164: */
165: public int setInfo() {
166: mLogger.setLevel(Level.INFO);
167: return 0;
168: }
169:
170: /**
171: * Set the log level of this logger to OFF.
172: * @return 0 if operation is successful, otherwise non-zero.
173: */
174: public int setOff() {
175: mLogger.setLevel(Level.OFF);
176: return 0;
177: }
178:
179: /**
180: * Set the log level of this logger to SEVERE.
181: * @return 0 if operation is successful, otherwise non-zero.
182: */
183: public int setSevere() {
184: mLogger.setLevel(Level.SEVERE);
185: return 0;
186: }
187:
188: /**
189: * Set the log level of this logger to WARNING.
190: * @return 0 if operation is successful, otherwise non-zero.
191: */
192: public int setWarning() {
193: mLogger.setLevel(Level.WARNING);
194: return 0;
195: }
196:
197: }
|