[PATCH 2 of 4] Use a list of "static" facets loaded from configuration to generate facets on artifact setup
Wald Commits
scm-commit at wald.intevation.org
Wed Apr 30 15:30:38 CEST 2014
# HG changeset patch
# User Raimund Renkert <rrenkert at intevation.de>
# Date 1398863154 -7200
# Node ID 69f99bdf3d65141019a1e405f5f7f092e05ac16f
# Parent ff79b8df9aa6c097393877b1f5389fa72061d743
Use a list of "static" facets loaded from configuration to generate facets on artifact setup.
diff -r ff79b8df9aa6 -r 69f99bdf3d65 artifact-database/src/main/java/org/dive4elements/artifactdatabase/DefaultArtifact.java
--- a/artifact-database/src/main/java/org/dive4elements/artifactdatabase/DefaultArtifact.java Wed Apr 30 15:04:14 2014 +0200
+++ b/artifact-database/src/main/java/org/dive4elements/artifactdatabase/DefaultArtifact.java Wed Apr 30 15:05:54 2014 +0200
@@ -17,6 +17,7 @@
import java.io.IOException;
import java.io.OutputStream;
+import java.util.List;
import org.apache.log4j.Logger;
@@ -124,7 +125,8 @@
ArtifactFactory factory,
Object context,
CallMeta callMeta,
- Document data)
+ Document data,
+ List<Class> facets)
{
if (logger.isDebugEnabled()) {
logger.debug("DefaultArtifact.setup: " + identifier);
diff -r ff79b8df9aa6 -r 69f99bdf3d65 artifact-database/src/main/java/org/dive4elements/artifactdatabase/DefaultArtifactFactory.java
--- a/artifact-database/src/main/java/org/dive4elements/artifactdatabase/DefaultArtifactFactory.java Wed Apr 30 15:04:14 2014 +0200
+++ b/artifact-database/src/main/java/org/dive4elements/artifactdatabase/DefaultArtifactFactory.java Wed Apr 30 15:05:54 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);
}
diff -r ff79b8df9aa6 -r 69f99bdf3d65 artifacts/src/main/java/org/dive4elements/artifacts/Artifact.java
--- a/artifacts/src/main/java/org/dive4elements/artifacts/Artifact.java Wed Apr 30 15:04:14 2014 +0200
+++ b/artifacts/src/main/java/org/dive4elements/artifacts/Artifact.java Wed Apr 30 15:05:54 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;
@@ -144,7 +145,8 @@
ArtifactFactory factory,
Object context,
CallMeta callMeta,
- Document data);
+ Document data,
+ List<Class> facets);
/**
* Called from artifact database when an artifact is
More information about the Dive4Elements-commits
mailing list