changeset 71:e4ecf3188bdf

Integrated FIS-Artifact gnv-artifacts/trunk@62 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Tim Englich <tim.englich@intevation.de>
date Thu, 10 Sep 2009 13:11:24 +0000
parents 0035862b0295
children 1fece4da4f2f
files gnv-artifacts/Changelog gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/GNVArtifactBase.java gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/fis/FISArtifact.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 gnv-artifacts/src/main/java/de/intevation/gnv/utils/ArtifactFactoryUtilities.java gnv-artifacts/src/main/java/de/intevation/gnv/utils/ArtifactXMLUtilities.java
diffstat 7 files changed, 621 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/gnv-artifacts/Changelog	Thu Sep 10 09:40:49 2009 +0000
+++ b/gnv-artifacts/Changelog	Thu Sep 10 13:11:24 2009 +0000
@@ -1,3 +1,22 @@
+2009-09-10  Tim Englich  <tim.englich@intevation.de>
+
+    * src/main/java/de/intevation/gnv/utils/ArtifactXMLUtilities.java Added:
+     Utilities-Class for some XML-Stuff that is only for gnv-artifacts
+     
+    * src/main/java/de/intevation/gnv/utils/ArtifactFactoryUtilities.java Added:
+     Factory to Instantiiate an ArtifactFactory (TODO: Should be moved to Artifact-database) 
+    
+    * src/main/java/de/intevation/gnv/artifacts/fis/product/Product.java Added, 
+      src/main/java/de/intevation/gnv/artifacts/fis/product/DefaultProduct.java Added:
+      Interfcaedefinition and Defaultimplementation for the Representation of the different
+      Products in an FIS.
+    
+    * src/main/java/de/intevation/gnv/artifacts/fis/FISArtifact.java Added:
+    Artifact to Repersent an FIS. This Artifact is able to switch between different
+    SubArtifacts for handling the different Products  of an FIS. 
+    * src/main/java/de/intevation/gnv/artifacts/GNVArtifactBase.java Edited:
+      Refactoring Work done because of changes in the artifact-modules 
+      
 2009-09-10  Tim Englich  <tim.englich@intevation.de>
 
     * src/main/java/de/intevation/gnv/artifacts/GNVArtifactBase.java Edited, 
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/GNVArtifactBase.java	Thu Sep 10 09:40:49 2009 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/GNVArtifactBase.java	Thu Sep 10 13:11:24 2009 +0000
@@ -9,6 +9,9 @@
 import java.util.Iterator;
 import java.util.Map;
 
+import javax.xml.XMLConstants;
+import javax.xml.xpath.XPathConstants;
+
 import org.apache.log4j.Logger;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
@@ -17,6 +20,7 @@
 
 import de.intevation.artifactdatabase.Config;
 import de.intevation.artifactdatabase.DefaultArtifact;
+import de.intevation.artifactdatabase.XMLUtils;
 import de.intevation.artifacts.ArtifactFactory;
 import de.intevation.artifacts.ArtifactNamespaceContext;
 import de.intevation.gnv.artifacts.context.GNVArtifactContext;
@@ -28,6 +32,7 @@
 import de.intevation.gnv.transition.Transition;
 import de.intevation.gnv.transition.TransitionFactory;
 import de.intevation.gnv.transition.exception.TransitionException;
+import de.intevation.gnv.utils.ArtifactXMLUtilities;
 
 /**
  * @author Tim Englich <tim.englich@intevation.de>
@@ -69,6 +74,8 @@
      */
     protected String name = null;
     
+    private ArtifactXMLUtilities xmlUtilities = new ArtifactXMLUtilities();
+    
     /**
      * Constructor
      */
