changeset 293:a367a0d011af

Set an interface for the global context; added a method to the artifact database to return an instance of an Artifact. artifacts/trunk@2331 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Thu, 14 Jul 2011 14:22:23 +0000
parents 39c0ff00d188
children b530e83acf2e
files ChangeLog artifact-database/src/main/java/de/intevation/artifactdatabase/ArtifactDatabaseImpl.java artifact-database/src/main/java/de/intevation/artifactdatabase/DefaultArtifactContext.java artifact-database/src/main/java/de/intevation/artifactdatabase/DefaultArtifactContextFactory.java artifact-database/src/main/java/de/intevation/artifactdatabase/DefaultArtifactFactory.java artifact-database/src/main/java/de/intevation/artifactdatabase/FactoryBootstrap.java artifacts-common/src/main/java/de/intevation/artifacts/common/utils/ClientProtocolUtils.java artifacts/src/main/java/de/intevation/artifacts/ArtifactContextFactory.java artifacts/src/main/java/de/intevation/artifacts/ArtifactDatabase.java artifacts/src/main/java/de/intevation/artifacts/ArtifactFactory.java artifacts/src/main/java/de/intevation/artifacts/GlobalContext.java
diffstat 11 files changed, 116 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Wed Jul 13 13:12:08 2011 +0000
+++ b/ChangeLog	Thu Jul 14 14:22:23 2011 +0000
@@ -1,3 +1,28 @@
+2011-07-14  Ingo Weinzierl <ingo@intevation.de>
+
+	* artifacts/src/main/java/de/intevation/artifacts/GlobalContext.java: New.
+	  An interface for global context objects. It defines two basic operations
+	  to put objects into the context and to retrieve objects from context.
+
+	* artifacts/src/main/java/de/intevation/artifacts/ArtifactDatabase.java:
+	  Added a method that returns an instance of an Artifact with one
+	  limitation: the internal state of this artifact is not persisted to
+	  database!
+
+	* artifacts-common/src/main/java/de/intevation/artifacts/common/utils/ClientProtocolUtils.java:
+	  Added a method that creates a document used to create new Artifacts with
+	  the UUID of another one.
+
+	* artifact-database/src/main/java/de/intevation/artifactdatabase/ArtifactDatabaseImpl.java,
+	  artifact-database/src/main/java/de/intevation/artifactdatabase/FactoryBootstrap.java,
+	  artifact-database/src/main/java/de/intevation/artifactdatabase/DefaultArtifactContextFactory.java,
+	  artifact-database/src/main/java/de/intevation/artifactdatabase/DefaultArtifactContext.java,
+	  artifact-database/src/main/java/de/intevation/artifactdatabase/DefaultArtifactFactory.java,
+	  artifacts/src/main/java/de/intevation/artifacts/ArtifactFactory.java,
+	  artifacts/src/main/java/de/intevation/artifacts/ArtifactContextFactory.java:
+	  Adapted method signatures to apply the new interface for global context
+	  objects.
+
 2011-07-13  Ingo Weinzierl <ingo@intevation.de>
 
 	* artifacts/src/main/java/de/intevation/artifacts/Hook.java: New. A hook
--- a/artifact-database/src/main/java/de/intevation/artifactdatabase/ArtifactDatabaseImpl.java	Wed Jul 13 13:12:08 2011 +0000
+++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/ArtifactDatabaseImpl.java	Thu Jul 14 14:22:23 2011 +0000
@@ -23,6 +23,7 @@
 import de.intevation.artifacts.CallContext;
 import de.intevation.artifacts.CallMeta;
 import de.intevation.artifacts.CollectionItem;
+import de.intevation.artifacts.GlobalContext;
 import de.intevation.artifacts.Hook;
 import de.intevation.artifacts.Service;
 import de.intevation.artifacts.ServiceFactory;
@@ -68,6 +69,10 @@
     private static Logger logger =
         Logger.getLogger(ArtifactDatabaseImpl.class);
 
+    /** The key under which the artifact database is stored in the global
+     * context.*/
+    public static final String GLOBAL_CONTEXT_KEY = "global.artifact.database";
+
     /** Message that is returned if an operation was successful.*/
     public static final String OPERATION_SUCCESSFUL =
         "SUCCESS";
@@ -403,7 +408,7 @@
     /**
      * Reference of the global context of the artifact runtime system.
      */
