diff artifact-database/src/main/java/de/intevation/artifactdatabase/FactoryBootstrap.java @ 263:c0fb96f88ad1

Make used HTTP server exchangeable. artifacts/trunk@1974 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Sun, 22 May 2011 11:21:40 +0000
parents c47a640cfdae
children d52947ce8629
line wrap: on
line diff
--- a/artifact-database/src/main/java/de/intevation/artifactdatabase/FactoryBootstrap.java	Wed May 18 10:10:11 2011 +0000
+++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/FactoryBootstrap.java	Sun May 22 11:21:40 2011 +0000
@@ -17,6 +17,9 @@
 import de.intevation.artifacts.ServiceFactory;
 import de.intevation.artifacts.UserFactory;
 
+
+import de.intevation.artifactdatabase.rest.HTTPServer;
+
 import java.util.ArrayList;
 
 import org.apache.log4j.Logger;
@@ -101,6 +104,13 @@
     public static final String CALLCONTEXT_LISTENER =
         "/artifact-database/callcontext-listener";
 
+
+    public static final String HTTP_SERVER =
+        "/artifact-database/rest-server/http-server/text()";
+
+    public static final String DEFAULT_HTTP_SERVER =
+        "de.intevation.artifactdatabase.rest.Standalone";
+
     /**
      * Default export signing secret.
      * <strong>PLEASE CHANGE THE SECRET VIA THE XPATH EXPORT_SECRET
@@ -146,6 +156,8 @@
      */
     protected byte [] exportSecret;
 
+    protected HTTPServer httpServer;
+
 
     /**
      * Default constructor
@@ -375,7 +387,33 @@
             callContextListener.setup(Config.getConfig(), listener);
         }
         catch (ClassNotFoundException cnfe) {
-                logger.error(cnfe.getLocalizedMessage(), 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);
+        }
+    }
+
+    protected void loadHTTPServer() {
+        logger.info("loading HTTPServer");
+
+        String className = Config.getStringXPath(
+            HTTP_SERVER, DEFAULT_HTTP_SERVER);
+
+        try {
+            Class clazz = Class.forName(className);
+            httpServer  = (HTTPServer)clazz.newInstance();
+
+            httpServer.setup(Config.getConfig());
+        }
+        catch (ClassNotFoundException cnfe) {
+            logger.error(cnfe.getLocalizedMessage(), cnfe);
         }
         catch (InstantiationException ie) {
             logger.error(ie.getLocalizedMessage(), ie);
@@ -415,6 +453,7 @@
         loadServiceFactories();
         loadUserFactory();
         loadCallContextListener();
+        loadHTTPServer();
     }
 
     /**
@@ -476,5 +515,9 @@
     public CallContext.Listener getCallContextListener() {
         return callContextListener;
     }
+
+    public HTTPServer getHTTPServer() {
+        return httpServer;
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org