changeset 70:ce488c1d3fc4

Serve services over artifact database. artifacts/trunk@597 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Fri, 22 Jan 2010 11:08:40 +0000
parents 498bb84334d0
children c99da6837be0
files ChangeLog artifact-database/src/main/java/de/intevation/artifactdatabase/ArtifactDatabaseImpl.java artifact-database/src/main/java/de/intevation/artifactdatabase/FactoryBootstrap.java artifacts/src/main/java/de/intevation/artifacts/ArtifactDatabase.java artifacts/src/main/java/de/intevation/artifacts/ServiceFactory.java
diffstat 5 files changed, 104 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Fri Jan 22 10:19:27 2010 +0000
+++ b/ChangeLog	Fri Jan 22 11:08:40 2010 +0000
@@ -1,4 +1,19 @@
-2010-01-17	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
+2010-01-22	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
+
+	* artifacts/src/main/java/de/intevation/artifacts/ArtifactDatabase.java:
+	  Forgot to throw exception if service is not available.
+
+	* artifacts/src/main/java/de/intevation/artifacts/ServiceFactory.java:
+	  Fixed indention.
+
+	* artifact-database/src/main/java/de/intevation/artifactdatabase/FactoryBootstrap.java:
+	  Implemented service factory loading trivial. TODO: Load
+	  them from the configuration.
+
+	* artifact-database/src/main/java/de/intevation/artifactdatabase/ArtifactDatabaseImpl.java:
+	  Serve the services.
+
+2010-01-22	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
 
 	* artifact-database/src/main/java/de/intevation/artifactdatabase/DefaultService.java:
 	  Default implementation of a service. Useful as a base class.
@@ -7,7 +22,7 @@
 	  Default implementation of a service factory. Modelled right after
 	  DefaultArtifactFactory. Useful as a base class.
 
-2010-01-17	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
+2010-01-22	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
 
 	* artifacts/src/main/java/de/intevation/artifacts/Service.java: New.
 	  Interface to describe a service. It takes XML documents and produces
@@ -24,7 +39,7 @@
 	  Setting it up from configuration, do the processing, register
 	  urls in REST server and so on.
 
-2010-01-17	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
+2010-01-22	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
 
 	* artifact-database/src/main/java/de/intevation/artifactdatabase/XMLUtils.java:
 	  Added method 'toStream()' to copy a document into an output stream.
--- a/artifact-database/src/main/java/de/intevation/artifactdatabase/ArtifactDatabaseImpl.java	Fri Jan 22 10:19:27 2010 +0000
+++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/ArtifactDatabaseImpl.java	Fri Jan 22 11:08:40 2010 +0000
@@ -1,26 +1,28 @@
 package de.intevation.artifactdatabase;
 
+import de.intevation.artifactdatabase.Backend.PersistentArtifact;
+
+import de.intevation.artifacts.Artifact;
+import de.intevation.artifacts.ArtifactDatabase;
+import de.intevation.artifacts.ArtifactDatabaseException;
+import de.intevation.artifacts.ArtifactFactory;
+import de.intevation.artifacts.CallContext;
+import de.intevation.artifacts.CallMeta;
+import de.intevation.artifacts.Service;
+import de.intevation.artifacts.ServiceFactory;
+
+import java.io.IOException;
+import java.io.OutputStream;
+
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.HashSet;
-import java.util.ArrayList;
 import java.util.List;
 
-import de.intevation.artifacts.ArtifactDatabaseException;
-import de.intevation.artifacts.ArtifactDatabase;
-import de.intevation.artifacts.ArtifactFactory;
-import de.intevation.artifacts.Artifact;
-import de.intevation.artifacts.CallContext;
-import de.intevation.artifacts.CallMeta;
-
-import de.intevation.artifactdatabase.Backend.PersistentArtifact;
-
 import org.apache.log4j.Logger;
 
 import org.w3c.dom.Document;
 
-import java.io.OutputStream;
-import java.io.IOException;
-
 /**
  *  @author Sascha L. Teichmann
  */
@@ -48,6 +50,9 @@
     public static final String INTERNAL_ERROR =
         "Creation of artifact failed";
 
