changeset 54:09b4bf848c7b

2009-09-08 Tim Englich <tim.englich@intevation.de> * src/test/java/de/intevation/gnv/artifacts/GNVArtifactsTestCase.java, * src/main/java/de/intevation/gnv/timeseries/TimeSeriesArtifact.java:, * src/main/java/de/intevation/gnv/artifacts/GNVArtifactBase.java: Edited Added Output for Describe to the Artifactimplementation gnv-artifacts/trunk@36 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Tim Englich <tim.englich@intevation.de>
date Tue, 08 Sep 2009 09:14:35 +0000
parents e464d9f9d967
children 6ded86ce30dd
files gnv-artifacts/Changelog gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/GNVArtifactBase.java gnv-artifacts/src/main/java/de/intevation/gnv/timeseries/TimeSeriesArtifact.java gnv-artifacts/src/main/java/de/intevation/gnv/transition/TransitionBase.java gnv-artifacts/src/test/java/de/intevation/gnv/artifacts/GNVArtifactsTestCase.java
diffstat 5 files changed, 149 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/gnv-artifacts/Changelog	Tue Sep 08 09:03:48 2009 +0000
+++ b/gnv-artifacts/Changelog	Tue Sep 08 09:14:35 2009 +0000
@@ -1,3 +1,10 @@
+2009-09-08  Tim Englich  <tim.englich@intevation.de>
+
+    * src/test/java/de/intevation/gnv/artifacts/GNVArtifactsTestCase.java, 
+    * src/main/java/de/intevation/gnv/timeseries/TimeSeriesArtifact.java:,
+    * src/main/java/de/intevation/gnv/artifacts/GNVArtifactBase.java: Edited
+    Added Output for Describe to the Artifactimplementation
+    
 2009-09-08  Tim Englich  <tim.englich@intevation.de>
 
     * src/test/ressources/GNVArtifactsTestCase_Configuration.xml, 
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/GNVArtifactBase.java	Tue Sep 08 09:03:48 2009 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/GNVArtifactBase.java	Tue Sep 08 09:14:35 2009 +0000
@@ -4,10 +4,12 @@
 package de.intevation.gnv.artifacts;
 
 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;
 
@@ -31,17 +33,32 @@
      */
     private static final long serialVersionUID = -8907096744400741458L;
     
+    /**
+     * 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 current Transition
+     */
     protected Transition current = null;
     
+    /**
+     * The Transitions that can be used
+     */
     protected Map<String, Transition> transitions = null;
 
+    /**
+     * The Name of the Artifact
+     */
     protected String name = null;
+    
     /**
      * Constructor
      */
@@ -54,7 +71,6 @@
         String xpathQuery = XPATH_ARTIFACT_CONFIGURATION.replaceAll(XPATH_IDENTIFIER_REPLACE, this.name);
         log.debug(xpathQuery);
         return Config.getNodeXPath(document,xpathQuery);
