changeset 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 eafe59ecfb7e
children 366cf4694d45
files ChangeLog artifact-database/src/main/java/de/intevation/artifactdatabase/ArtifactDatabaseImpl.java artifact-database/src/main/java/de/intevation/artifactdatabase/FactoryBootstrap.java
diffstat 3 files changed, 70 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Thu Apr 14 13:02:46 2011 +0000
+++ b/ChangeLog	Thu Apr 14 13:08:49 2011 +0000
@@ -1,3 +1,10 @@
+2011-04-14  Ingo Weinzierl <ingo@intevation.de>
+
+	* artifact-database/src/main/java/de/intevation/artifactdatabase/ArtifactDatabaseImpl.java,
+	  artifact-database/src/main/java/de/intevation/artifactdatabase/FactoryBootstrap.java:
+	  Enhanced the bootstrap - the CallContext.Listener is initialized (if
+	  configured).
+
 2011-04-14  Ingo Weinzierl <ingo@intevation.de>
 
 	* artifacts/src/main/java/de/intevation/artifacts/CallContext.java:
--- a/artifact-database/src/main/java/de/intevation/artifactdatabase/ArtifactDatabaseImpl.java	Thu Apr 14 13:02:46 2011 +0000
+++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/ArtifactDatabaseImpl.java	Thu Apr 14 13:08:49 2011 +0000
@@ -430,6 +430,7 @@
         setupArtifactFactories(bootstrap);
         setupServices(bootstrap);
         setupUserFactory(bootstrap);
+        setupCallContextListener(bootstrap);
 
         context      = bootstrap.getContext();
         exportSecret = bootstrap.getExportSecret();
@@ -481,6 +482,14 @@
         }
     }
 
+    /**
+     * Used to extract the callContextListener from the bootstrap.
+     *
+     * @param bootstrap The bootstrap parameters.
+     */
+    protected void setupCallContextListener(FactoryBootstrap bootstrap) {
+        setCallContextListener(bootstrap.getCallContextListener());
+    }
 
     /**
      * Used to extract the user factory from the bootstrap.
--- 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