diff artifact-database/src/main/java/de/intevation/artifactdatabase/FactoryBootstrap.java @ 249:c47a640cfdae

Enhanced the bootstrap - the CallContext.Listener is initialized (if configured). artifacts/trunk@1692 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Thu, 14 Apr 2011 13:08:49 +0000
parents b2115f484edb
children c0fb96f88ad1
line wrap: on
line diff
--- a/artifact-database/src/main/java/de/intevation/artifactdatabase/FactoryBootstrap.java	Thu Apr 14 13:02:46 2011 +0000
+++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/FactoryBootstrap.java	Thu Apr 14 13:08:49 2011 +0000
@@ -13,6 +13,7 @@
 import de.intevation.artifacts.ArtifactCollectionFactory;
 import de.intevation.artifacts.ArtifactContextFactory;
 import de.intevation.artifacts.ArtifactFactory;
+import de.intevation.artifacts.CallContext;
 import de.intevation.artifacts.ServiceFactory;
 import de.intevation.artifacts.UserFactory;
 
@@ -95,6 +96,12 @@
         "/artifact-database/export-secret/text()";
 
     /**
+     * XPAth that points to a configuration node for a CallContext.Listener.
+     */
+    public static final String CALLCONTEXT_LISTENER =
+        "/artifact-database/callcontext-listener";
+
+    /**
      * Default export signing secret.
      * <strong>PLEASE CHANGE THE SECRET VIA THE XPATH EXPORT_SECRET
      * IN THE CONFIGURATION.</strong>.
@@ -130,6 +137,11 @@
     protected ArtifactCollectionFactory collectionFactory;
 
     /**
+     * The CallContext.Listener.
+     */
+    protected CallContext.Listener callContextListener;
+
+    /**
      * byte array holding the export signing secret.
      */
     protected byte [] exportSecret;
@@ -344,6 +356,38 @@
         }
     }
 
+
+    protected void loadCallContextListener() {
+        logger.info("loading CallContext.Listener");
+
+        Node listener = Config.getNodeXPath(CALLCONTEXT_LISTENER);
+
+        if (listener == null) {
+            return;
+        }
+
+        String className = Config.getStringXPath(listener, "text()");
+
+        try {
+            Class clazz         = Class.forName(className);
+            callContextListener = (CallContext.Listener) clazz.newInstance();
+
+            callContextListener.setup(Config.getConfig(), listener);
+        }
+        catch (ClassNotFoundException cnfe) {
+                logger.error(cnfe.getLocalizedMessage(), cnfe);
+        }
+        catch (InstantiationException ie) {
+            logger.error(ie.getLocalizedMessage(), ie);
+        }
+        catch (ClassCastException cce) {
+            logger.error(cce.getLocalizedMessage(), cce);
+        }
+        catch (IllegalAccessException iae) {
+            logger.error(iae.getLocalizedMessage(), iae);
+        }
+    }
+
     /**
      * Fetches the export signing secret from the global configuration.
      * If none is found if defaults to the DEFAULT_EXORT_SECRET which
@@ -370,6 +414,7 @@
         loadArtifactFactories();
         loadServiceFactories();
         loadUserFactory();
+        loadCallContextListener();
     }
 
     /**
@@ -422,5 +467,14 @@
     public byte [] getExportSecret() {
         return exportSecret;
     }
+
+    /**
+     * Returns a CallContext.Listener if configured or null.
+     *
+     * @return a CallContext.Listener.
+     */
+    public CallContext.Listener getCallContextListener() {
+        return callContextListener;
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org