changeset 478:0e0c64c821dc

Added support to step back to the point for choosing a product. gnv-artifacts/trunk@547 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Fri, 15 Jan 2010 18:21:49 +0000
parents 40a058047854
children d47b478e662b
files gnv-artifacts/ChangeLog gnv-artifacts/doc/conf/conf.xml gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/GNVArtifactBase.java gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/GNVArtifactFactory.java gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/GNVProductArtifactFactory.java gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/fis/FISArtifact.java gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/fis/SelectProductArtifact.java gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/fis/product/DefaultProduct.java gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/fis/product/Product.java
diffstat 9 files changed, 290 insertions(+), 602 deletions(-) [+]
line wrap: on
line diff
--- a/gnv-artifacts/ChangeLog	Fri Jan 15 10:13:18 2010 +0000
+++ b/gnv-artifacts/ChangeLog	Fri Jan 15 18:21:49 2010 +0000
@@ -1,3 +1,37 @@
+2010-01-15  Ingo Weinzierl <ingo.weinzierl@intevation.de>
+
+	  Added support to step back to the point where the user is able to choose
+	  the product of a FIS.
+
+	* src/main/java/de/intevation/gnv/artifacts/GNVArtifactFactory.java,
+	  src/main/java/de/intevation/gnv/artifacts/GNVProductArtifactFactory.java:
+	  Cleaned up factories regarding their tasks. GNVArtifactFactory creates
+	  concrete products. GNVProductArtifactFactory handles all FIS and knows 
+	  the products of a FIS.
+
+	* src/main/java/de/intevation/gnv/artifacts/fis/FISArtifact.java: Removed,
+	  because it is not used anymore.
+
+	* src/main/java/de/intevation/gnv/artifacts/fis/product/Product.java,
+	  src/main/java/de/intevation/gnv/artifacts/fis/product/DefaultProduct.java:
+	  A Product does no longer save its factory but the name of its factory as
+	  string.
+
+	* src/main/java/de/intevation/gnv/artifacts/fis/SelectProductArtifact.java:
+	  This artifact will no longer read the config file to get information about
+	  the products of a fis.  The products are set via setter method out of the
+	  ArtifactFactory where this artifact is build.
+
+	* src/main/java/de/intevation/gnv/artifacts/GNVArtifactBase.java: Added the
+	  possibility to step back to the point where the user can choose a product.
+	  If the target of advance is 'product' we fetch the
+	  GNVProductArtifactFactory from ArtifactDatabase and create a new
+	  SelectProductArtifact, put it into the ProxyArtifact and clean up the ugly
+	  cache.
+
+	* doc/conf/conf.xml: Create top level FIS artifacts with
+	  GNVProductArtifactFactory instead of GNVArtifactFactory.
+
 2010-01-15  Tim Englich  <tim.englich@intevation.de>
 
 	* doc/conf/arcsdeconnectionpool.properties: 
--- a/gnv-artifacts/doc/conf/conf.xml	Fri Jan 15 10:13:18 2010 +0000
+++ b/gnv-artifacts/doc/conf/conf.xml	Fri Jan 15 18:21:49 2010 +0000
@@ -3,37 +3,37 @@
         <context-factory>de.intevation.gnv.artifacts.context.GNVArtifactContextFactory</context-factory>
         <artifact-factories>
             <artifact-factory name="fis_marnet" description="Factory to create an artifact to be used with the FIS Marnet"  
-                              ttl="3600000" artifact="de.intevation.artifactdatabase.ProxyArtifact">de.intevation.gnv.artifacts.GNVArtifactFactory</artifact-factory>
+                              ttl="3600000" artifact="de.intevation.artifactdatabase.ProxyArtifact">de.intevation.gnv.artifacts.GNVProductArtifactFactory</artifact-factory>
             <artifact-factory name="fis_imis" description="Factory to create an artifact to be used with the FIS IMIS"  
-                              ttl="3600000" artifact="de.intevation.artifactdatabase.ProxyArtifact">de.intevation.gnv.artifacts.GNVArtifactFactory</artifact-factory>
+                              ttl="3600000" artifact="de.intevation.artifactdatabase.ProxyArtifact">de.intevation.gnv.artifacts.GNVProductArtifactFactory</artifact-factory>
             <artifact-factory name="fis_staun" description="Factory to create an artifact to be used with the FIS STAUN"  
-                              ttl="3600000" artifact="de.intevation.artifactdatabase.ProxyArtifact">de.intevation.gnv.artifacts.GNVArtifactFactory</artifact-factory>
+                              ttl="3600000" artifact="de.intevation.artifactdatabase.ProxyArtifact">de.intevation.gnv.artifacts.GNVProductArtifactFactory</artifact-factory>
             <artifact-factory name="fis_modeldata" description="Factory to create an artifact to be used with the FIS Modeldata"  
-                              ttl="3600000" artifact="de.intevation.artifactdatabase.ProxyArtifact">de.intevation.gnv.artifacts.GNVArtifactFactory</artifact-factory>
+                              ttl="3600000" artifact="de.intevation.artifactdatabase.ProxyArtifact">de.intevation.gnv.artifacts.GNVProductArtifactFactory</artifact-factory>
             <artifact-factory name="fis_eisklimatologie" description="Factory to create an artifact to be used with the FIS Modeldata"  
-                              ttl="3600000" artifact="de.intevation.artifactdatabase.ProxyArtifact">de.intevation.gnv.artifacts.GNVArtifactFactory</artifact-factory>
+                              ttl="3600000" artifact="de.intevation.artifactdatabase.ProxyArtifact">de.intevation.gnv.artifacts.GNVProductArtifactFactory</artifact-factory>
             <artifact-factory name="fis_icestations" description="Factory to create an artifact to be used with the FIS Modeldata"  