-    protected Object      context;
+    protected GlobalContext context;
 
     /**
      * The signing secret to be used for ex-/importing artifacts.
@@ -463,7 +468,9 @@
         setupCallContextListener(bootstrap);
         setupHooks(bootstrap);
 
-        context      = bootstrap.getContext();
+        context = bootstrap.getContext();
+        context.put(GLOBAL_CONTEXT_KEY, this);
+
         exportSecret = bootstrap.getExportSecret();
 
         wireWithBackend(backend);
@@ -713,6 +720,20 @@
         }
     }
 
+
+    public Artifact getRawArtifact(String identifier)
+    throws ArtifactDatabaseException
+    {
+        PersistentArtifact artifact = backend.getArtifact(identifier);
+
+        if (artifact == null) {
+            throw new ArtifactDatabaseException(NO_SUCH_ARTIFACT);
+        }
+
+        return artifact.getArtifact();
+    }
+
+
     public Document describe(
         String   identifier,
         Document data,
--- a/artifact-database/src/main/java/de/intevation/artifactdatabase/DefaultArtifactContext.java	Wed Jul 13 13:12:08 2011 +0000
+++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/DefaultArtifactContext.java	Thu Jul 14 14:22:23 2011 +0000
@@ -12,13 +12,15 @@
 
 import org.w3c.dom.Document;
 
+import de.intevation.artifacts.GlobalContext;
+
 /**
  * Default implementation of the context.
  * Besides of the configuration it hosts a map to store key/value pairs.
  *
  * @author <a href="mailto:sascha.teichmann@intevation.de">Sascha L. Teichmann</a>
  */
