335a68dfbbb761c914b5523fee10115bba5e75e9
[cfb.git] / prod / net / jaekl / cfb / CfbBundle.java
1 package net.jaekl.cfb;
2
3 // Copyright (C) 2015 Christian Jaekl
4
5 import java.util.Locale;
6 import java.util.MissingResourceException;
7 import java.util.ResourceBundle;
8 import java.util.concurrent.ConcurrentHashMap;
9
10 import net.jaekl.qd.QDBundleFactory;
11
12 public class CfbBundle {
13         public static final String ANALYSIS_FAILED = "analysis.failed";
14         public static final String CANNOT_CONNECT = "cannot.connect.to.db";
15         public static final String CANNOT_EXEC = "cannot.exec";
16         public static final String STDERR_WAS = "stderr.was";
17         public static final String STDOUT_WAS = "stdout.was";
18         
19         final static String BUNDLE_NAME = "cfb";
20         
21         static ConcurrentHashMap<Locale, CfbBundle> m_bundleMap = new ConcurrentHashMap<Locale, CfbBundle>();
22         
23         ResourceBundle m_bundle;
24         
25         public static CfbBundle getInst(Locale locale) {
26                 CfbBundle result = m_bundleMap.get(locale);
27                 if (null == result) {
28                         synchronized(CfbBundle.class) {
29                                 result = m_bundleMap.get(locale);
30                                 if (null == result) {
31                                         result = new CfbBundle(locale); 
32                                 }
33                                 m_bundleMap.put(locale, result);
34                         }
35                 }
36                 return result;
37         }
38         
39         private CfbBundle(Locale locale) {
40                 m_bundle = QDBundleFactory.getInst().getBundle(BUNDLE_NAME, locale); 
41         }
42         
43         public String get(String key) {
44                 try {
45                         if (null != m_bundle) {
46                                 return m_bundle.getString(key);
47                         }
48                 }
49                 catch (MissingResourceException exc) {
50                         // Make it clear that something has gone wrong.
51                         exc.printStackTrace();  
52                         // Fall through to the fallback behaviour below
53                 }
54                 return "[" + key + "]";
55         }
56 }