diff artifact-database/src/main/java/de/intevation/artifactdatabase/FactoryBootstrap.java @ 155:f797093c60bd

Made a (single one) artifact collection factory configurable. artifacts/trunk@1380 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Thu, 03 Mar 2011 09:51:09 +0000
parents 147610c43863
children b2115f484edb
line wrap: on
line diff
--- a/artifact-database/src/main/java/de/intevation/artifactdatabase/FactoryBootstrap.java	Thu Mar 03 09:36:03 2011 +0000
+++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/FactoryBootstrap.java	Thu Mar 03 09:51:09 2011 +0000
@@ -8,6 +8,7 @@
 
 package de.intevation.artifactdatabase;
 
+import de.intevation.artifacts.ArtifactCollectionFactory;
 import de.intevation.artifacts.ArtifactContextFactory;
 import de.intevation.artifacts.ArtifactFactory;
 import de.intevation.artifacts.ServiceFactory;
@@ -63,7 +64,7 @@
      * configuration.
      */
     public static final String USER_FACTORY =
-        "/artfifact-database/factories/user-factory";
+        "/artifact-database/factories/user-factory";
 
     /**
      * The name of the default user factory.
@@ -72,6 +73,19 @@
         "de.intevation.artifactdatabase.DefaultUserFactory";
 
     /**
+     * XPath to figure out the class name of the collection factory from global
+     * configuration.
+     */
+    public static final String COLLECTION_FACTORY =
+        "/artifact-database/factories/collection-factory";
+
+    /**
+     * The name of the default user factory.
+     */
+    public static final String DEFAULT_COLLECTION_FACTORY =
+        "de.intevation.artifactdatabase.DefaultArtifactCollectionFactory";
+
+    /**
      * XPath to figure out the secret used to sign the artifact exports
      * made by the artfifact database server.
      */
@@ -109,6 +123,11 @@
     protected UserFactory userFactory;
 
     /**
+     * The factory that is used to create new artifact collections.
+     */
+    protected ArtifactCollectionFactory collectionFactory;
+
+    /**
      * byte array holding the export signing secret.
      */
     protected byte [] exportSecret;
@@ -153,6 +172,40 @@
         context = factory.createArtifactContext(Config.getConfig());
     }
 
+
+    /**
+     * Scans the global configuration to load the configured collection factory
+     * and sets it up.
+     */
+    protected void loadCollectionFactory() {
+
+        logger.info("loading collection factory.");
+
+        Node factory = Config.getNodeXPath(COLLECTION_FACTORY);
+
+        String className = Config.getStringXPath(
+            factory, "text()", DEFAULT_COLLECTION_FACTORY);
+
+        try {
+            Class clazz       = Class.forName(className);
+            collectionFactory = (ArtifactCollectionFactory) clazz.newInstance();
+
+            collectionFactory.setup(Config.getConfig(), factory);
+        }
+        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);
+        }
+    }
+
     /**
      * Scans the global configuration to load the configured
      * artifact factories and sets them up.
@@ -311,12 +364,22 @@
     public void boot() {
         setupExportSecret();
         buildContext();
+        loadCollectionFactory();
         loadArtifactFactories();
         loadServiceFactories();
         loadUserFactory();
     }
 
     /**
+     * Returns the artifact collection factory.
+     *
+     * @return the artifact collection factory.
+     */
+    public ArtifactCollectionFactory getArtifactCollectionFactory() {
+        return collectionFactory;
+    }
+
+    /**
      * Returns the list of ready to use artifact factories.
      * @return The list of artifact factories.
      */

http://dive4elements.wald.intevation.org