-public class DefaultArtifactContext
+public class DefaultArtifactContext implements GlobalContext
 {
     /**
      * The global configuration document of the artifact database.
--- a/artifact-database/src/main/java/de/intevation/artifactdatabase/DefaultArtifactContextFactory.java	Wed Jul 13 13:12:08 2011 +0000
+++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/DefaultArtifactContextFactory.java	Thu Jul 14 14:22:23 2011 +0000
@@ -9,6 +9,7 @@
 package de.intevation.artifactdatabase;
 
 import de.intevation.artifacts.ArtifactContextFactory;
+import de.intevation.artifacts.GlobalContext;
 
 import org.w3c.dom.Document;
 
@@ -27,7 +28,7 @@
     public DefaultArtifactContextFactory() {
     }
 
-    public Object createArtifactContext(Document config) {
+    public GlobalContext createArtifactContext(Document config) {
         return new DefaultArtifactContext(config);
     }
 }
--- a/artifact-database/src/main/java/de/intevation/artifactdatabase/DefaultArtifactFactory.java	Wed Jul 13 13:12:08 2011 +0000
+++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/DefaultArtifactFactory.java	Thu Jul 14 14:22:23 2011 +0000
@@ -13,6 +13,7 @@
 import de.intevation.artifacts.Artifact;
 import de.intevation.artifacts.ArtifactFactory;
 import de.intevation.artifacts.ArtifactSerializer;
+import de.intevation.artifacts.GlobalContext;
 
 import org.apache.log4j.Logger;
 
@@ -100,9 +101,9 @@
     }
 
     public Artifact createArtifact(
-        String   identifier,
-        Object   context,
-        Document data
+        String        identifier,
+        GlobalContext context,
+        Document      data
     ) {
         try {
             Artifact artifact =
--- a/artifact-database/src/main/java/de/intevation/artifactdatabase/FactoryBootstrap.java	Wed Jul 13 13:12:08 2011 +0000
+++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/FactoryBootstrap.java	Thu Jul 14 14:22:23 2011 +0000
@@ -14,6 +14,7 @@
 import de.intevation.artifacts.ArtifactContextFactory;
 import de.intevation.artifacts.ArtifactFactory;
 import de.intevation.artifacts.CallContext;
+import de.intevation.artifacts.GlobalContext;
 import de.intevation.artifacts.Hook;
 import de.intevation.artifacts.ServiceFactory;
 import de.intevation.artifacts.UserFactory;
@@ -129,7 +130,7 @@
     /**
      * Reference to the global context build by the global context factory.
      */
-    protected Object context;
+    protected GlobalContext context;
 
     /**
      * List of the artifact factories to be exposed by the
@@ -571,7 +572,7 @@
      * Returns the global context created by the global context factory.
      * @return The global context.
      */
-    public Object getContext() {
+    public GlobalContext getContext() {
         return context;
     }
 
--- a/artifacts-common/src/main/java/de/intevation/artifacts/common/utils/ClientProtocolUtils.java	Wed Jul 13 13:12:08 2011 +0000
+++ b/artifacts-common/src/main/java/de/intevation/artifacts/common/utils/ClientProtocolUtils.java	Thu Jul 14 14:22:23 2011 +0000
@@ -71,6 +71,16 @@
      * @return the CREATE document.
      */
     public static Document newCreateDocument(String factory) {
+        return newCreateDocument(factory, null);
+    }
+
+
+    /**
+     * This method creates a new CREATE document.
+     *
+     * @return the CREATE document.
+     */
+    public static Document newCreateDocument(String factory, String uuid) {
         Document doc = XMLUtils.newDocument();
 
         XMLUtils.ElementCreator cr = new XMLUtils.ElementCreator(
@@ -88,6 +98,14 @@
         action.appendChild(type);
         action.appendChild(fac);
 
+        if (uuid != null) {
+            Element templ = cr.create("template");
+            templ.setAttribute("uuid", uuid);
+            action.appendChild(templ);
+        }
+
+
+
         doc.appendChild(action);
 
         return doc;
--- a/artifacts/src/main/java/de/intevation/artifacts/ArtifactContextFactory.java	Wed Jul 13 13:12:08 2011 +0000
+++ b/artifacts/src/main/java/de/intevation/artifacts/ArtifactContextFactory.java	Thu Jul 14 14:22:23 2011 +0000
@@ -24,6 +24,6 @@
      *   {@link de.intevation.artifacts.ArtifactFactory#createArtifact(String, Object, Document) createArtifact()}
      *   {@link de.intevation.artifacts.Artifact Artifact}
      */
-    Object createArtifactContext(Document config);
+    GlobalContext createArtifactContext(Document config);
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/artifacts/src/main/java/de/intevation/artifacts/ArtifactDatabase.java	Wed Jul 13 13:12:08 2011 +0000
+++ b/artifacts/src/main/java/de/intevation/artifacts/ArtifactDatabase.java	Thu Jul 14 14:22:23 2011 +0000
@@ -73,6 +73,13 @@
     ) throws ArtifactDatabaseException;
 
     /**
+     * Used to retrieve an artifact.<b>NOTE: artifact modifications are not
+     * persisted to database!</b>
+     */
+    Artifact getRawArtifact(String identifier)
+    throws ArtifactDatabaseException;
+
+    /**
      * Returns the describe document of artifact identified
      * with the string 'artifact'.
      * @param artifact The identifier of the artifact.
--- a/artifacts/src/main/java/de/intevation/artifacts/ArtifactFactory.java	Wed Jul 13 13:12:08 2011 +0000
+++ b/artifacts/src/main/java/de/intevation/artifacts/ArtifactFactory.java	Thu Jul 14 14:22:23 2011 +0000
@@ -13,6 +13,9 @@
 import org.w3c.dom.Document;
 import org.w3c.dom.Node;
 
+import de.intevation.artifacts.GlobalContext;
+
+
 /**
  * Interface of an artifact producing factory.
  *
@@ -40,7 +43,10 @@
      * @param data  the data containing more details for the setup of an Artifact.
      * @return a new {@linkplain de.intevation.artifacts.Artifact Artifact}
      */
-    Artifact createArtifact(String identifier, Object context, Document data);
+    Artifact createArtifact(
+        String        identifier,
+        GlobalContext context,
+        Document      data);
 
     /**
      * Setup the factory with a given configuration
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/artifacts/src/main/java/de/intevation/artifacts/GlobalContext.java	Thu Jul 14 14:22:23 2011 +0000
@@ -0,0 +1,23 @@
+package de.intevation.artifacts;
+
+public interface GlobalContext {
+
+    /**
+     * Fetch a custom value from the global key/value map using
+     * a given key.
+     * @param key The key.
+     * @return The stored value or null if no value was found under
+     * this key.
+     */
+    Object get(Object key);
+
+    /**
+     * Store a custom key/value pair in the global map.
+     * @param key The key to store
+     * @param value The value to store
+     * @return The old value registered under the key or null
+     * if none wa there before.
+     */
+    Object put(Object key, Object value);
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org