-                              ttl="3600000" artifact="de.intevation.artifactdatabase.ProxyArtifact">de.intevation.gnv.artifacts.GNVArtifactFactory</artifact-factory>
+                              ttl="3600000" artifact="de.intevation.artifactdatabase.ProxyArtifact">de.intevation.gnv.artifacts.GNVProductArtifactFactory</artifact-factory>
             <artifact-factory name="fis_sst" description="Factory to create an artifact to be used with the FIS Modeldata"  
-                              ttl="3600000" artifact="de.intevation.artifactdatabase.ProxyArtifact">de.intevation.gnv.artifacts.GNVArtifactFactory</artifact-factory>
+                              ttl="3600000" artifact="de.intevation.artifactdatabase.ProxyArtifact">de.intevation.gnv.artifacts.GNVProductArtifactFactory</artifact-factory>
             <artifact-factory name="fis_delphin" description="Factory to create an artifact to be used with the FIS Modeldata"  
-                              ttl="3600000" artifact="de.intevation.artifactdatabase.ProxyArtifact">de.intevation.gnv.artifacts.GNVArtifactFactory</artifact-factory>
+                              ttl="3600000" artifact="de.intevation.artifactdatabase.ProxyArtifact">de.intevation.gnv.artifacts.GNVProductArtifactFactory</artifact-factory>
             <artifact-factory name="fis_thermosalinograph" description="Factory to create an artifact to be used with the FIS Modeldata"  
-                              ttl="3600000" artifact="de.intevation.artifactdatabase.ProxyArtifact">de.intevation.gnv.artifacts.GNVArtifactFactory</artifact-factory>
+                              ttl="3600000" artifact="de.intevation.artifactdatabase.ProxyArtifact">de.intevation.gnv.artifacts.GNVProductArtifactFactory</artifact-factory>
             <artifact-factory name="fis_chemusurvey" description="Factory to create an artifact to be used with the FIS Modeldata"  
-                              ttl="3600000" artifact="de.intevation.artifactdatabase.ProxyArtifact">de.intevation.gnv.artifacts.GNVArtifactFactory</artifact-factory>
+                              ttl="3600000" artifact="de.intevation.artifactdatabase.ProxyArtifact">de.intevation.gnv.artifacts.GNVProductArtifactFactory</artifact-factory>
             <artifact-factory name="fis_gts" description="Factory to create an artifact to be used with the FIS Modeldata"  
-                              ttl="3600000" artifact="de.intevation.artifactdatabase.ProxyArtifact">de.intevation.gnv.artifacts.GNVArtifactFactory</artifact-factory>
+                              ttl="3600000" artifact="de.intevation.artifactdatabase.ProxyArtifact">de.intevation.gnv.artifacts.GNVProductArtifactFactory</artifact-factory>
             <artifact-factory name="fis_bsh_ctd" description="Factory to create an artifact to be used with the FIS Modeldata"  
-                              ttl="3600000" artifact="de.intevation.artifactdatabase.ProxyArtifact">de.intevation.gnv.artifacts.GNVArtifactFactory</artifact-factory>
+                              ttl="3600000" artifact="de.intevation.artifactdatabase.ProxyArtifact">de.intevation.gnv.artifacts.GNVProductArtifactFactory</artifact-factory>
             <artifact-factory name="fis_bsh_xbt" description="Factory to create an artifact to be used with the FIS Modeldata"  
-                              ttl="3600000" artifact="de.intevation.artifactdatabase.ProxyArtifact">de.intevation.gnv.artifacts.GNVArtifactFactory</artifact-factory>
+                              ttl="3600000" artifact="de.intevation.artifactdatabase.ProxyArtifact">de.intevation.gnv.artifacts.GNVProductArtifactFactory</artifact-factory>
             <artifact-factory name="fis_seacat" description="Factory to create an artifact to be used with the FIS Modeldata"  
-                              ttl="3600000" artifact="de.intevation.artifactdatabase.ProxyArtifact">de.intevation.gnv.artifacts.GNVArtifactFactory</artifact-factory>
+                              ttl="3600000" artifact="de.intevation.artifactdatabase.ProxyArtifact">de.intevation.gnv.artifacts.GNVProductArtifactFactory</artifact-factory>
             <artifact-factory name="fis_seastate" description="Factory to create an artifact to be used with the FIS Modeldata"  
-                              ttl="3600000" artifact="de.intevation.artifactdatabase.ProxyArtifact">de.intevation.gnv.artifacts.GNVArtifactFactory</artifact-factory>
+                              ttl="3600000" artifact="de.intevation.artifactdatabase.ProxyArtifact">de.intevation.gnv.artifacts.GNVProductArtifactFactory</artifact-factory>
             <artifact-factory name="fis_currentmeter" description="Factory to create an artifact to be used with the FIS Modeldata"  
-                              ttl="3600000" artifact="de.intevation.artifactdatabase.ProxyArtifact">de.intevation.gnv.artifacts.GNVArtifactFactory</artifact-factory>
+                              ttl="3600000" artifact="de.intevation.artifactdatabase.ProxyArtifact">de.intevation.gnv.artifacts.GNVProductArtifactFactory</artifact-factory>
         </artifact-factories>
     </factories>
     
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/GNVArtifactBase.java	Fri Jan 15 10:13:18 2010 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/GNVArtifactBase.java	Fri Jan 15 18:21:49 2010 +0000
@@ -22,6 +22,9 @@
 import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
 
+import de.intevation.artifacts.Artifact;
+import de.intevation.artifacts.ArtifactDatabase;
+import de.intevation.artifactdatabase.ArtifactDatabaseImpl;
 import de.intevation.artifactdatabase.Config;
 import de.intevation.artifactdatabase.DefaultArtifact;
 import de.intevation.artifactdatabase.ProxyArtifact;
@@ -87,7 +90,7 @@
 
     public static final String XPATH_OUTPUT_PARAMS = "/art:action/art:out/art:params/art:input"; 
 
