changeset 515:22d66b405b24

merged-
author Raimund Renkert <rrenkert@intevation.de>
date Wed, 30 Apr 2014 15:30:33 +0200
parents 0416d9fb3668 (diff) 439927f9cdc3 (current diff)
children 7bdc45945e5d 97dc9b8ae68a
files
diffstat 4 files changed, 129 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/artifact-database/src/main/java/org/dive4elements/artifactdatabase/DefaultArtifact.java	Fri Mar 07 18:41:09 2014 +0100
+++ b/artifact-database/src/main/java/org/dive4elements/artifactdatabase/DefaultArtifact.java	Wed Apr 30 15:30:33 2014 +0200
@@ -17,6 +17,7 @@
 
 import java.io.IOException;
 import java.io.OutputStream;
+import java.util.List;
 
 import org.apache.log4j.Logger;
 
@@ -36,6 +37,11 @@
      */
     protected String identifier;
 
+    /**
+     * The name of the artifact.
+     */
+    protected String name;
+
 
     /**
      * Default constructor.
@@ -119,7 +125,8 @@
         ArtifactFactory factory,
         Object          context,
         CallMeta        callMeta,
-        Document        data)
+        Document        data,
+        List<Class>     facets)
     {
         if (logger.isDebugEnabled()) {
             logger.debug("DefaultArtifact.setup: " + identifier);
@@ -138,5 +145,17 @@
             logger.debug("DefaultArtifact.cleanup: " + identifier);
         }
     }
+
+
+    @Override
+    public String getName() {
+        return name;
+    }
+
+
+    @Override
+    public void setName(String name) {
+        this.name = name;
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/artifact-database/src/main/java/org/dive4elements/artifactdatabase/DefaultArtifactFactory.java	Fri Mar 07 18:41:09 2014 +0100
+++ b/artifact-database/src/main/java/org/dive4elements/artifactdatabase/DefaultArtifactFactory.java	Wed Apr 30 15:30:33 2014 +0200
@@ -8,7 +8,15 @@
 
 package org.dive4elements.artifactdatabase;
 
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.xpath.XPathConstants;
+
 import org.dive4elements.artifacts.common.utils.Config;
+import org.dive4elements.artifacts.common.utils.XMLUtils;
 
 import org.dive4elements.artifacts.Artifact;
 import org.dive4elements.artifacts.ArtifactFactory;
@@ -20,6 +28,7 @@
 
 import org.w3c.dom.Document;
 import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
 
 /**
  * Trivial implementation of the ArtifactFactory interface.
@@ -53,6 +62,17 @@
      * by this factory.
      */
     public static final String XPATH_ARTIFACT    = "@artifact";
+    /**
+     * XPath to access the static facets configured for artifacts
+     */
+    public static final String XPATH_ARTIFACT_CONFIG =
+        "/artifact-database/artifacts/artifact[@name=$name]/load-facets/facet";
+
+    /**
+     * XPath to access the static facets configured for artifacts
+     */
+    public static final String XPATH_ARTIFACT_NAME =
+        "/artifact-database/artifacts/artifact/@name";
 
     /**
      * Default description of this factory if none is given by the
@@ -88,9 +108,20 @@
     protected Class  artifactClass;
 
     /**
+     * The name of the artifacts to be build by this factory.
+     */
+    protected String  artifactName;
+
+    /**
+     * The list of facets the generated artifact creates on instantiation.
+     */
+    protected List<Class> facetClasses;
+
+    /**
      * Default constructor.
      */
     public DefaultArtifactFactory() {
+        facetClasses = new ArrayList<Class>();
     }
 
     public String getName() {
@@ -111,7 +142,17 @@
             Artifact artifact =
                 (Artifact)artifactClass.newInstance();
 
-            artifact.setup(identifier, this, context, callMeta, data);
+            if (artifact.getName() == null ||
+                artifact.getName().length() == 0) {
+                artifact.setName(artifactName);
+            }
+            artifact.setup(
+                identifier,
+                this,
+                context,
+                callMeta,
+                data,
+                facetClasses);
 
             return artifact;
         }
@@ -129,7 +170,6 @@
     }
 
     public void setup(Document document, Node factoryNode) {
-
         String ttlString = Config.getStringXPath(factoryNode, XPATH_TTL);
         if (ttlString != null) {
             try {
@@ -145,10 +185,34 @@
 
         name = Config.getStringXPath(
             factoryNode, XPATH_NAME, toString());
+        logger.debug("setting up " + name);
 
         String artifact = Config.getStringXPath(
             factoryNode, XPATH_ARTIFACT, DEFAULT_ARTIFACT);
 
+        artifactName = Config.getStringXPath(
+            document, XPATH_ARTIFACT_NAME, "default");
+        logger.debug(artifactName);
+        Map<String, String> variables = new HashMap<String, String>();
+        variables.put("name", name);
+        NodeList facets = (NodeList) XMLUtils.xpath(
+            document,
+            XPATH_ARTIFACT_CONFIG,
+            XPathConstants.NODESET,
+            null,
+            variables);
+
+        for (int i = 0; i < facets.getLength(); i++) {
+            logger.debug(facets.item(i).getAttributes().getNamedItem("class").getNodeValue());
+            String className =
+                facets.item(i).getAttributes().getNamedItem("class").getNodeValue();
+            try {
+                facetClasses.add(Class.forName(className));
+            }
+            catch (ClassNotFoundException cnfe) {
+                logger.error(cnfe.getLocalizedMessage(), cnfe);
+            }
+        }
         try {
             artifactClass = Class.forName(artifact);
         }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/artifact-database/src/main/java/org/dive4elements/artifactdatabase/state/StaticFacet.java	Wed Apr 30 15:30:33 2014 +0200
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2014 by Intevation GmbH
+ *
+ * This program is free software under the LGPL (>=v2.1)
+ * Read the file LGPL.txt coming with the software for details
+ * or visit http://www.gnu.org/licenses/ if it does not exist.
+ */
+
+package org.dive4elements.artifactdatabase.state;
+
+import java.io.Serializable;
+
+import org.dive4elements.artifacts.Artifact;
+import org.dive4elements.artifacts.CallMeta;
+import org.w3c.dom.Document;
+
+
+public interface StaticFacet
+extends Facet
+{
+    /**
+     * Setup the static facet by parsing the data document.
+     *
+     * @param artifact  The artifact
+     * @param data      The document
+     * @param meat      The call meta
+     */
+    public void setup(Artifact artifact, Document data, CallMeta meta);
+}
--- a/artifacts/src/main/java/org/dive4elements/artifacts/Artifact.java	Fri Mar 07 18:41:09 2014 +0100
+++ b/artifacts/src/main/java/org/dive4elements/artifacts/Artifact.java	Wed Apr 30 15:30:33 2014 +0200
@@ -11,6 +11,7 @@
 import java.io.IOException;
 import java.io.OutputStream;
 import java.io.Serializable;
+import java.util.List;
 
 import org.w3c.dom.Document;
 
@@ -46,6 +47,17 @@
 public interface Artifact
 extends          Serializable
 {
+    /**
+     * The artifact name.
+     * @return The name of the artifact.
+     */
+    public String getName();
+
+    /**
+     * Set the artifact name.
+     * @param name The name of the artifact.
+     */
+    public void setName(String name);
 
     /**
      * Set a new identifier for this artifact.
@@ -133,7 +145,8 @@
         ArtifactFactory factory,
         Object          context,
         CallMeta        callMeta,
-        Document        data);
+        Document        data,
+        List<Class>     facets);
 
     /**
      * Called from artifact database when an artifact is

http://dive4elements.wald.intevation.org