Bring things to a state where the basic DB schema gets auto-created if it doesn't...
[cfb.git] / prod / net / jaekl / cfb / CfbBundle.java
1 package net.jaekl.cfb;
2
3 import java.util.Locale;
4 import java.util.MissingResourceException;
5 import java.util.ResourceBundle;
6 import java.util.concurrent.ConcurrentHashMap;
7
8 import net.jaekl.qd.QDBundleFactory;
9
10 public class CfbBundle {
11         public static final String CANNOT_CONNECT = "cannot.connect.to.db";
12         
13         final static String BUNDLE_NAME = "cfb";
14         
15         static ConcurrentHashMap<Locale, CfbBundle> m_bundleMap = new ConcurrentHashMap<Locale, CfbBundle>();
16         
17         ResourceBundle m_bundle;
18         
19         public static CfbBundle getInst(Locale locale) {
20                 CfbBundle result = m_bundleMap.get(locale);
21                 if (null == result) {
22                         synchronized(CfbBundle.class) {
23                                 result = m_bundleMap.get(locale);
24                                 if (null == result) {
25                                         result = new CfbBundle(locale); 
26                                 }
27                                 m_bundleMap.put(locale, result);
28                         }
29                 }
30                 return result;
31         }
32         
33         private CfbBundle(Locale locale) {
34                 m_bundle = QDBundleFactory.getInst().getBundle(BUNDLE_NAME, locale); 
35         }
36         
37         public String get(String key) {
38                 try {
39                         if (null != m_bundle) {
40                                 return m_bundle.getString(key);
41                         }
42                 }
43                 catch (MissingResourceException exc) {
44                         // Make it clear that something has gone wrong.
45                         exc.printStackTrace();  
46                         // Fall through to the fallback behaviour below
47                 }
48                 return "[" + key + "]";
49         }
50 }