KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > admin > mbeans > custom > Strings


1 /*
2  * Strings.java
3  *
4  * Created on February 14, 2006, 2:17 AM
5  *
6  */

7
8 package com.sun.enterprise.admin.mbeans.custom;
9
10 import java.util.*;
11 import java.text.MessageFormat JavaDoc;
12
13 /**
14  *
15  * @author bnevins
16  */

17
18  class Strings
19 {
20      Strings(String JavaDoc... fqnPropsList)
21     {
22         for(String JavaDoc fqnProps : fqnPropsList)
23             addBundle(fqnProps);
24     }
25     
26     ///////////////////////////////////////////////////////////////////////////
27

28      void addBundle(String JavaDoc fqnProps)
29     {
30         // format: "com.elf.foo.LogStrings"
31
try
32         {
33             bundles.add(ResourceBundle.getBundle(fqnProps));
34         }
35         catch(Exception JavaDoc e)
36         {
37             // should throw ???
38
}
39     }
40     
41     ///////////////////////////////////////////////////////////////////////////
42

43     String JavaDoc get(String JavaDoc indexString)
44     {
45         // grab the first property that matches...
46
for(ResourceBundle bundle : bundles)
47         {
48             try
49             {
50                 return bundle.getString(indexString);
51             }
52             catch (Exception JavaDoc e)
53             {
54                 // not an error...
55
}
56         }
57         // it is not an error to have no key...
58
return indexString;
59     }
60
61     ///////////////////////////////////////////////////////////////////////////
62

63      String JavaDoc get(String JavaDoc indexString, Object JavaDoc... objects)
64     {
65         indexString = get(indexString);
66         
67         try
68         {
69             MessageFormat JavaDoc mf = new MessageFormat JavaDoc(indexString);
70             return mf.format(objects);
71         }
72         catch(Exception JavaDoc e)
73         {
74             return indexString;
75         }
76     }
77
78     ///////////////////////////////////////////////////////////////////////////
79

80     List<ResourceBundle> getBundles()
81     {
82         //for testing purposes
83
return bundles;
84     }
85
86     ///////////////////////////////////////////////////////////////////////////
87

88     private List<ResourceBundle> bundles = new ArrayList<ResourceBundle>();
89 }
90
Popular Tags