KickJava   Java API By Example, From Geeks To Geeks.

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


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): Emmanuel Cecchet.
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 JMX MBeans descriptions.
31  *
32  * @author <a HREF="mailto:Emmanuel.Cecchet@inria.fr">Emmanuel Cecchet </a>
33  * @author <a HREF="mailto:Nicolas.Modrzyk@inrialpes.fr">Nicolas Modrzyk </a>
34  * @version 1.0
35  */

36
37 public final class JmxTranslate
38 {
39   /**
40    * JMX message description is stored in a different file
41    */

42   private static final String JavaDoc BUNDLE_NAME = "org.continuent.sequoia.common.i18n.mbean-messages"; //$NON-NLS-1$
43

44   /**
45    * Translation RESOURCE_BUNDLE for Sequoia messages
46    */

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

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

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

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

100   /**
101    * @see #get(String, Object[])
102    */

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

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

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

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