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.
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 Translate {
036: private static final String BUNDLE_NAME = "org.continuent.sequoia.common.i18n.messages"; //$NON-NLS-1$
037:
038: private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle
039: .getBundle(BUNDLE_NAME);
040:
041: /**
042: * Class is not meant to be instantiated.
043: */
044: private Translate() {
045: }
046:
047: /**
048: * Returns the translation for the given <code>key</code>
049: *
050: * @param key the translation key
051: * @return the translation or <code>'!' + key + '!'</code> if
052: * there is no translation for the given key
053: */
054: public static String get(String key) {
055: try {
056: return RESOURCE_BUNDLE.getString(key);
057: } catch (MissingResourceException e) {
058: return '!' + key + '!';
059: }
060: }
061:
062: /**
063: * Returns the translation for the given <code>key</code>
064: *
065: * @param key the translation key
066: * @param args array of <code>Objects</code> used by the
067: * translation
068: * @return the translation or <code>'!' + key + '!'</code> if
069: * there is no translation for the given key
070: */
071: public static String get(String key, Object[] args) {
072: try {
073: return MessageFormat.format(RESOURCE_BUNDLE.getString(key),
074: args);
075: } catch (MissingResourceException e) {
076: return '!' + key + '!';
077: }
078: }
079:
080: // all methods below are convenience methods which
081: // delegate to get(String key, Object[] args)
082:
083: /**
084: * @see #get(String, Object[])
085: */
086: public static String get(String key, boolean parameter) {
087: return get(key, new Object[] { Boolean.valueOf(parameter) });
088: }
089:
090: /**
091: * @see #get(String, Object[])
092: */
093: public static String get(String key, int parameter) {
094: return get(key, new Object[] { Integer.toString(parameter) });
095: }
096:
097: /**
098: * @see #get(String, Object[])
099: */
100: public static String get(String key, long parameter) {
101: return get(key, new Object[] { Long.toString(parameter) });
102: }
103:
104: /**
105: * @see #get(String, Object[])
106: */
107: public static String get(String key, Object param1, Object param2) {
108: return get(key, new Object[] { param1, param2 });
109: }
110:
111: /**
112: * @see #get(String, Object[])
113: */
114: public static String get(String key, Object parameter) {
115: return get(key, new Object[] { parameter });
116: }
117: }
|