-        
     }
     
     /**
@@ -83,5 +99,96 @@
         }
     }
     
+    
+    protected Document createDescibeOutput(){
+        log.debug("GNVArtifactBase.createDescibeOutput");
+        Document document = super.newDocument();
+        Element rootNode = this.createRootNode(document);
+        this.createHeader(rootNode, document, "describe");
+        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 = createElement(document,"result");
+        document.appendChild(rootNode);
+        return rootNode;
+    }
+    
+    protected void createHeader(Element parent, Document document, String documentType){
+        Element typeNode = createElement(document,"type");
+        typeNode.setAttribute("name", documentType);
+        parent.appendChild(typeNode);
+        
+        Element uuidNode = createElement(document,"uuid");
+        uuidNode.setAttribute("value", super.identifier);
+        parent.appendChild(uuidNode);
+        
+        Element hashNode = createElement(document,"hash");
+        hashNode.setAttribute("value", this.hash());
+        parent.appendChild(hashNode);
+
+        
+    }
+    protected void createReachableStates(Element parent,Document document){
+        Element stateNode = createElement(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");
+                currentNode.setAttribute("name", value);
+                currentNode.setAttribute("description", transitions.get(value).getDescription());
+                stateNode.appendChild(currentNode);
+            }
+        }
+        parent.appendChild(stateNode);
+    }
+    
+    protected void createCurrentState(Element parent, Document document){
+        Element stateNode = createElement(document,"state");
+        stateNode.setAttribute("name", this.current.getID());
+        stateNode.setAttribute("description", this.current.getDescription());
+        parent.appendChild(stateNode);
+    }
+    
+    
+    protected void createModel(Element parent, Document document){
+        Element modelNode = createElement(document,"model");
+        // TODO mit leben füllen.
+        
+        parent.appendChild(modelNode);
+    }
+    
+    protected void createUserInterface(Element parent, Document document){
+        Element uiNode = createElement(document,"ui");
+        
+        // TODO mit leben füllen.
+        
+        parent.appendChild(uiNode);
+    }
+    
+    protected void createOutputs(Element parent, Document document){
+        Element outputsNode = createElement(document,"outputs");
+        
+        // TODO mit leben füllen.
+        
+        parent.appendChild(outputsNode);
+    }
+
+    /**
+     * @param document
+     * @return
+     */
+    private Element createElement(Document document, String name) {
+        Element node = document.createElementNS(DefaultArtifact.NAMESPACE_URI, name);
+        node.setPrefix(DefaultArtifact.NAMESPACE_PREFIX);
+        return node;
+    }
+    
 
 }
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/timeseries/TimeSeriesArtifact.java	Tue Sep 08 09:03:48 2009 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/timeseries/TimeSeriesArtifact.java	Tue Sep 08 09:14:35 2009 +0000
@@ -41,7 +41,7 @@
     @Override
     public Document describe(Object context) {
         log.debug("TimeSeriesArtifact.describe");
-        return super.describe(context);
+        return super.createDescibeOutput();
     }
 
     /**
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/transition/TransitionBase.java	Tue Sep 08 09:03:48 2009 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/transition/TransitionBase.java	Tue Sep 08 09:14:35 2009 +0000
@@ -69,7 +69,7 @@
     public void setup(Node configuration) {
         
         this.id = Config.getStringXPath(configuration,"@id");
-        this.description = Config.getStringXPath(configuration,"@descriptionb");
+        this.description = Config.getStringXPath(configuration,"@description");
         
         log.info("Transition-ID = "+ this.id);
         NodeList nodes = Config.getNodeSetXPath(configuration,"reachableTransitions/transition");
--- a/gnv-artifacts/src/test/java/de/intevation/gnv/artifacts/GNVArtifactsTestCase.java	Tue Sep 08 09:03:48 2009 +0000
+++ b/gnv-artifacts/src/test/java/de/intevation/gnv/artifacts/GNVArtifactsTestCase.java	Tue Sep 08 09:14:35 2009 +0000
@@ -3,8 +3,17 @@
  */
 package de.intevation.gnv.artifacts;
 
+import java.io.StringWriter;
+
 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.BasicConfigurator;
 import org.apache.log4j.Logger;
@@ -70,9 +79,12 @@
         
         Document indata = this.getDocument();
         Document outData = this.createOutputDocument();
+        Document outputData = artifact.describe(bootstrap.getContext());
+        this.writeDocument2Log(outputData);
+        
         artifact.feed(indata, bootstrap.getContext());
         artifact.advance(outData, bootstrap.getContext());
-        Document outputData = artifact.describe(bootstrap.getContext());
+        outputData = artifact.describe(bootstrap.getContext());
         
         
         
@@ -108,5 +120,24 @@
         }
         return null;
     }
+    
+    protected void writeDocument2Log(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);
+            log.debug(sw.getBuffer().toString());
+        } catch (TransformerConfigurationException e) {
+            log.error(e,e);
+        } catch (TransformerFactoryConfigurationError e) {
+            log.error(e,e);
+        } catch (TransformerException e) {
+            log.error(e,e);
+        }
+    }
+    
 
 }

http://dive4elements.wald.intevation.org