changeset 125:cee54e52000c

Added the registration of the UserFactory to the bootstrap process. artifacts/trunk@1349 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Tue, 01 Mar 2011 17:45:06 +0000
parents caf9f456f7e3
children 76744dcbe826
files ChangeLog artifact-database/src/main/java/de/intevation/artifactdatabase/FactoryBootstrap.java
diffstat 2 files changed, 53 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Tue Mar 01 17:43:16 2011 +0000
+++ b/ChangeLog	Tue Mar 01 17:45:06 2011 +0000
@@ -1,3 +1,8 @@
+2011-03-01  Ingo Weinzierl <ingo@intevation.de>
+
+	* artifact-database/src/main/java/de/intevation/artifactdatabase/FactoryBootstrap.java:
+	  Added the registration of the UserFactory to the bootstrap process.
+
 2011-03-01	Sascha L. Teichmann <sascha.teichmann@intevation.de>
 
 	* artifact-database/src/main/resources/sql/org-h2-driver.properties,
--- a/artifact-database/src/main/java/de/intevation/artifactdatabase/FactoryBootstrap.java	Tue Mar 01 17:43:16 2011 +0000
+++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/FactoryBootstrap.java	Tue Mar 01 17:45:06 2011 +0000
@@ -11,6 +11,7 @@
 import de.intevation.artifacts.ArtifactContextFactory;
 import de.intevation.artifacts.ArtifactFactory;
 import de.intevation.artifacts.ServiceFactory;
+import de.intevation.artifacts.UserFactory;
 
 import java.util.ArrayList;
 
@@ -57,6 +58,19 @@
         "/artifact-database/factories/service-factories/service-factory";
 
     /**
+     * XPath to figure out the class name of the user factory from global
+     * configuration.
+     */
+    public static final String USER_FACTORY =
+        "/artfifact-database/factories/user-factory/text()";
+
+    /**
+     * The name of the default user factory.
+     */
+    public static final String DEFAULT_USER_FACTORY =
+        "de.intevation.artifactdatabase.DefaultUserFactory";
+
+    /**
      * XPath to figure out the secret used to sign the artifact exports
      * made by the artfifact database server.
      */
@@ -89,6 +103,11 @@
     protected ServiceFactory [] serviceFactories;
 
     /**
+     * The factory that is used to create and list users.
+     */
+    protected UserFactory userFactory;
+
+    /**
      * byte array holding the export signing secret.
      */
     protected byte [] exportSecret;
@@ -237,6 +256,34 @@
             new ServiceFactory[loadedFactories.size()]);
     }
 
+
+    /**
+     * Scans the global configuration for the configured user factory.
+     */
+    protected void loadUserFactory() {
+        logger.info("loading user factory");
+
+        String className = Config.getStringXPath(
+            USER_FACTORY, DEFAULT_USER_FACTORY);
+
+        try {
+            Class clazz = Class.forName(className);
+            userFactory = (UserFactory) clazz.newInstance();
+        }
+        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
@@ -261,6 +308,7 @@
         buildContext();
         loadArtifactFactories();
         loadServiceFactories();
+        loadUserFactory();
     }
 
     /**

http://dive4elements.wald.intevation.org