Minor fine-tuning of findbugs command execution
[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         public static final String CANNOT_EXEC = "cannot.exec";
13         public static final String STDERR_WAS = "stderr.was";
14         public static final String STDOUT_WAS = "stdout.was";
15         
16         final static String BUNDLE_NAME = "cfb";
17         
18         static ConcurrentHashMap<Locale, CfbBundle> m_bundleMap = new ConcurrentHashMap<Locale, CfbBundle>();
19         
20         ResourceBundle m_bundle;
21         
22         public static CfbBundle getInst(Locale locale) {
23                 CfbBundle result = m_bundleMap.get(locale);
24                 if (null == result) {
25                         synchronized(CfbBundle.class) {
26                                 result = m_bundleMap.get(locale);
27                                 if (null == result) {
28                                         result = new CfbBundle(locale); 
29                                 }
30                                 m_bundleMap.put(locale, result);
31                         }
32                 }
33                 return result;
34         }
35         
36         private CfbBundle(Locale locale) {
37                 m_bundle = QDBundleFactory.getInst().getBundle(BUNDLE_NAME, locale); 
38         }
39         
40         public String get(String key) {
41                 try {
42                         if (null != m_bundle) {
43                                 return m_bundle.getString(key);
44                         }
45                 }
46                 catch (MissingResourceException exc) {
47                         // Make it clear that something has gone wrong.
48                         exc.printStackTrace();  
49                         // Fall through to the fallback behaviour below
50                 }
51                 return "[" + key + "]";
52         }
53 }