001: /**
002: * Sequoia: Database clustering technology.
003: * Copyright (C) 2002-2004 French National Institute For Research In Computer
004: * Science And Control (INRIA).
005: * Contact: sequoia@continuent.org
006: *
007: * Licensed under the Apache License, Version 2.0 (the "License");
008: * you may not use this file except in compliance with the License.
009: * You may obtain a copy of the License at
010: *
011: * http://www.apache.org/licenses/LICENSE-2.0
012: *
013: * Unless required by applicable law or agreed to in writing, software
014: * distributed under the License is distributed on an "AS IS" BASIS,
015: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016: * See the License for the specific language governing permissions and
017: * limitations under the License.
018: *
019: * Initial developer(s): Nicolas Modrzyk.
020: * Contributor(s): Emmanuel Cecchet.
021: */package org.continuent.sequoia.common.i18n;
022:
023: import java.text.MessageFormat;
024: import java.util.MissingResourceException;
025: import java.util.ResourceBundle;
026:
027: /**
028: * Class to translate the different messages of Sequoia JMX MBeans descriptions.
029: *
030: * @author <a href="mailto:Emmanuel.Cecchet@inria.fr">Emmanuel Cecchet </a>
031: * @author <a href="mailto:Nicolas.Modrzyk@inrialpes.fr">Nicolas Modrzyk </a>
032: * @version 1.0
033: */
034:
035: public final class JmxTranslate {
036: /**
037: * JMX message description is stored in a different file
038: */
039: private static final String BUNDLE_NAME = "org.continuent.sequoia.common.i18n.mbean-messages"; //$NON-NLS-1$
040:
041: /**
042: * Translation RESOURCE_BUNDLE for Sequoia messages
043: */
044: private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle
045: .getBundle(BUNDLE_NAME);
046:
047: /**
048: * Class is not meant to be instantiated.
049: */
050: private JmxTranslate() {
051: }
052:
053: /**
054: * Returns the translation for the given <code>key</code>
055: *
056: * @param key the translation key
057: * @return the translation or <code>'!' + key + '!'</code> if
058: * there is no translation for the given key
059: */
060: public static String get(String key) {
061: try {
062: return RESOURCE_BUNDLE.getString(key);
063: } catch (MissingResourceException e) {
064: return '!' + key + '!';
065: }
066: }
067:
068: /**
069: * Returns the translation for the given <code>key</code>
070: *
071: * @param key the translation key
072: * @param args array of <code>Objects</code> used by the
073: * translation
074: * @return the translation or <code>'!' + key + '!'</code> if
075: * there is no translation for the given key
076: */
077: public static String get(String key, Object[] args) {
078: try {
079: return MessageFormat.format(RESOURCE_BUNDLE.getString(key),
080: args);
081: } catch (MissingResourceException e) {
082: return '!' + key + '!';
083: }
084: }
085:
086: // all methods below are convenience methods which
087: // delegate to get(String key, Object[] args)
088:
089: /**
090: * @see #get(String, Object[])
091: */
092: public static String get(String key, boolean parameter) {
093: return get(key, new Object[] { Boolean.valueOf(parameter) });
094: }
095:
096: /**
097: * @see #get(String, Object[])
098: */
099: public static String get(String key, int parameter) {
100: return get(key, new Object[] { Integer.toString(parameter) });
101: }
102:
103: /**
104: * @see #get(String, Object[])
105: */
106: public static String get(String key, long parameter) {
107: return get(key, new Object[] { Long.toString(parameter) });
108: }
109:
110: /**
111: * @see #get(String, Object[])
112: */
113: public static String get(String key, Object parameter) {
114: return get(key, new Object[] { parameter });
115: }
116: }
|