-    public static final String INITIAL_STATE = "start";
+    public static final String INITIAL_STATE = "product";
 
     /**
      * The current State
@@ -177,7 +180,7 @@
 
                 // remove data from future states from cache
                 resetDescribeData(current, identifier, targetState);
-                
+
                 current = next;
 
                 result = createReport(
@@ -187,10 +190,17 @@
 
             // goto initial step
             else if(targetState.equals(INITIAL_STATE)) {
-                SelectProductArtifact select = new SelectProductArtifact();
-                select.setup(identifier, new GNVArtifactFactory(), context);
+
+                String fis                    = product.getArtifactFactory();
+                ArtifactDatabase db           = context.getDatabase();
+                GNVProductArtifactFactory fac = (GNVProductArtifactFactory)
+                    db.getInternalArtifactFactory(fis);
+
+                Artifact select = fac.createArtifact(identifier, context);
                 context.putContextValue(ProxyArtifact.REPLACE_PROXY, select);
 
+                resetDescribeData(current, identifier, INITIAL_STATE);
+
                 result = createReport(
                     result, "result", "success", "Advance success"
                 );
@@ -273,6 +283,9 @@
             while(!target.equals(state.getID())) {
                 data.remove(data.size()-1);
                 state = state.getParent();
+
+                if (state == null)
+                    break;
             }
 
             cache.put(new net.sf.ehcache.Element(key, data));
@@ -413,8 +426,16 @@
             XMLUtils.XFORM_PREFIX
         );
 
+        XMLUtils.ElementCreator artCreator = new XMLUtils.ElementCreator(
+            document,
+            ArtifactNamespaceContext.NAMESPACE_URI,
+            ArtifactNamespaceContext.NAMESPACE_PREFIX
+        );
+
         if (staticNode != null) {
-            Element staticUI = createSelectBox(creator, document, context);
+            Element staticUI = createSelectBox(
+                artCreator, creator, document, context
+            );
             staticNode.insertBefore(staticUI, staticNode.getFirstChild());
         }
 
@@ -502,7 +523,6 @@
         if (value != null){
             includeUI = Boolean.parseBoolean(value);
         }
-        log.debug("INCLUDE UI? " + includeUI);
         return includeUI;
     }
 
@@ -520,7 +540,7 @@
         Element                 parent,
         Document                document,
         String                  documentType
-    ) { 
+    ) {
         Element typeNode = creator.create("type");
         creator.addAttr(typeNode, "name", documentType);
         parent.appendChild(typeNode);
@@ -535,16 +555,19 @@
     }
 
     protected Element createSelectBox(
+        XMLUtils.ElementCreator artCreator,
         XMLUtils.ElementCreator creator,
         Document                document,
         CallContext             context
     ) {
         RessourceFactory resource = RessourceFactory.getInstance();
         CallMeta callMeta         = (CallMeta) context.getMeta();
-        String productName        = product.getName(); 
+        String productName        = product.getName();
 
         Element selectNode = creator.create("select1");
         creator.addAttr(selectNode, "ref", "product");
+        artCreator.addAttr(selectNode, "state", INITIAL_STATE, true);
+
 
         Element labelNode = creator.create("label");
         labelNode.setTextContent(
@@ -671,12 +694,15 @@
         Element uiNode = creator.create("ui");
 
         if (this.current != null) {
-            this.current.describe(document, uiNode, callMeta, uuid);
+            this.current.describe(
+                document, uiNode, callMeta, uuid
+            );
         }
 
         parent.appendChild(uiNode);
     }
 
+
     protected void createOutputs(
         XMLUtils.ElementCreator creator,
         Element                 parent,
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/GNVArtifactFactory.java	Fri Jan 15 10:13:18 2010 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/GNVArtifactFactory.java	Fri Jan 15 18:21:49 2010 +0000
@@ -1,34 +1,28 @@
 package de.intevation.gnv.artifacts;
 
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+
+import org.apache.log4j.Logger;
+
 import de.intevation.artifactdatabase.DefaultArtifactFactory;
-import de.intevation.artifactdatabase.ProxyArtifact;
-import de.intevation.artifacts.Artifact;
-import de.intevation.gnv.artifacts.fis.SelectProductArtifact;
 
-import org.apache.log4j.Logger;
 
 /**
  * @author Ingo Weinzierl <ingo.weinzierl@intevation.de>
  */
 public class GNVArtifactFactory extends DefaultArtifactFactory {
 
+    public static final String XPATH_PRODUCT_FACTORY   = "artifact-factory";
+
     private static Logger logger = Logger.getLogger(GNVArtifactFactory.class);
 
     public GNVArtifactFactory() {
     }
 
     @Override
-    public Artifact createArtifact(String identifier, Object context) {
-        Artifact artifact = super.createArtifact(identifier, context);
-
-        if (artifact instanceof ProxyArtifact) {
-            SelectProductArtifact select = new SelectProductArtifact();
-            select.setup(identifier, this, context);
-
-            ((ProxyArtifact) artifact).setProxied(select);
-        }
-
-        return artifact;
+    public void setup(Document document, Node factoryNode) {
+        super.setup(document, factoryNode);
     }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8:
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/GNVProductArtifactFactory.java	Fri Jan 15 18:21:49 2010 +0000
@@ -0,0 +1,174 @@
+package de.intevation.gnv.artifacts;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+import javax.xml.xpath.XPathConstants;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+import de.intevation.artifactdatabase.DefaultArtifactFactory;
+import de.intevation.artifactdatabase.ProxyArtifact;
+import de.intevation.artifactdatabase.XMLUtils;
+import de.intevation.artifacts.Artifact;
+import de.intevation.artifacts.ArtifactFactory;
+import de.intevation.gnv.artifacts.fis.SelectProductArtifact;
+import de.intevation.gnv.artifacts.fis.product.DefaultProduct;
+import de.intevation.gnv.state.DefaultInputData;
+import de.intevation.gnv.state.InputData;
+
+import org.apache.log4j.Logger;
+
+/**
+ * @author Ingo Weinzierl <ingo.weinzierl@intevation.de>
+ */
+public class GNVProductArtifactFactory extends DefaultArtifactFactory {
+
+    public static final String XPATH_REPLACE_NAME = "IDENTIFIER";
+
+    public static final String XPATH_PRODUCT_ARTIFACT =
+        "artifact-database/artifacts/artifact[@name='"+XPATH_REPLACE_NAME+"']";
+
+    public static final String XPATH_PRODUCT = "products/product";
+
+    public static final String XPATH_PRODUCT_NAME = "@name";
+
+    public static final String XPATH_PRODUCT_FACTORY = "artifact-factory";
+
+    public static final String XPATH_PRODUCT_PARAMETER = "parameters/parameter";
+
+    private Logger logger = Logger.getLogger(GNVProductArtifactFactory.class);
+
+    private Map productFactories;
+    private Map products;
+
+
+    public GNVProductArtifactFactory() {
+    }
+
+    @Override
+    public Artifact createArtifact(String identifier, Object context) {
+
+        // create a SelectProductArtifact for initial product selection
+        Artifact artifact = super.createArtifact(identifier, context);
+
+        if (artifact instanceof ProxyArtifact) {
+
+            SelectProductArtifact select = new SelectProductArtifact();
+            select.setProducts(products);
+            select.setup(identifier, this, context);
+
+            ((ProxyArtifact) artifact).setProxied(select);
+        }
+
+        return artifact;
+    }
+
+    @Override
+    public void setup(Document document, Node factoryNode) {
+        super.setup(document, factoryNode);
+
+        String xpath  = XPATH_PRODUCT_ARTIFACT.replace(XPATH_REPLACE_NAME, name);
+        Node artifact = (Node) XMLUtils.xpath(
+            document, xpath, XPathConstants.NODE);
+
+        NodeList productNodes = (NodeList) XMLUtils.xpath(
+            artifact, XPATH_PRODUCT, XPathConstants.NODESET);
+
+        if (productNodes == null) {
+            logger.warn("No products found for fis: " + name);
+            return;
+        }
+
+        int productLength = productNodes.getLength();
+
+        if (productLength != 0) {
+            productFactories = new HashMap(productLength);
+            products         = new HashMap(productLength);
+
+            parseProductFactories(document, productNodes);
+        }
+    }
+
+
+    public ArtifactFactory getArtifactFactoryByName(String name) {
+        return (ArtifactFactory) productFactories.get(name);
+    }
+
+
+    protected void parseProductFactories(Document document, NodeList products) {
+        int items = products.getLength();
+
+        for(int i = 0; i < items; i++) {
+
+            try {
+                Node product = products.item(i);
+
+                String name = (String) XMLUtils.xpath(
+                    product, XPATH_PRODUCT_NAME, XPathConstants.STRING);
+
+                Node factoryNode = (Node) XMLUtils.xpath(
+                    product, XPATH_PRODUCT_FACTORY, XPathConstants.NODE);
+
+                String factoryClass = factoryNode.getTextContent();
+
+                if (factoryClass == null || factoryClass.equals("")) {
+                    logger.warn("No artifact factory class found for " + name);
+                    continue;
+                }
+
+                Class cls               = Class.forName(factoryClass);
+                ArtifactFactory factory = (ArtifactFactory) cls.newInstance();
+                factory.setup(document, factoryNode);
+
+                productFactories.put(name, factory);
+                initializeProducts(product);
+            }
+            catch (ClassNotFoundException cnfe) {
+                logger.warn(cnfe, cnfe);
+            }
+            catch (InstantiationException ie) {
+                logger.warn(ie, ie);
+            }
+            catch (IllegalAccessException iae) {
+                logger.warn(iae, iae);
+            }
+        }
+    }
+
+
+    protected void initializeProducts(Node productNode) {
+        String productName = (String) XMLUtils.xpath(
+            productNode, "@name", XPathConstants.STRING);
+
+        NodeList parameterNodes = (NodeList) XMLUtils.xpath(
+            productNode, XPATH_PRODUCT_PARAMETER, XPathConstants.NODESET
+        );
+
+        if (parameterNodes != null) {
+            int items = parameterNodes.getLength();
+            Collection inputParameter = new ArrayList(items);
+
+            for (int j = 0; j < items; j++) {
+                Node parameterNode = (Node) parameterNodes.item(j);
+                String name        = (String) XMLUtils.xpath(
+                    parameterNode, "@name", XPathConstants.STRING);
+                String value       = (String) XMLUtils.xpath(
+                    parameterNode, "@value", XPathConstants.STRING);
+
+                inputParameter.add(new DefaultInputData(name, value));
+            }
+
+            products.put(
+                productName,
+                new DefaultProduct(productName, inputParameter, this.name)
+            );
+        }
+    }
+}
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/fis/FISArtifact.java	Fri Jan 15 10:13:18 2010 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,478 +0,0 @@
-/**
- *
- */
-package de.intevation.gnv.artifacts.fis;
-
-import java.io.IOException;
-import java.io.OutputStream;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-
-import org.apache.log4j.Logger;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-
-import de.intevation.artifactdatabase.Config;
-import de.intevation.artifactdatabase.DefaultArtifact;
-import de.intevation.artifactdatabase.XMLUtils;
-import de.intevation.artifacts.Artifact;
-import de.intevation.artifacts.ArtifactFactory;
-import de.intevation.artifacts.CallContext;
-import de.intevation.artifacts.CallMeta;
-import de.intevation.gnv.artifacts.GNVArtifactBase;
-import de.intevation.gnv.artifacts.context.GNVArtifactContext;
-import de.intevation.gnv.artifacts.fis.product.DefaultProduct;
-import de.intevation.gnv.artifacts.fis.product.Product;
-import de.intevation.gnv.artifacts.ressource.RessourceFactory;
-import de.intevation.gnv.state.DefaultInputData;
-import de.intevation.gnv.state.InputData;
-import de.intevation.gnv.utils.ArtifactFactoryUtilities;
-import de.intevation.gnv.utils.ArtifactXMLUtilities;
-
-/**
- * @author Tim Englich <tim.englich@intevation.de>
- * 
- */
-public class FISArtifact extends DefaultArtifact {
-
-    /**
-     * the logger, used to log exceptions and additonaly information
-     */
-    private static Logger log = Logger.getLogger(GNVArtifactBase.class);
-    /**
-     * The UID of this Class
-     */
-    private static final long serialVersionUID = 2874044542701727083L;
-
-    /**
-     * The Identifier for the Replacement of the Artifactname
-     */
-    public static final String XPATH_IDENTIFIER_REPLACE = "IDENTIFIER";
-
-    /**
-     * The XPATH to the XML-Fragment that should be used for the Configuration
-     */
-    public static final String XPATH_ARTIFACT_CONFIGURATION = "/artifact-database/artifacts/artifact[@name='"
-                                                              + XPATH_IDENTIFIER_REPLACE
-                                                              + "']";
-
-    /**
-     * The Name of the Artifact
-     */
-    private String name = null;
-
-    private Map<String, Product> products = null;
-
-    private Artifact productArtifact = null;
-
-    private Product current = null;
-
-    private ArtifactXMLUtilities xmlUtilities = new ArtifactXMLUtilities();
-
-    /**
-     * @see de.intevation.artifactdatabase.DefaultArtifact#advance(org.w3c.dom.Document,
-     *      de.intevation.artifacts.CallContext)
-     */
-    @Override
-    public Document advance(Document target, CallContext context) {
-
-        Document result = null;
-        if (this.productArtifact == null) {
-            if (this.current != null) {
-
-                String uuid = Config.getStringXPath(target,
-                        "action/uuid/@value");
-                String hash = Config.getStringXPath(target,
-                        "action/hash/@value");
-                this.productArtifact = this.current.getArtifactFactory()
-                        .createArtifact(uuid, context);
-                
-                Document feedDocument = xmlUtilities.reInitDocument(this
-                        .createFeedProductArtifactDocument(uuid, hash));
-                log.debug("Feed ==> "
-                          + this.xmlUtilities
-                                  .writeDocument2String(feedDocument));
-                this.productArtifact.feed(feedDocument, context);
-                result = ((GNVArtifactBase)this.productArtifact).initialize(context);
-            } else {
-                String msg = "Artifact is not configured properly. Call feed first.";
-                log.error(msg);
-                result = new ArtifactXMLUtilities().createExceptionReport(msg,
-                        XMLUtils.newDocument());
-            }
-        } else {
-            result = this.productArtifact.advance(target, context);
-        }
-        return result;
-    }
-    
-    private Document createDescribeRequestBody(String uuid, 
-                                               String hash,
-                                               boolean includeUI){
-        Document document = XMLUtils.newDocument();
-        
-        Element rootNode = xmlUtilities.createArtifactElement(document,"action");
-        document.appendChild(rootNode);
-        
-        Element typeNode = this.xmlUtilities.createArtifactElement(document, "type");
-        typeNode.setAttribute("name", "describe");
-        rootNode.appendChild(typeNode);
-        
-        Element uuidNode = this.xmlUtilities.createArtifactElement(document, "uuid");
-        uuidNode.setAttribute("value",uuid);
-        rootNode.appendChild(uuidNode);
-        
-        Element hashNode = this.xmlUtilities.createArtifactElement(document, "hash");
-        hashNode.setAttribute("value", hash);
-        rootNode.appendChild(hashNode);
-        
-        Element includeUINode =  this.xmlUtilities.createArtifactElement(document, "include-ui");
-        includeUINode.setTextContent(""+includeUI);
-        rootNode.appendChild(includeUINode);
-        
-        return document;
-    }
-
-    private Document createAdvanceProductArtifactDocument(String uuid,
-                                                          String hash,
-                                                          String targetName) {
-        Document document = XMLUtils.newDocument();
-        Element rootNode = xmlUtilities.createArtifactElement(document,
-                "action");
-
-        Element typeNode = xmlUtilities.createArtifactElement(document, "type");
-        typeNode.setAttribute("name", "advanve");
-        rootNode.appendChild(typeNode);
-
-        Element uuidNode = xmlUtilities.createArtifactElement(document, "uuid");
-        uuidNode.setAttribute("value", uuid);
-        rootNode.appendChild(uuidNode);
-
-        Element hashNode = xmlUtilities.createArtifactElement(document, "hash");
-        hashNode.setAttribute("value", hash);
-        rootNode.appendChild(hashNode);
-        Element targetNode = xmlUtilities.createArtifactElement(document,
-                "target");
-        targetNode.setAttribute("name", targetName);
-        rootNode.appendChild(targetNode);
-
-        document.appendChild(rootNode);
-        return document;
-    }
-
-    private Document createFeedProductArtifactDocument(String uuid, String hash) {
-        Document document = XMLUtils.newDocument();
-        Element rootNode = xmlUtilities.createArtifactElement(document,
-                "action");
-
-        Element typeNode = xmlUtilities.createArtifactElement(document, "type");
-        typeNode.setAttribute("name", "feed");
-        rootNode.appendChild(typeNode);
-
-        Element uuidNode = xmlUtilities.createArtifactElement(document, "uuid");
-        uuidNode.setAttribute("value", uuid);
-        rootNode.appendChild(uuidNode);
-
-        Element hashNode = xmlUtilities.createArtifactElement(document, "hash");
-        hashNode.setAttribute("value", hash);
-        rootNode.appendChild(hashNode);
-
-        Element dataNode = xmlUtilities.createArtifactElement(document, "data");
-        rootNode.appendChild(dataNode);
-
-        Collection<InputData> parameter = this.current.getParameter();
-        if (parameter != null) {
-            Iterator<InputData> parameterIt = parameter.iterator();
-            while (parameterIt.hasNext()) {
-                InputData inputData = parameterIt.next();
-                Element inputNode = xmlUtilities.createArtifactElement(
-                        document, "input");
-                inputNode.setAttribute("name", inputData.getName());
-                inputNode.setAttribute("value", inputData.getValue());
-                dataNode.appendChild(inputNode);
-            }
-        }
-        document.appendChild(rootNode);
-        return document;
-
-    }
-
-    /**
-     * @see de.intevation.artifactdatabase.DefaultArtifact#describe(org.w3c.dom.Document, de.intevation.artifacts.CallContext)
-     */
-    @Override
-    public Document describe(Document data, CallContext context) {
-        if (this.productArtifact == null) {
-            return this.createDescibeOutput(context.getMeta());
-        } else {
-            Document document = this.productArtifact.describe(data,context);
-            document = new ArtifactXMLUtilities().reInitDocument(document);
-            Node staticNode = Config
-                    .getNodeXPath(document, "/result/ui/static");
-            if (staticNode != null) {
-                Node staticUI = this.createSelectBox(document, context
-                        .getMeta());
-                staticNode.insertBefore(staticUI, staticNode.getFirstChild());
-            }
-            return document;
-        }
-    }
-
-
-    /**
-     * @see de.intevation.artifactdatabase.DefaultArtifact#feed(org.w3c.dom.Document,
-     *      java.lang.Object)
-     */
-    @Override
-    public Document feed(Document target, CallContext context) {
-        log.debug("FISArtifact.feed");
-        Document result = null;
-        if (this.productArtifact == null) {
-            String productName = Config.getStringXPath(target,
-                    "action/data/input[@name='product']/@value");
-            log.debug("Looking for ProductArtifact " + productName);
-            if (this.products.containsKey(productName)) {
-                this.current = this.products.get(productName);
-                result = new ArtifactXMLUtilities().createSuccessReport(
-                        "Feed success New ProductArtifact created", XMLUtils
-                                .newDocument());
-            } else {
-                String msg = "Product does not exists for " + productName;
-                log.error(msg);
-                result = new ArtifactXMLUtilities().createExceptionReport(msg,
-                        XMLUtils.newDocument());
-            }
-        } else {
-            log.debug("Feed a Productartifact");
-            result = this.productArtifact.feed(target, context);
-        }
-        return result;
-    }
-
-    /**
-     * @see de.intevation.artifactdatabase.DefaultArtifact#out(org.w3c.dom.Document,
-     *      java.lang.Object)
-     */
-    @Override
-    public void out(Document format, OutputStream outputStream,
-                    CallContext context) throws IOException {
-        if (this.productArtifact != null) {
-            this.productArtifact.out(format, outputStream, context);
-        }
-    }
-
-    /**
-     * Constructor
-     */
-    public FISArtifact() {
-        super();
-    }
-
-    /**
-     * @see de.intevation.artifactdatabase.DefaultArtifact#setup(java.lang.String,
-     *      de.intevation.artifacts.ArtifactFactory, java.lang.Object)
-     */
-    @Override
-    public void setup(String identifier, ArtifactFactory factory, Object context) {
-        log.debug("FISArtifact.setup");
-        this.name = factory.getName();
-        super.setup(identifier, factory, context);
-        if (context instanceof GNVArtifactContext) {
-            GNVArtifactContext gnvContext = (GNVArtifactContext) context;
-            Document doc = gnvContext.getConfig();
-            Node artifactNode = this.getConfigurationFragment(doc);
-
-            NodeList products = Config.getNodeSetXPath(artifactNode,
-                    "products/product");
-            if (products != null) {
-                this.products = new HashMap<String, Product>(products
-                        .getLength());
-                
-                for (int i = 0; i < products.getLength(); i++) {
-                    Element productNode = (Element)products.item(i);
-                    String productName = productNode.getAttribute("name");
-                    NodeList parameterNodes = Config.getNodeSetXPath(
-                            productNode, "parameters/parameter");
-                    Collection<InputData> parameter = null;
-                    if (parameterNodes != null) {
-                        parameter = new ArrayList<InputData>(parameterNodes
-                                .getLength());
-                        for (int j = 0; j < parameterNodes.getLength(); j++) {
-                            Element parameterNode = (Element)parameterNodes.item(j);
-                            String name = parameterNode.getAttribute("name");
-                            String value = parameterNode.getAttribute("value");
-                            parameter.add(new DefaultInputData(name, value));
-                        }
-                    }
-                    Node artifactFactoryNode = Config.getNodeXPath(productNode,
-                            "artifact-factory");
-                    ArtifactFactory artifactFactory = new ArtifactFactoryUtilities()
-                            .createArtitfactFactor(doc, artifactFactoryNode);
-                    this.products.put(productName, new DefaultProduct(
-                            productName, parameter, artifactFactory));
-                }
-            }
-        }
-    }
-
-    protected Node getConfigurationFragment(Document document) {
-        log.debug("GNVArtifactBase.getConfigurationFragment");
-        String xpathQuery = XPATH_ARTIFACT_CONFIGURATION.replaceAll(
-                XPATH_IDENTIFIER_REPLACE, this.name);
-        log.debug(xpathQuery);
-        return Config.getNodeXPath(document, xpathQuery);
-    }
-
-    protected Document createDescibeOutput(CallMeta callMeta) {
-        log.debug("GNVArtifactBase.createDescibeOutput");
-        Document document = XMLUtils.newDocument();
-        Element rootNode = this.createRootNode(document);
-        this.createHeader(rootNode, document, "describe");
-        this.createOutputs(rootNode, document);
-        this.createCurrentState(rootNode, document);
-        this.createReachableStates(rootNode, document);
-        this.createModel(rootNode, document);
-        this.createUserInterface(rootNode, document, callMeta);
-
-        return document;
-    }
-
-    protected Element createRootNode(Document document) {
-        Element rootNode = xmlUtilities.createArtifactElement(document,
-                "result");
-        document.appendChild(rootNode);
-        return rootNode;
-    }
-
-    protected void createHeader(Element parent, Document document,
-                                String documentType) {
-        Element typeNode = xmlUtilities.createArtifactElement(document, "type");
-        typeNode.setAttribute("name", documentType);
-        parent.appendChild(typeNode);
-
-        Element uuidNode = xmlUtilities.createArtifactElement(document, "uuid");
-        uuidNode.setAttribute("value", super.identifier);
-        parent.appendChild(uuidNode);
-
-        Element hashNode = xmlUtilities.createArtifactElement(document, "hash");
-        hashNode.setAttribute("value", this.hash());
-        parent.appendChild(hashNode);
-
-    }
-
-    protected void createReachableStates(Element parent, Document document) {
-        Element stateNode = xmlUtilities.createArtifactElement(document,
-                "reachable-states");
-        if (this.products != null) {
-            Iterator<Product> products = this.products.values().iterator();
-            while (products.hasNext()) {
-                Product product = products.next();
-                Element currentNode = xmlUtilities.createArtifactElement(
-                        document, "state");
-                currentNode.setAttribute("name", product.getName());
-                currentNode.setAttribute("description", product.getName());
-                stateNode.appendChild(currentNode);
-            }
-        }
-        parent.appendChild(stateNode);
-    }
-
-    protected void createCurrentState(Element parent, Document document) {
-        Element stateNode = xmlUtilities.createArtifactElement(document,
-                "state");
-        stateNode.setAttribute("name", "choose-product");
-        stateNode.setAttribute("description",
-                "Initialer Stand Auswahl des products");
-        parent.appendChild(stateNode);
-    }
-
-    protected void createModel(Element parent, Document document) {
-        Element modelNode = xmlUtilities.createArtifactElement(document,
-                "model");
-
-        Element inputNode = xmlUtilities.createArtifactElement(document,
-                "input");
-        inputNode.setAttribute("name", "product");
-        inputNode.setAttribute("type", "String");
-        modelNode.appendChild(inputNode);
-
-        parent.appendChild(modelNode);
-    }
-
-    protected void createUserInterface(Element parent, Document document,
-                                       CallMeta callMeta) {
-        Element uiNode = xmlUtilities.createArtifactElement(document, "ui");
-        ArtifactXMLUtilities xmlUtilities = new ArtifactXMLUtilities();
-        Node dynamic = xmlUtilities.createArtifactElement(document, "dynamic");
-        uiNode.appendChild(dynamic);
-        if (this.products != null && !this.products.isEmpty()) {
-            Element selectNode = createSelectBox(document, callMeta);
-
-            dynamic.appendChild(selectNode);
-        }
-
-        parent.appendChild(uiNode);
-    }
-
-    /**
-     * @param document
-     * @param xmlUtilities
-     * @return
-     */
-    private Element createSelectBox(Document document, CallMeta callMeta) {
-
-        ArtifactXMLUtilities xmlUtilities = new ArtifactXMLUtilities();
-        String selectboxName = "product";
-        Iterator<Product> it = this.products.values().iterator();
-        Element selectNode = xmlUtilities.createXFormElement(document,
-                "select1");
-        selectNode.setAttribute("ref", selectboxName);
-
-        Element lableNode = xmlUtilities.createXFormElement(document, "label");
-        lableNode.setTextContent(RessourceFactory.getInstance().getRessource(
-                callMeta.getLanguages(), selectboxName, selectboxName));
-        selectNode.appendChild(lableNode);
-        Element choiceNode = xmlUtilities.createXFormElement(document,
-                "choices");
-        selectNode.appendChild(choiceNode);
-        while (it.hasNext()) {
-            Product p = it.next();
-            Element itemNode = xmlUtilities
-                    .createXFormElement(document, "item");
-
-            if (this.current != null
-                && this.current.getName().equals(p.getName())) {
-                itemNode.setAttribute("selected", "true");
-            }
-
-            Element choiceLableNode = xmlUtilities.createXFormElement(document,
-                    "label");
-            choiceLableNode.setTextContent(RessourceFactory.getInstance()
-                    .getRessource(callMeta.getLanguages(), p.getName(),
-                            p.getName()));
-            itemNode.appendChild(choiceLableNode);
-
-            Element choicValueNode = xmlUtilities.createXFormElement(document,
-                    "value");
-            choicValueNode.setTextContent(p.getName());
-            itemNode.appendChild(choicValueNode);
-
-            choiceNode.appendChild(itemNode);
-
-        }
-        return selectNode;
-    }
-
-    protected void createOutputs(Element parent, Document document) {
-        log.debug("GNVArtifactBase.createOutputs");
-        Element outputsNode = xmlUtilities.createArtifactElement(document,
-                "outputs");
-        parent.appendChild(outputsNode);
-    }
-
-}
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/fis/SelectProductArtifact.java	Fri Jan 15 10:13:18 2010 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/fis/SelectProductArtifact.java	Fri Jan 15 18:21:49 2010 +0000
@@ -6,6 +6,7 @@
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.Iterator;
+import java.util.Map;
 import javax.xml.xpath.XPathConstants;
 
 import org.apache.log4j.Logger;
@@ -23,11 +24,11 @@
 import de.intevation.artifacts.CallContext;
 import de.intevation.artifacts.CallMeta;
 import de.intevation.gnv.artifacts.GNVArtifactBase;
+import de.intevation.gnv.artifacts.GNVProductArtifactFactory;
 import de.intevation.gnv.artifacts.context.GNVArtifactContext;
 import de.intevation.gnv.artifacts.fis.product.DefaultProduct;
 import de.intevation.gnv.artifacts.fis.product.Product;
 import de.intevation.gnv.artifacts.ressource.RessourceFactory;
-import de.intevation.gnv.state.DefaultInputData;
 import de.intevation.gnv.state.InputData;
 import de.intevation.gnv.utils.ArtifactFactoryUtilities;
 
@@ -37,12 +38,6 @@
  */
 public class SelectProductArtifact extends DefaultArtifact {
 
-    public static final String XPATH_IDENTIFIER_REPLACE = "IDENTIFIER";
-
-    public static final String XPATH_ARTIFACT_CONFIGURATION =
-        "/artifact-database/artifacts/artifact[@name='"
-        + XPATH_IDENTIFIER_REPLACE + "']";
-
     public static final String XPATH_UUID = "art:action/art:uuid/@value";
 
     public static final String XPATH_HASH = "art:action/art:hash/@value";
@@ -50,24 +45,12 @@
     public static final String XPATH_INPUT_DATA_VALUE =
         "art:action/art:data/art:input[@name='product']/@value";
 
-    /**
-     * this xpath is related to the config.xml document which doesn't have any
-     * prefixes yet
-     */
-    public static final String XPATH_PRODUCTS = "products/product";
-
-    /**
-     * this xpath is related to the config.xml document which doesn't have any
-     * prefixes yet
-     */
-    public static final String XPATH_PRODUCT_PARAMETER = "parameters/parameter";
-
     public static final String XFORM_URL    = "http://www.w3.org/2002/xforms";
     public static final String XFORM_PREFIX = "xform";
 
     private static Logger log = Logger.getLogger(SelectProductArtifact.class);
 
-    private HashMap  products;
+    private Map      products;
     private Product  current;
     private Artifact artifact;
     private String   name;
@@ -86,53 +69,11 @@
         log.debug("setup()");
         super.setup(identifier, factory, context);
         this.name = factory.getName();
-
-        if (context instanceof GNVArtifactContext) {
-            GNVArtifactContext gnvContext   = (GNVArtifactContext) context;
-            Document           doc          = gnvContext.getConfig();
-            Node               artifactNode = getConfigurationFragment(doc);
-
-            NodeList products = (NodeList) XMLUtils.xpath(
-                artifactNode, XPATH_PRODUCTS, XPathConstants.NODESET);
-
-            if (products != null) {
-                this.products = new HashMap(products.getLength());
-
-                for (int i = 0; i < products.getLength(); i++) {
-                    Element  productNode    = (Element)products.item(i);
-                    String   productName    = productNode.getAttribute("name");
-                    NodeList parameterNodes = (NodeList) XMLUtils.xpath(
-                        productNode,
-                        XPATH_PRODUCT_PARAMETER,
-                        XPathConstants.NODESET
-                    );
+    }
 
-                    Collection<InputData> parameter = null;
-                    if (parameterNodes != null) {
-                        parameter = new ArrayList(parameterNodes.getLength());
 
-                        for (int j = 0; j < parameterNodes.getLength(); j++) {
-                            Element parameterNode = (Element)parameterNodes.item(j);
-                            String name  = parameterNode.getAttribute("name");
-                            String value = parameterNode.getAttribute("value");
-                            parameter.add(new DefaultInputData(name, value));
-                        }
-                    }
-                    Node artifactFactoryNode = (Node) XMLUtils.xpath(
-                        productNode, "artifact-factory", XPathConstants.NODE
-                    );
-
-                    ArtifactFactory artifactFactory =
-                        new ArtifactFactoryUtilities().createArtitfactFactor(
-                            doc, artifactFactoryNode
-                        );
-
-                    this.products.put(productName, new DefaultProduct(
-                        productName, parameter, artifactFactory)
-                    );
-                }
-            }
-        }
+    public void setProducts(Map products) {
+        this.products = products;
     }
 
 
@@ -224,9 +165,12 @@
             target, XPATH_HASH, ArtifactNamespaceContext.INSTANCE
         );
 
-        artifact = current.getArtifactFactory().createArtifact(
-            uuid, context
-        );
+        // fetch ArtifactFactory from context and create a new Artifact
+        ArtifactFactory factory = context.getDatabase()
+            .getInternalArtifactFactory(this.name);
+        factory                 = ((GNVProductArtifactFactory)factory)
+            .getArtifactFactoryByName(current.getName());
+        artifact                = factory.createArtifact(uuid, context);
 
         Document feedDocument = feedDocument(uuid, hash);
         artifact.feed(feedDocument(uuid, hash), context);
@@ -386,15 +330,6 @@
     }
 
 