+    public static final String NO_SUCH_SERVICE =
+        "No such service";
+
     public class CallContextImpl
     implements   CallContext
     {
@@ -163,6 +168,9 @@
     protected String [][] factoryNamesAndDescription;
     protected HashMap     name2factory;
 
+    protected String [][] serviceNamesAndDescription;
+    protected HashMap     name2service;
+
     protected Backend     backend;
     protected Object      context;
 
@@ -178,6 +186,16 @@
     public ArtifactDatabaseImpl(FactoryBootstrap bootstrap, Backend backend) {
 
         backgroundIds = new HashSet();
+
+        setupArtifactFactories(bootstrap);
+        setupServices(bootstrap);
+
+        context = bootstrap.getContext();
+
+        wireWithBackend(backend);
+    }
+
+    protected void setupArtifactFactories(FactoryBootstrap bootstrap) {
         name2factory  = new HashMap();
 
         ArtifactFactory [] factories = bootstrap.getArtifactFactories();
@@ -195,10 +213,32 @@
 
             name2factory.put(name, factory);
         }
+    }
 
-        context = bootstrap.getContext();
+    protected void setupServices(FactoryBootstrap bootstrap) {
 
-        wireWithBackend(backend);
+        name2service  = new HashMap();
+
+        ServiceFactory [] serviceFactories =
+            bootstrap.getServiceFactories();
+
+        serviceNamesAndDescription =
+            new String[serviceFactories.length][];
+
+        for (int i = 0; i < serviceFactories.length; ++i) {
+            ServiceFactory factory = serviceFactories[i];
+
+            String name        = factory.getName();
+            String description = factory.getDescription();
+
+            serviceNamesAndDescription[i] =
+                new String [] { name, description };
+
+            name2service.put(
+                name,
+                factory.createService(bootstrap.getContext()));
+        }
+
     }
 
     public void wireWithBackend(Backend backend) {
@@ -384,11 +424,23 @@
     }
 
     public String [][] serviceNamesAndDescriptions() {
-        throw new IllegalArgumentException("Describing services is not implemented yet");
+        return serviceNamesAndDescription;
     }
 
-    public Document process(String service, Document input, CallMeta callMeta) {
-        throw new IllegalArgumentException("Service processing is not implemented yet");
+    public Document process(
+        String   serviceName, 
+        Document input,
+        CallMeta callMeta
+    )
+    throws ArtifactDatabaseException
+    {
+        Service service = (Service)name2service.get(serviceName);
+
+        if (service == null) {
+            throw new ArtifactDatabaseException(NO_SUCH_SERVICE);
+        }
+
+        return service.process(input, context, callMeta);
     }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8:
--- a/artifact-database/src/main/java/de/intevation/artifactdatabase/FactoryBootstrap.java	Fri Jan 22 10:19:27 2010 +0000
+++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/FactoryBootstrap.java	Fri Jan 22 11:08:40 2010 +0000
@@ -1,15 +1,15 @@
 package de.intevation.artifactdatabase;
 
+import de.intevation.artifacts.ArtifactContextFactory;
+import de.intevation.artifacts.ArtifactFactory;
+import de.intevation.artifacts.ServiceFactory;
+
+import java.util.ArrayList;
+
+import org.apache.log4j.Logger;
+
 import org.w3c.dom.Document;
 import org.w3c.dom.NodeList;
-
-import java.util.ArrayList;
-
-import de.intevation.artifacts.ArtifactFactory;
-import de.intevation.artifacts.ArtifactContextFactory;
-
-import org.apache.log4j.Logger;
-
 /**
  * Bootstrap facility for the global context and the artifact factories.
  *
@@ -121,6 +121,11 @@
         return artifactFactories;
     }
 
+    public ServiceFactory [] getServiceFactories() {
+        logger.warn("Service factories are not supported yet");
+        return new ServiceFactory[0];
+    }
+
     public Object getContext() {
         return context;
     }
--- a/artifacts/src/main/java/de/intevation/artifacts/ArtifactDatabase.java	Fri Jan 22 10:19:27 2010 +0000
+++ b/artifacts/src/main/java/de/intevation/artifacts/ArtifactDatabase.java	Fri Jan 22 11:08:40 2010 +0000
@@ -43,7 +43,8 @@
 
     String [][] serviceNamesAndDescriptions();
 
-    Document process(String service, Document input, CallMeta callMeta);
+    Document process(String service, Document input, CallMeta callMeta)
+        throws ArtifactDatabaseException;
 
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8:
--- a/artifacts/src/main/java/de/intevation/artifacts/ServiceFactory.java	Fri Jan 22 10:19:27 2010 +0000
+++ b/artifacts/src/main/java/de/intevation/artifacts/ServiceFactory.java	Fri Jan 22 11:08:40 2010 +0000
@@ -8,7 +8,7 @@
  * @author Sascha L. Teichmann (sascha.teichmann@intevation.de)
  */
 public interface ServiceFactory
-extends         Serializable
+extends          Serializable
 {
     String getName();
 

http://dive4elements.wald.intevation.org