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: * @(#)DynamicRuntimeConfiguration.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.config;
030:
031: import com.sun.jbi.StringTranslator;
032: import com.sun.jbi.management.ConfigurationCategory;
033: import com.sun.jbi.management.message.MessageBuilder;
034:
035: import java.util.Properties;
036: import java.util.logging.Logger;
037: import javax.management.modelmbean.ModelMBeanAttributeInfo;
038:
039: /**
040: * ConfigurationFactory is the producer of configuration data set for a
041: * particular category.
042: *
043: * @author Sun Microsystems, Inc.
044: */
045: public abstract class ConfigurationFactory {
046: /** The Logger */
047: private Logger mLog;
048:
049: /** The string translator */
050: private StringTranslator mTranslator;
051:
052: /** The category */
053: protected ConfigurationCategory mCategory;
054:
055: /** The default proiperties */
056: protected Properties mDefaults;
057:
058: /**
059: * Contructor that gets the default properties and category
060: *
061: * @param defaults - defualt attribute values
062: * @category - the configuration category
063: */
064: public ConfigurationFactory(Properties defaults,
065: ConfigurationCategory category) {
066: mDefaults = defaults;
067: mCategory = category;
068: }
069:
070: /**
071: * @return an array of attribute meta data for a configuration category.
072: */
073: public abstract ModelMBeanAttributeInfo[] createMBeanAttributeInfo();
074:
075: /**
076: * Get the I18N String from the resource bundle.
077: *
078: * @return the 118N string after removing the token prefix
079: */
080: protected String getString(String key) {
081: String str = getTranslator().getString(key);
082: return MessageBuilder.getMessageString(str);
083: }
084:
085: /**
086: * Get the I18N String token from the resource bundle.
087: *
088: * @return the 118N token from the localized string.
089: */
090: protected String getToken(String key) {
091: String str = getTranslator().getString(key);
092: return MessageBuilder.getMessageToken(str);
093: }
094:
095: /**
096: */
097: protected StringTranslator getTranslator() {
098: if (mTranslator == null) {
099: com.sun.jbi.EnvironmentContext envCtx = com.sun.jbi.util.EnvironmentAccess
100: .getContext();
101: mTranslator = envCtx
102: .getStringTranslator("com.sun.jbi.management");
103: }
104: return mTranslator;
105: }
106:
107: /**
108: *
109: */
110: protected Logger getLogger() {
111: if (mLog == null) {
112: mLog = Logger.getLogger("com.sun.jbi.management");
113: }
114: return mLog;
115: }
116:
117: /**
118: * @return the attrbute name prefixed with the category
119: * @param key - identification for the attribute
120: */
121: protected String getQualifiedKey(String key) {
122: StringBuffer strBuf = new StringBuffer(mCategory.toString()
123: .toLowerCase());
124: strBuf.append(".");
125: strBuf.append(key);
126: return strBuf.toString();
127: }
128:
129: /**
130: * @return the default log level for the JBI Runtime
131: */
132: protected String getDefaultLogLevel() {
133: java.util.logging.Level level = Logger.getLogger("com.sun.jbi")
134: .getLevel();
135: if (level != null) {
136: return level.toString();
137: } else {
138: return "INFO";
139: }
140: }
141:
142: }
|