Mercurial > dive4elements > gnv-client
comparison gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/GNVArtifactBase.java @ 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 | 4d6a82b96059 |
children | 737d8bf63701 |
comparison
equal
deleted
inserted
replaced
53:e464d9f9d967 | 54:09b4bf848c7b |
---|---|
2 * | 2 * |
3 */ | 3 */ |
4 package de.intevation.gnv.artifacts; | 4 package de.intevation.gnv.artifacts; |
5 | 5 |
6 import java.util.HashMap; | 6 import java.util.HashMap; |
7 import java.util.Iterator; | |
7 import java.util.Map; | 8 import java.util.Map; |
8 | 9 |
9 import org.apache.log4j.Logger; | 10 import org.apache.log4j.Logger; |
10 import org.w3c.dom.Document; | 11 import org.w3c.dom.Document; |
12 import org.w3c.dom.Element; | |
11 import org.w3c.dom.Node; | 13 import org.w3c.dom.Node; |
12 import org.w3c.dom.NodeList; | 14 import org.w3c.dom.NodeList; |
13 | 15 |
14 import de.intevation.artifactdatabase.Config; | 16 import de.intevation.artifactdatabase.Config; |
15 import de.intevation.artifactdatabase.DefaultArtifact; | 17 import de.intevation.artifactdatabase.DefaultArtifact; |
29 /** | 31 /** |
30 * The UID of this Class | 32 * The UID of this Class |
31 */ | 33 */ |
32 private static final long serialVersionUID = -8907096744400741458L; | 34 private static final long serialVersionUID = -8907096744400741458L; |
33 | 35 |
36 /** | |
37 * The Identifier for the Replacement of the Artifactname | |
38 */ | |
34 public static final String XPATH_IDENTIFIER_REPLACE = "IDENTIFIER"; | 39 public static final String XPATH_IDENTIFIER_REPLACE = "IDENTIFIER"; |
40 | |
35 /** | 41 /** |
36 * The XPATH to the XML-Fragment that should be used for the Configuration | 42 * The XPATH to the XML-Fragment that should be used for the Configuration |
37 */ | 43 */ |
38 public static final String XPATH_ARTIFACT_CONFIGURATION= "/artifact-database/artifacts/artifact[@name='"+XPATH_IDENTIFIER_REPLACE+"']"; | 44 public static final String XPATH_ARTIFACT_CONFIGURATION= "/artifact-database/artifacts/artifact[@name='"+XPATH_IDENTIFIER_REPLACE+"']"; |
39 | 45 |
46 | |
47 /** | |
48 * The current Transition | |
49 */ | |
40 protected Transition current = null; | 50 protected Transition current = null; |
41 | 51 |
52 /** | |
53 * The Transitions that can be used | |
54 */ | |
42 protected Map<String, Transition> transitions = null; | 55 protected Map<String, Transition> transitions = null; |
43 | 56 |
57 /** | |
58 * The Name of the Artifact | |
59 */ | |
44 protected String name = null; | 60 protected String name = null; |
61 | |
45 /** | 62 /** |
46 * Constructor | 63 * Constructor |
47 */ | 64 */ |
48 public GNVArtifactBase() { | 65 public GNVArtifactBase() { |
49 super(); | 66 super(); |
52 protected Node getConfigurationFragment(Document document){ | 69 protected Node getConfigurationFragment(Document document){ |
53 log.debug("GNVArtifactBase.getConfigurationFragment"); | 70 log.debug("GNVArtifactBase.getConfigurationFragment"); |
54 String xpathQuery = XPATH_ARTIFACT_CONFIGURATION.replaceAll(XPATH_IDENTIFIER_REPLACE, this.name); | 71 String xpathQuery = XPATH_ARTIFACT_CONFIGURATION.replaceAll(XPATH_IDENTIFIER_REPLACE, this.name); |
55 log.debug(xpathQuery); | 72 log.debug(xpathQuery); |
56 return Config.getNodeXPath(document,xpathQuery); | 73 return Config.getNodeXPath(document,xpathQuery); |
57 | |
58 } | 74 } |
59 | 75 |
60 /** | 76 /** |
61 * @see de.intevation.artifactdatabase.DefaultArtifact#setup(java.lang.String, java.lang.Object) | 77 * @see de.intevation.artifactdatabase.DefaultArtifact#setup(java.lang.String, java.lang.Object) |
62 */ | 78 */ |
81 } | 97 } |
82 | 98 |
83 } | 99 } |
84 } | 100 } |
85 | 101 |
102 | |
103 protected Document createDescibeOutput(){ | |
104 log.debug("GNVArtifactBase.createDescibeOutput"); | |
105 Document document = super.newDocument(); | |
106 Element rootNode = this.createRootNode(document); | |
107 this.createHeader(rootNode, document, "describe"); | |
108 this.createCurrentState(rootNode, document); | |
109 this.createReachableStates(rootNode, document); | |
110 this.createModel(rootNode, document); | |
111 this.createUserInterface(rootNode, document); | |
112 | |
113 return document; | |
114 } | |
115 | |
116 protected Element createRootNode(Document document){ | |
117 Element rootNode = createElement(document,"result"); | |
118 document.appendChild(rootNode); | |
119 return rootNode; | |
120 } | |
121 | |
122 protected void createHeader(Element parent, Document document, String documentType){ | |
123 Element typeNode = createElement(document,"type"); | |
124 typeNode.setAttribute("name", documentType); | |
125 parent.appendChild(typeNode); | |
126 | |
127 Element uuidNode = createElement(document,"uuid"); | |
128 uuidNode.setAttribute("value", super.identifier); | |
129 parent.appendChild(uuidNode); | |
130 | |
131 Element hashNode = createElement(document,"hash"); | |
132 hashNode.setAttribute("value", this.hash()); | |
133 parent.appendChild(hashNode); | |
134 | |
135 | |
136 } | |
137 protected void createReachableStates(Element parent,Document document){ | |
138 Element stateNode = createElement(document,"reachable-states"); | |
139 if (this.current != null){ | |
140 Iterator<String> states = this.current.reachableTransitions().iterator(); | |
141 while(states.hasNext()){ | |
142 String value = states.next(); | |
143 Element currentNode = createElement(document,"state"); | |
144 currentNode.setAttribute("name", value); | |
145 currentNode.setAttribute("description", transitions.get(value).getDescription()); | |
146 stateNode.appendChild(currentNode); | |
147 } | |
148 } | |
149 parent.appendChild(stateNode); | |
150 } | |
151 | |
152 protected void createCurrentState(Element parent, Document document){ | |
153 Element stateNode = createElement(document,"state"); | |
154 stateNode.setAttribute("name", this.current.getID()); | |
155 stateNode.setAttribute("description", this.current.getDescription()); | |
156 parent.appendChild(stateNode); | |
157 } | |
158 | |
159 | |
160 protected void createModel(Element parent, Document document){ | |
161 Element modelNode = createElement(document,"model"); | |
162 // TODO mit leben füllen. | |
163 | |
164 parent.appendChild(modelNode); | |
165 } | |
166 | |
167 protected void createUserInterface(Element parent, Document document){ | |
168 Element uiNode = createElement(document,"ui"); | |
169 | |
170 // TODO mit leben füllen. | |
171 | |
172 parent.appendChild(uiNode); | |
173 } | |
174 | |
175 protected void createOutputs(Element parent, Document document){ | |
176 Element outputsNode = createElement(document,"outputs"); | |
177 | |
178 // TODO mit leben füllen. | |
179 | |
180 parent.appendChild(outputsNode); | |
181 } | |
182 | |
183 /** | |
184 * @param document | |
185 * @return | |
186 */ | |
187 private Element createElement(Document document, String name) { | |
188 Element node = document.createElementNS(DefaultArtifact.NAMESPACE_URI, name); | |
189 node.setPrefix(DefaultArtifact.NAMESPACE_PREFIX); | |
190 return node; | |
191 } | |
192 | |
86 | 193 |
87 } | 194 } |