KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > continuent > sequoia > common > i18n > ConsoleTranslate


1 /**
2  * Sequoia: Database clustering technology.
3  * Copyright (C) 2002-2004 French National Institute For Research In Computer
4  * Science And Control (INRIA).
5  * Contact: sequoia@continuent.org
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  * Initial developer(s): Nicolas Modrzyk
20  * Contributor(s): ______________________.
21  */

22
23 package org.continuent.sequoia.common.i18n;
24
25 import java.text.MessageFormat JavaDoc;
26 import java.util.MissingResourceException JavaDoc;
27 import java.util.ResourceBundle JavaDoc;
28
29 /**
30  * Class to translate the different messages of Sequoia CLI Console.
31  *
32  * @author <a HREF="mailto:Nicolas.Modrzyk@inria.fr">Nicolas Modrzyk </a>
33  * @version 1.0
34  */

35 public final class ConsoleTranslate
36 {
37   /**
38    * console message description is stored in a different file
39    */

40   private static final String JavaDoc BUNDLE_NAME = "org.continuent.sequoia.common.i18n.console-messages"; //$NON-NLS-1$
41

42   /**
43    * Translation RESOURCE_BUNDLE for Sequoia messages
44    */

45   private static final ResourceBundle JavaDoc RESOURCE_BUNDLE = ResourceBundle
46                                                           .getBundle(BUNDLE_NAME);
47
48   /**
49    * Class is not meant to be instantiated.
50    */

51   private ConsoleTranslate()
52   {
53   }
54
55   /**
56    * Returns the translation for the given &lt;code&gt;key&lt;/code&gt;
57    *
58    * @param key the translation key
59    * @return the translation or &lt;code&gt;'!' + key + '!'&lt;/code&gt; if
60    * there is no translation for the given key
61    */

62   public static String JavaDoc get(String JavaDoc key)
63   {
64     try
65     {
66       return RESOURCE_BUNDLE.getString(key);
67     }
68     catch (MissingResourceException JavaDoc e)
69     {
70       return '!' + key + '!';
71     }
72   }
73
74   /**
75    * Returns the translation for the given &lt;code&gt;key&lt;/code&gt;
76    *
77    * @param key the translation key
78    * @param args array of &lt;code&gt;Objects&lt;/code&gt; used by the
79    * translation
80    * @return the translation or &lt;code&gt;'!' + key + '!'&lt;/code&gt; if
81    * there is no translation for the given key
82    */

83   public static String JavaDoc get(String JavaDoc key, Object JavaDoc[] args)
84   {
85     try
86     {
87       return MessageFormat.format(RESOURCE_BUNDLE.getString(key), args);
88     }
89     catch (MissingResourceException JavaDoc e)
90     {
91       return '!' + key + '!';
92     }
93   }
94
95   // all methods below are convenience methods which
96
// delegate to get(String key, Object[] args)
97

98   /**
99    * @see #get(String, Object[])
100    */

101   public static String JavaDoc get(String JavaDoc key, boolean parameter)
102   {
103     return get(key, new Object JavaDoc[]{Boolean.toString(parameter)});
104   }
105
106   /**
107    * @see #get(String, Object[])
108    */

109   public static String JavaDoc get(String JavaDoc key, int parameter)
110   {
111     return get(key, new Object JavaDoc[]{Integer.toString(parameter)});
112   }
113
114   /**
115    * @see #get(String, Object[])
116    */

117   public static String JavaDoc get(String JavaDoc key, long parameter)
118   {
119     return get(key, new Object JavaDoc[]{Long.toString(parameter)});
120   }
121
122   /**
123    * @see #get(String, Object[])
124    */

125   public static String JavaDoc get(String JavaDoc key, Object JavaDoc parameter)
126   {
127     return get(key, new Object JavaDoc[]{parameter});
128   }
129 }
Popular Tags