changeset 59:2c5d8f5bced1

Outputs integrated in describe and XForms integrated gnv-artifacts/trunk@41 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Tim Englich <tim.englich@intevation.de>
date Tue, 08 Sep 2009 16:21:46 +0000 (2009-09-08)
parents f31343d80d53
children eed1baaeb481
files gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/GNVArtifactBase.java gnv-artifacts/src/main/java/de/intevation/gnv/transition/DefaultTransition.java gnv-artifacts/src/main/java/de/intevation/gnv/transition/Transition.java gnv-artifacts/src/main/java/de/intevation/gnv/transition/TransitionBase.java
diffstat 4 files changed, 80 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/GNVArtifactBase.java	Tue Sep 08 14:07:59 2009 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/GNVArtifactBase.java	Tue Sep 08 16:21:46 2009 +0000
@@ -90,6 +90,7 @@
                         this.current.advance();
                         // 3. Ergebnisse �bergeben
                         nextStep.setDescibeData(this.current.getDescibeData());
+                        nextStep.putInputData(this.current.getInputData());
                         // 4. Umschalten auf neue Transistion
                         this.current = nextStep;
                     } catch (TransitionException e) {
@@ -176,6 +177,7 @@
         Document document = super.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);
@@ -257,7 +259,9 @@
     protected void createOutputs(Element parent, Document document){
         Element outputsNode = createElement(document,"outputs");
         
-        // TODO mit leben f�llen.
+        if (this.current != null){
+            this.current.describe(document, outputsNode);
+        }
         
         parent.appendChild(outputsNode);
     }
@@ -288,6 +292,4 @@
         }
         return returnValue;
     }
-    
-
 }
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/transition/DefaultTransition.java	Tue Sep 08 14:07:59 2009 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/transition/DefaultTransition.java	Tue Sep 08 16:21:46 2009 +0000
@@ -3,7 +3,6 @@
  */
 package de.intevation.gnv.transition;
 
-import org.w3c.dom.Document;
 
 /**
  * @author Tim Englich <tim.englich@intevation.de>
@@ -17,13 +16,6 @@
     public DefaultTransition() {
     }
 
-    /**
-     * @see de.intevation.gnv.transition.Transition#describe()
-     */
-    public Document describe() {
-
-        return null;
-    }
 
     /**
      * @see de.intevation.gnv.transition.Transition#validate()
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/transition/Transition.java	Tue Sep 08 14:07:59 2009 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/transition/Transition.java	Tue Sep 08 16:21:46 2009 +0000
@@ -28,7 +28,7 @@
     
     public boolean validate();
     
-    public Document describe();
+    public void describe(Document document, Node rootNode);
     
     public void setParent(Transition transition);
     
@@ -38,6 +38,8 @@
     
     public void putInputData(Collection<InputData> inputData) throws TransitionException;
     
+    public Collection<InputData> getInputData() throws TransitionException;
+    
     public void advance() throws TransitionException;
     
     
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/transition/TransitionBase.java	Tue Sep 08 14:07:59 2009 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/transition/TransitionBase.java	Tue Sep 08 16:21:46 2009 +0000
@@ -11,6 +11,7 @@
 
 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;
 
@@ -32,6 +33,9 @@
      */
     private static Logger log = Logger.getLogger(GNVArtifactBase.class);
     
+    public static final String XFORM_URL = "http://www.w3.org/2002/xforms";
+    public static final String XFORM_PREFIX = "xform";
+    
     private String id = null;
     
     private String description = null;
@@ -147,14 +151,13 @@
                 if (inputValue != null){
                     if (this.inputData == null){
                         this.inputData = new HashMap<String,InputData>(inputData.size());
-                        // TODO validate Value; und Valueconcatenieren
-                        this.inputData.put(tmpItem.getName(),tmpItem);
                     }
+                    // TODO validate Value; und Valueconcatenieren
+                    this.inputData.put(tmpItem.getName(),tmpItem);
                     
                 }else{
                     String errMsg = "No Inputvalue given for Inputdata "+ tmpItem.getName();
                     log.warn(errMsg+ "Value will be ignored");
-                    throw new TransitionException(errMsg);
                     
                 }
             }
@@ -191,7 +194,9 @@
             Iterator<String> it = this.inputValueNames.iterator();
             int i = 0;
             while (it.hasNext()){
-                filterValues[i++] = this.inputData.get(it.next()).getValue();
+                String value = it.next();
+                InputData data = this.inputData.get(value);
+                filterValues[i++] = data.getValue();
             }
             QueryExecutor queryExecutor = QueryExecutorFactory.getInstance().getQueryExecutor();
             Collection<Result> result = queryExecutor.executeQuery(this.queryID, filterValues);
@@ -204,6 +209,62 @@
             throw new TransitionException(e);
         }
     }
+    
+    /**
+     * @see de.intevation.gnv.transition.Transition#describe(org.w3c.dom.Document, org.w3c.dom.Node)
+     */
+    public void describe(Document document, Node rootNode) {
+        
+        if(this.descibeData != null){
+            Iterator<Object> it = this.descibeData.iterator();
+            while (it.hasNext()){
+                Element selectNode = this.createXFormElement(document,"select");
+                // TODO: HACK:
+                // BESSERE L�SUNG FINDEN
+                Object[] names = this.inputValueNames.toArray();
+                String name = names[names.length-1].toString();
+                
+                selectNode.setAttribute("ref", name);
+                
+                Element lableNode = this.createXFormElement(document, "label");
+                lableNode.setTextContent(name);
+                Element choiceNode = this.createXFormElement(document, "choices");
+                
+                
+                Object o = it.next();
+                if (o instanceof Collection<?>){
+                    Collection<Result> values = (Collection)o;
+                    Iterator<Result> resultIt = values.iterator();
+                    while (resultIt.hasNext()){
+                        Result result = resultIt.next();
+                        Element itemNode = this.createXFormElement(document, "item");
+                        String lableName = result.getResultDescriptor().getColumnName(1);
+                        String valueName = result.getResultDescriptor().getColumnName(0);
+                        
+                        Element choiceLableNode = this.createXFormElement(document, "label");
+                        choiceLableNode.setTextContent(result.getString(lableName));
+                        itemNode.appendChild(choiceLableNode);
+                        
+                        Element choicValueNode = this.createXFormElement(document, "value");
+                        choicValueNode.setTextContent(result.getString(valueName));
+                        itemNode.appendChild(choicValueNode);
+                        
+                        choiceNode.appendChild(itemNode);
+                    }
+                }
+                selectNode.appendChild(lableNode);
+                selectNode.appendChild(choiceNode);
+                rootNode.appendChild(selectNode);
+            }
+        }
+       
+    }
+
+    private Element createXFormElement(Document document, String name) {
+        Element node = document.createElementNS(XFORM_URL, name);
+        node.setPrefix(XFORM_PREFIX);
+        return node;
+    }
 
     /**
      * @see de.intevation.gnv.transition.Transition#getDescibeData()
@@ -219,4 +280,11 @@
         this.descibeData = descibeData;
         
     }
+
+    /**
+     * @see de.intevation.gnv.transition.Transition#getInputData()
+     */
+    public Collection<InputData> getInputData() throws TransitionException {
+        return this.inputData.values();
+    }
 }

http://dive4elements.wald.intevation.org