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