yet another rewrite of the producers...
[mir.git] / source / mircoders / global / MirGlobal.java
index cbbea02..28a4a3b 100755 (executable)
@@ -3,21 +3,42 @@ package mircoders.global;
 import mir.misc.*;
 import mircoders.localizer.*;
 
-import mircoders.localizer.basic.*;
-
-
 public class MirGlobal {
   static private MirConfig configuration;
   static private MirLocalizer localizer;
   static private ProducerEngine producerEngine;
 
   public static MirLocalizer localizer() {
+    String localizerClassName;
+    Class localizerClass;
+
     if (localizer == null ) {
-      localizer = new MirCachingLocalizerDecorator(new MirBasicLocalizer());
+      synchronized(MirGlobal.class) {
+        if (localizer == null ) {
+          localizerClassName = getConfigPropertyWithDefault("Mir.Localizer", "mirlocal.loaclizer.basic.MirBasicLocalizer");
+
+          try {
+            localizerClass = Class.forName(localizerClassName);
+          }
+          catch (Throwable t) {
+            throw new ConfigException("localizer class '" + localizerClassName + "' not found: " + t.toString());
+          }
+
+          if (!(MirLocalizer.class.isAssignableFrom(localizerClass)))
+            throw new ConfigException("localizer class '" + localizerClassName + "' is not assignable from MirLocalizer");
+
+          try {
+            localizer = new MirCachingLocalizerDecorator((MirLocalizer) localizerClass.newInstance());
+          }
+          catch (Throwable t) {
+            throw new ConfigException("localizer class '" + localizerClassName + "' cannot be instantiated: " + t.toString());
+          }
+        }
+      }
     }
 
     return localizer;
-  };
+  }
 
   public static MirConfig config() {
     if (configuration == null) {
@@ -25,7 +46,7 @@ public class MirGlobal {
     }
 
     return configuration;
-  };
+  }
 
   public static ProducerEngine producerEngine() {
     if (producerEngine == null) {
@@ -35,6 +56,17 @@ public class MirGlobal {
     return producerEngine;
   }
 
+  public static String getConfigPropertyWithDefault(String aPropertyName, String aDefault) {
+    String result;
+
+    result = config().getProp(aPropertyName);
+
+    if (result==null)
+      result = aDefault;
+
+    return result;
+  }
+
   public static String getConfigProperty(String aPropertyName) {
     String result;