Mercurial > dive4elements > gnv-client
comparison gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/GNVArtifactBase.java @ 204:734ac082c8d1
Split the Configuration File in several small Documents to speed up the Artifactinstantiation and also make the administration of the Artifactdatabase easier. issue40 and issue59
gnv-artifacts/trunk@259 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Tim Englich <tim.englich@intevation.de> |
---|---|
date | Thu, 22 Oct 2009 08:50:21 +0000 |
parents | 00c1a931b9c3 |
children | d87347142702 |
comparison
equal
deleted
inserted
replaced
203:226091ed3cbd | 204:734ac082c8d1 |
---|---|
8 import java.util.Collection; | 8 import java.util.Collection; |
9 import java.util.HashMap; | 9 import java.util.HashMap; |
10 import java.util.Iterator; | 10 import java.util.Iterator; |
11 import java.util.Map; | 11 import java.util.Map; |
12 | 12 |
13 import javax.xml.parsers.DocumentBuilderFactory; | |
14 import javax.xml.parsers.ParserConfigurationException; | |
13 import javax.xml.xpath.XPathConstants; | 15 import javax.xml.xpath.XPathConstants; |
14 | 16 |
15 import org.apache.log4j.Logger; | 17 import org.apache.log4j.Logger; |
16 import org.w3c.dom.Document; | 18 import org.w3c.dom.Document; |
17 import org.w3c.dom.Element; | 19 import org.w3c.dom.Element; |
18 import org.w3c.dom.Node; | 20 import org.w3c.dom.Node; |
19 import org.w3c.dom.NodeList; | 21 import org.w3c.dom.NodeList; |
22 import org.xml.sax.SAXException; | |
20 | 23 |
21 import de.intevation.artifactdatabase.Config; | 24 import de.intevation.artifactdatabase.Config; |
22 import de.intevation.artifactdatabase.DefaultArtifact; | 25 import de.intevation.artifactdatabase.DefaultArtifact; |
23 import de.intevation.artifactdatabase.XMLUtils; | 26 import de.intevation.artifactdatabase.XMLUtils; |
24 import de.intevation.artifacts.ArtifactFactory; | 27 import de.intevation.artifacts.ArtifactFactory; |
106 try { | 109 try { |
107 Transition nextStep = this.transitions | 110 Transition nextStep = this.transitions |
108 .get(transitionName); | 111 .get(transitionName); |
109 // 2.Ergebnisse Berechnen | 112 // 2.Ergebnisse Berechnen |
110 this.current.advance(uuid, context.getMeta()); | 113 this.current.advance(uuid, context.getMeta()); |
111 // 3. Ergebnisse übergeben | 114 // 3. Ergebnisse Übergeben |
112 nextStep.setDescibeData(this.current | 115 nextStep.setDescibeData(this.current |
113 .getDescibeData()); | 116 .getDescibeData()); |
114 nextStep.putInputData(this.current.getInputData(), | 117 nextStep.putInputData(this.current.getInputData(), |
115 uuid); | 118 uuid); |
116 // 4. Umschalten auf neue Transistion | 119 // 4. Umschalten auf neue Transistion |
164 protected Node getConfigurationFragment(Document document) { | 167 protected Node getConfigurationFragment(Document document) { |
165 log.debug("GNVArtifactBase.getConfigurationFragment"); | 168 log.debug("GNVArtifactBase.getConfigurationFragment"); |
166 String xpathQuery = XPATH_ARTIFACT_CONFIGURATION.replaceAll( | 169 String xpathQuery = XPATH_ARTIFACT_CONFIGURATION.replaceAll( |
167 XPATH_IDENTIFIER_REPLACE, this.name); | 170 XPATH_IDENTIFIER_REPLACE, this.name); |
168 log.debug(xpathQuery); | 171 log.debug(xpathQuery); |
169 return Config.getNodeXPath(document, xpathQuery); | 172 |
173 Element configurationNode = (Element)Config.getNodeXPath(document, xpathQuery); | |
174 | |
175 String link = configurationNode.getAttribute("xlink:href"); | |
176 if (link != null ){ | |
177 String absolutFileName = Config.replaceConfigDir(link); | |
178 configurationNode = (Element)this.readConfiguration(absolutFileName); | |
179 } | |
180 | |
181 return configurationNode; | |
182 } | |
183 | |
184 | |
185 private Node readConfiguration(String fileName){ | |
186 try { | |
187 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); | |
188 factory.setValidating(false); | |
189 return factory.newDocumentBuilder().parse(fileName).getChildNodes().item(0); | |
190 } catch (SAXException e) { | |
191 log.error(e,e); | |
192 return null; | |
193 } catch (IOException e) { | |
194 log.error(e,e); | |
195 return null; | |
196 } catch (ParserConfigurationException e) { | |
197 log.error(e,e); | |
198 return null; | |
199 } | |
170 } | 200 } |
171 | 201 |
172 /** | 202 /** |
173 * @see de.intevation.artifactdatabase.DefaultArtifact#feed(org.w3c.dom.Document, | 203 * @see de.intevation.artifactdatabase.DefaultArtifact#feed(org.w3c.dom.Document, |
174 * de.intevation.artifacts.CallContext) | 204 * de.intevation.artifacts.CallContext) |
224 | 254 |
225 if (localContext instanceof GNVArtifactContext) { | 255 if (localContext instanceof GNVArtifactContext) { |
226 GNVArtifactContext gnvContext = (GNVArtifactContext) localContext; | 256 GNVArtifactContext gnvContext = (GNVArtifactContext) localContext; |
227 Document doc = gnvContext.getConfig(); | 257 Document doc = gnvContext.getConfig(); |
228 Node artifactNode = this.getConfigurationFragment(doc); | 258 Node artifactNode = this.getConfigurationFragment(doc); |
259 | |
229 NodeList transitionList = Config.getNodeSetXPath(artifactNode, | 260 NodeList transitionList = Config.getNodeSetXPath(artifactNode, |
230 "transitions/transition"); | 261 "transitions/transition"); |
231 this.transitions = new HashMap<String, Transition>(transitionList | 262 this.transitions = new HashMap<String, Transition>(transitionList |
232 .getLength()); | 263 .getLength()); |
233 for (int i = 0; i < transitionList.getLength(); i++) { | 264 for (int i = 0; i < transitionList.getLength(); i++) { |
401 // ""); | 432 // ""); |
402 if (inputElemets != null) { | 433 if (inputElemets != null) { |
403 returnValue = new HashMap<String, InputData>(inputElemets | 434 returnValue = new HashMap<String, InputData>(inputElemets |
404 .getLength()); | 435 .getLength()); |
405 for (int i = 0; i < inputElemets.getLength(); i++) { | 436 for (int i = 0; i < inputElemets.getLength(); i++) { |
406 Node inputDataNode = inputElemets.item(i); | 437 Element inputDataNode = (Element)inputElemets.item(i); |
407 String name = Config.getStringXPath(inputDataNode, "@name"); | 438 String name = inputDataNode.getAttribute("name"); |
408 String value = Config.getStringXPath(inputDataNode, "@value"); | 439 String value = inputDataNode.getAttribute("value"); |
409 | 440 |
410 if (returnValue.containsKey(name)) { | 441 if (returnValue.containsKey(name)) { |
411 InputData inputData = returnValue.get(name); | 442 InputData inputData = returnValue.get(name); |
412 inputData.concartValue(value); | 443 inputData.concartValue(value); |
413 log.debug(inputData.toString()); | 444 log.debug(inputData.toString()); |