@@ -81,7 +88,7 @@
      */
     @Override
     public Document advance(Document target, Object context) {
-        Document result = super.newDocument();
+        Document result = XMLUtils.newDocument();
         if (this.current != null){
             String transitionName = this.readTransitionName(target);
             if (this.current.isTransitionReachable(transitionName)){
@@ -136,7 +143,7 @@
      */
     @Override
     public Document feed(Document target, Object context) {
-        Document result = super.newDocument();
+        Document result = XMLUtils.newDocument();
         try {
             if (this.current != null){
                 this.current.putInputData(this.parseInputData(target));
@@ -178,7 +185,7 @@
     
     protected Document createDescibeOutput(){
         log.debug("GNVArtifactBase.createDescibeOutput");
-        Document document = super.newDocument();
+        Document document = XMLUtils.newDocument();
         Element rootNode = this.createRootNode(document);
         this.createHeader(rootNode, document, "describe");
         this.createOutputs(rootNode, document);
@@ -191,33 +198,33 @@
     }
     
     protected Element createRootNode(Document document){
-        Element rootNode = createElement(document,"result");
+        Element rootNode = xmlUtilities.createArtifactElement(document,"result");
         document.appendChild(rootNode);
         return rootNode;
     }
     
     protected void createHeader(Element parent, Document document, String documentType){
-        Element typeNode = createElement(document,"type");
+        Element typeNode = xmlUtilities.createArtifactElement(document,"type");
         typeNode.setAttribute("name", documentType);
         parent.appendChild(typeNode);
         
-        Element uuidNode = createElement(document,"uuid");
+        Element uuidNode = xmlUtilities.createArtifactElement(document,"uuid");
         uuidNode.setAttribute("value", super.identifier);
         parent.appendChild(uuidNode);
         
-        Element hashNode = createElement(document,"hash");
+        Element hashNode = xmlUtilities.createArtifactElement(document,"hash");
         hashNode.setAttribute("value", this.hash());
         parent.appendChild(hashNode);
 
         
     }
     protected void createReachableStates(Element parent,Document document){
-        Element stateNode = createElement(document,"reachable-states");
+        Element stateNode = xmlUtilities.createArtifactElement(document,"reachable-states");
         if (this.current != null){
             Iterator<String> states = this.current.reachableTransitions().iterator();
             while(states.hasNext()){
                 String value = states.next();
-                Element currentNode = createElement(document,"state");
+                Element currentNode = xmlUtilities.createArtifactElement(document,"state");
                 currentNode.setAttribute("name", value);
                 currentNode.setAttribute("description", transitions.get(value).getDescription());
                 stateNode.appendChild(currentNode);
@@ -227,7 +234,7 @@
     }
     
     protected void createCurrentState(Element parent, Document document){
-        Element stateNode = createElement(document,"state");
+        Element stateNode = xmlUtilities.createArtifactElement(document,"state");
         stateNode.setAttribute("name", this.current.getID());
         stateNode.setAttribute("description", this.current.getDescription());
         parent.appendChild(stateNode);
@@ -235,14 +242,14 @@
     
     
     protected void createModel(Element parent, Document document){
-        Element modelNode = createElement(document,"model");
+        Element modelNode = xmlUtilities.createArtifactElement(document,"model");
         if (this.current != null){
             Collection<InputValue>  inputValues = this.current.getRequiredInputValues();
             if (inputValues != null){
                 Iterator<InputValue> it = inputValues.iterator();
                 while(it.hasNext()){
                     InputValue inputValue = it.next();
-                    Element inputNode = createElement(document,"input");
+                    Element inputNode = xmlUtilities.createArtifactElement(document,"input");
                     inputNode.setAttribute("name", inputValue.getName());
                     inputNode.setAttribute("type", inputValue.getType());
                     modelNode.appendChild(inputNode);
@@ -253,7 +260,7 @@
     }
     
     protected void createUserInterface(Element parent, Document document){
-        Element uiNode = createElement(document,"ui");
+        Element uiNode = xmlUtilities.createArtifactElement(document,"ui");
         
         if (this.current != null){
             this.current.describe(document, uiNode);
@@ -264,7 +271,7 @@
     
     protected void createOutputs(Element parent, Document document){
         log.debug("GNVArtifactBase.createOutputs");
-        Element outputsNode = createElement(document,"outputs");
+        Element outputsNode = xmlUtilities.createArtifactElement(document,"outputs");
         if (this.current instanceof OutputTransition){
             Collection<OutputMode> outputModes = ((OutputTransition)this.current).getOutputModes();
             if (outputModes != null){
@@ -272,7 +279,7 @@
                 while(it.hasNext()){
                     OutputMode outputMode = it.next();
                     log.debug("Write Outputnode for "+ outputMode.toString());
-                    Element outputModeNode = createElement(document,"output");
+                    Element outputModeNode = xmlUtilities.createArtifactElement(document,"output");
                     outputModeNode.setAttribute("name", outputMode.getName());
                     outputModeNode.setAttribute("description", outputMode.getDescription());
                     outputModeNode.setAttribute("mime-type", outputMode.getMimeType());
@@ -285,21 +292,14 @@
         parent.appendChild(outputsNode);
     }
 
-    /**
-     * @param document
-     * @return
-     */
-    private Element createElement(Document document, String name) {
-        Element node = document.createElementNS(ArtifactNamespaceContext.NAMESPACE_URI, name);
-        node.setPrefix(ArtifactNamespaceContext.NAMESPACE_PREFIX);
-        return node;
-    }
     
     protected Collection<InputData> parseInputData(Document document){
         log.debug("GNVArtifactBase.parseInputData");
         Collection<InputData> returnValue = null;
         
-        NodeList inputElemets = Config.getNodeSetXPath(document, "action/data/input");
+        log.debug(new ArtifactXMLUtilities().writeDocument2String(document));
+        
+        NodeList inputElemets = (NodeList)XMLUtils.xpath(document, "/action/data/input",XPathConstants.NODESET, ArtifactNamespaceContext.INSTANCE);//Config.getNodeSetXPath(document, "");
         if(inputElemets != null){
             returnValue = new ArrayList<InputData>(inputElemets.getLength());
             for (int i = 0; i < inputElemets.getLength(); i++){
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/fis/FISArtifact.java	Thu Sep 10 13:11:24 2009 +0000
@@ -0,0 +1,341 @@
+/**
+ *
+ */
+package de.intevation.gnv.artifacts.fis;
+
+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.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.transition.DefaultInputData;
+import de.intevation.gnv.transition.InputData;
+import de.intevation.gnv.transition.InputValue;
+import de.intevation.gnv.transition.OutputMode;
+import de.intevation.gnv.transition.OutputTransition;
+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, java.lang.Object)
+     */
+    @Override
+    public Document advance(Document target, Object context) {
+        if (this.productArtifact == null){
+            if (this.current != null){
+                String uuid = Config.getStringXPath(target, "action/uuid/@value"); // TODO: müssen wir für das subartifact eine veränderte uuid führen?
+                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));
+                Document descibeDocument =  xmlUtilities.reInitDocument(this.productArtifact.describe(context));
+                log.debug("Descibe ==> "+this.xmlUtilities.writeDocument2String(descibeDocument));
+                this.productArtifact.feed(feedDocument, context);
+                String targetName =  Config.getStringXPath(descibeDocument, "result/reachable-states/state/@name");
+                Document advanceDocument = xmlUtilities.reInitDocument(this.createAdvanceProductArtifactDocument(uuid, hash, targetName));
+                log.debug("Advance ==> "+this.xmlUtilities.writeDocument2String(advanceDocument));
+                return this.productArtifact.advance(advanceDocument, context);
+            }else{
+                log.warn("Artifact is not configured properly. Call feed first.");
+                // TODO Fehlerdokument erzeugen.
+            }
+            return null;
+        }else{
+            return this.productArtifact.advance(target, context);
+        }
+    }
+    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(java.lang.Object)
+     */
+    @Override
+    public Document describe(Object context) {
+        if (this.productArtifact == null){
+            return this.createDescibeOutput();
+        }else{
+            return this.productArtifact.describe(context);
+        }
+    }
+
+    /**
+     * @see de.intevation.artifactdatabase.DefaultArtifact#feed(org.w3c.dom.Document, java.lang.Object)
+     */
+    @Override
+    public Document feed(Document target, Object context) {
+        if (this.productArtifact == null){
+            String productName = Config.getStringXPath(target, "action/data/input[@name='product']/@value");
+            if (this.products.containsKey(productName)) {
+                this.current = this.products.get(productName);
+            }else{
+                log.error("Product does not exists for "+productName);
+                // TODO: Fehlerdokument erzeugen.
+            }
+            return null;
+        }else{
+            return this.productArtifact.feed(target, context);
+        }
+    }
+
+    /**
+     * @see de.intevation.artifactdatabase.DefaultArtifact#out(org.w3c.dom.Document, java.lang.Object)
+     */
+    @Override
+    public byte[] out(Document format, Object context) {
+        byte[] returnValue = null;
+        if (this.productArtifact != null){
+            returnValue = this.productArtifact.out(format, context);
+        }
+        return returnValue;
+    }
+
+    /**
+     * 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++){
+                   Node productNode = products.item(i);
+                   String productName = Config.getStringXPath(productNode, "@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++){
+                           Node parameterNode = parameterNodes.item(j);
+                           String name = Config.getStringXPath(parameterNode, "@name");
+                           String value = Config.getStringXPath(parameterNode, "@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(){
+        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);
+        
+        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){
+        Element uiNode = xmlUtilities.createArtifactElement(document,"ui");
+        
+        // TODO hier selectbox mit den produktnamen
+        
+        parent.appendChild(uiNode);
+    }
+    
+    protected void createOutputs(Element parent, Document document){
+        log.debug("GNVArtifactBase.createOutputs");
+        Element outputsNode = xmlUtilities.createArtifactElement(document,"outputs");
+        parent.appendChild(outputsNode);
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/fis/product/DefaultProduct.java	Thu Sep 10 13:11:24 2009 +0000
@@ -0,0 +1,58 @@
+/**
+ *
+ */
+package de.intevation.gnv.artifacts.fis.product;
+
+import java.util.Collection;
+
+import de.intevation.artifacts.ArtifactFactory;
+import de.intevation.gnv.transition.InputData;
+
+/**
+ * @author Tim Englich <tim.englich@intevation.de>
+ *
+ */
+public class DefaultProduct implements Product {
+
+    private String name = null;
+    
+    private Collection<InputData> parameter = null;
+    
+    private ArtifactFactory artifactFactory = null;
+    
+
+    /**
+     * Constructor
+     * @param name
+     * @param parameter
+     * @param artifactFactory
+     */
+    public DefaultProduct(String name, Collection<InputData> parameter, ArtifactFactory artifactFactory) {
+        super();
+        this.name = name;
+        this.parameter = parameter;
+        this.artifactFactory = artifactFactory;
+    }
+
+    /**
+     * @see de.intevation.gnv.artifacts.fis.product.Product#getName()
+     */
+    public String getName() {
+        return this.name;
+    }
+
+    /**
+     * @see de.intevation.gnv.artifacts.fis.product.Product#getParameter()
+     */
+    public Collection<InputData> getParameter() {
+        return this.parameter;
+    }
+
+    /**
+     * @see de.intevation.gnv.artifacts.fis.product.Product#getArtifactFactory()
+     */
+    public ArtifactFactory getArtifactFactory() {
+        return this.artifactFactory;
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/fis/product/Product.java	Thu Sep 10 13:11:24 2009 +0000
@@ -0,0 +1,20 @@
+/**
+ *
+ */
+package de.intevation.gnv.artifacts.fis.product;
+
+import java.util.Collection;
+
+import de.intevation.artifacts.ArtifactFactory;
+import de.intevation.gnv.transition.InputData;
+
+/**
+ * @author Tim Englich <tim.englich@intevation.de>
+ *
+ */
+public interface Product {
+
+    public String getName();
+    public Collection<InputData> getParameter();
+    public ArtifactFactory getArtifactFactory();
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/utils/ArtifactFactoryUtilities.java	Thu Sep 10 13:11:24 2009 +0000
@@ -0,0 +1,57 @@
+/**
+ *
+ */
+package de.intevation.gnv.utils;
+
+import org.apache.log4j.Logger;
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+
+import de.intevation.artifactdatabase.Config;
+import de.intevation.artifacts.ArtifactFactory;
+
+
+/**
+ * @author Tim Englich <tim.englich@intevation.de>
+ *
+ */
+public class ArtifactFactoryUtilities {
+    /**
+     * the logger, used to log exceptions and additonaly information
+     */
+    private static Logger log = Logger.getLogger(ArtifactFactoryUtilities.class);
+    /**
+     * Constructor
+     */
+    public ArtifactFactoryUtilities() {
+    }
+
+    public ArtifactFactory createArtitfactFactor(Document config, Node artifactFactoryNode){
+        String className =artifactFactoryNode.getTextContent();
+
+        ArtifactFactory factory = null;
+
+        try {
+            Class clazz = Class.forName(className);
+            factory = (ArtifactFactory)clazz.newInstance();
+        }
+        catch (ClassNotFoundException cnfe) {
+            log.error(cnfe.getLocalizedMessage(), cnfe);
+        }
+        catch (InstantiationException ie) {
+            log.error(ie.getLocalizedMessage(), ie);
+        }
+        catch (ClassCastException cce) {
+            log.error(cce.getLocalizedMessage(), cce);
+        }
+        catch (IllegalAccessException iae) {
+            log.error(iae.getLocalizedMessage(), iae);
+        }
+
+        if (factory != null) {
+            factory.setup(config, artifactFactoryNode);
+            log.info("Registering '" + factory.getName() + "' as artifact factory.");
+        }
+        return factory;
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/utils/ArtifactXMLUtilities.java	Thu Sep 10 13:11:24 2009 +0000
@@ -0,0 +1,101 @@
+/**
+ *
+ */
+package de.intevation.gnv.utils;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.StringBufferInputStream;
+import java.io.StringWriter;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerConfigurationException;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.TransformerFactoryConfigurationError;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+
+import org.apache.log4j.Logger;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.xml.sax.SAXException;
+
+import de.intevation.artifacts.ArtifactNamespaceContext;
+import de.intevation.gnv.transition.timeseries.TimeSeriesOutputTransition;
+
+/**
+ * @author Tim Englich <tim.englich@intevation.de>
+ *
+ */
+public class ArtifactXMLUtilities {
+    /**
+     * the logger, used to log exceptions and additonaly information
+     */
+    private static Logger log = Logger.getLogger(TimeSeriesOutputTransition.class);
+  
+    /**
+     * Constructor
+     */
+    public ArtifactXMLUtilities() {
+    }
+    
+    /**
+     * @param document
+     * @return
+     */
+    public Element createArtifactElement(Document document, String name) {
+        Element node = document.createElementNS(ArtifactNamespaceContext.NAMESPACE_URI, name);
+        node.setPrefix(ArtifactNamespaceContext.NAMESPACE_PREFIX);
+        return node;
+    }
+    
+    public String writeDocument2String(Document document){
+        try {
+            TransformerFactory transformerFactory = TransformerFactory.newInstance();
+            Transformer transformer = transformerFactory.newTransformer();
+            DOMSource source = new DOMSource(document);
+            StringWriter sw = new StringWriter();
+            StreamResult result =  new StreamResult(sw);
+            transformer.transform(source, result);
+            return sw.getBuffer().toString();
+        } catch (TransformerConfigurationException e) {
+            log.error(e,e);
+        } catch (TransformerFactoryConfigurationError e) {
+            log.error(e,e);
+        } catch (TransformerException e) {
+            log.error(e,e);
+        }
+        return null;
+    }
+    
+    public Document readDocument(InputStream inputStream){
+        Document returnValue = null;
+        try {
+            DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
+            DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
+            returnValue = docBuilder.parse (inputStream);
+        } catch (ParserConfigurationException e) {
+            log.error(e,e);
+        } catch (SAXException e) {
+            log.error(e,e);
+        } catch (IOException e) {
+            log.error(e,e);
+        }
+        return returnValue;
+    }
+    
+    public Document reInitDocument(Document document){
+        
+        StringBufferInputStream inputStream = new StringBufferInputStream(this.writeDocument2String(document));
+        return this.readDocument(inputStream);
+    }
+    
+    
+    
+
+}

http://dive4elements.wald.intevation.org