-    protected Node getConfigurationFragment(Document document) {
-        String xpathQuery = XPATH_ARTIFACT_CONFIGURATION.replaceAll(
-            XPATH_IDENTIFIER_REPLACE, name
-        );
-
-        return (Node) XMLUtils.xpath(document, xpathQuery, XPathConstants.NODE);
-    }
-
-
     protected Document feedDocument(String uuid, String hash) {
         Document document = XMLUtils.newDocument();
 
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/fis/product/DefaultProduct.java	Fri Jan 15 10:13:18 2010 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/fis/product/DefaultProduct.java	Fri Jan 15 18:21:49 2010 +0000
@@ -23,7 +23,7 @@
 
     private Collection<InputData> parameter = null;
 
-    private ArtifactFactory artifactFactory = null;
+    private String artifactFactory = null;
 
     /**
      * Constructor
@@ -32,11 +32,14 @@
      * @param parameter
      * @param artifactFactory
      */
-    public DefaultProduct(String name, Collection<InputData> parameter,
-                          ArtifactFactory artifactFactory) {
+    public DefaultProduct(
+        String                name,
+        Collection<InputData> parameter,
+        String                artifactFactory
+    ) {
         super();
-        this.name = name;
-        this.parameter = parameter;
+        this.name            = name;
+        this.parameter       = parameter;
         this.artifactFactory = artifactFactory;
     }
 
@@ -57,7 +60,7 @@
     /**
      * @see de.intevation.gnv.artifacts.fis.product.Product#getArtifactFactory()
      */
-    public ArtifactFactory getArtifactFactory() {
+    public String getArtifactFactory() {
         return this.artifactFactory;
     }
 
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/fis/product/Product.java	Fri Jan 15 10:13:18 2010 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/fis/product/Product.java	Fri Jan 15 18:21:49 2010 +0000
@@ -19,5 +19,5 @@
 
     public Collection<InputData> getParameter();
 
-    public ArtifactFactory getArtifactFactory();
+    public String getArtifactFactory();
 }

http://dive4elements.wald.intevation.org