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
diff --git a/prod/net/jaekl/cfb/CfbBundle.java b/prod/net/jaekl/cfb/CfbBundle.java
new file mode 100644 (file)
index 0000000..0384851
--- /dev/null
@@ -0,0 +1,50 @@
+package net.jaekl.cfb;
+
+import java.util.Locale;
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+import java.util.concurrent.ConcurrentHashMap;
+
+import net.jaekl.qd.QDBundleFactory;
+
+public class CfbBundle {
+       public static final String CANNOT_CONNECT = "cannot.connect.to.db";
+       
+       final static String BUNDLE_NAME = "cfb";
+       
+       static ConcurrentHashMap<Locale, CfbBundle> m_bundleMap = new ConcurrentHashMap<Locale, CfbBundle>();
+       
+       ResourceBundle m_bundle;
+       
+       public static CfbBundle getInst(Locale locale) {
+               CfbBundle result = m_bundleMap.get(locale);
+               if (null == result) {
+                       synchronized(CfbBundle.class) {
+                               result = m_bundleMap.get(locale);
+                               if (null == result) {
+                                       result = new CfbBundle(locale); 
+                               }
+                               m_bundleMap.put(locale, result);
+                       }
+               }
+               return result;
+       }
+       
+       private CfbBundle(Locale locale) {
+               m_bundle = QDBundleFactory.getInst().getBundle(BUNDLE_NAME, locale); 
+       }
+       
+       public String get(String key) {
+               try {
+                       if (null != m_bundle) {
+                               return m_bundle.getString(key);
+                       }
+               }
+               catch (MissingResourceException exc) {
+                       // Make it clear that something has gone wrong.
+                       exc.printStackTrace();  
+                       // Fall through to the fallback behaviour below
+               }
+               return "[" + key + "]";
+       }
+}