Mercurial > dive4elements > gnv-client
comparison gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/GNVArtifactBase.java @ 778:9a828e5a2390
Removed trailing whitespace
gnv-artifacts/trunk@851 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Mon, 29 Mar 2010 07:58:51 +0000 |
parents | d47901df0a14 |
children | b1f5f2a8840f |
comparison
equal
deleted
inserted
replaced
777:8009961db1cb | 778:9a828e5a2390 |
---|---|
47 /** | 47 /** |
48 * @author Tim Englich (tim.englich@intevation.de) | 48 * @author Tim Englich (tim.englich@intevation.de) |
49 * @author Ingo Weinzierl (ingo.weinzierl@intevation.de) | 49 * @author Ingo Weinzierl (ingo.weinzierl@intevation.de) |
50 * @author Sascha L. Teichmann (sascha.teichmann@intevation.de) | 50 * @author Sascha L. Teichmann (sascha.teichmann@intevation.de) |
51 */ | 51 */ |
52 public abstract class GNVArtifactBase extends GNVDefaultArtifact | 52 public abstract class GNVArtifactBase extends GNVDefaultArtifact |
53 implements PreSettingArtifact { | 53 implements PreSettingArtifact { |
54 | 54 |
55 /** | 55 /** |
56 * the logger, used to log exceptions and additonaly information | 56 * the logger, used to log exceptions and additonaly information |
57 */ | 57 */ |
79 | 79 |
80 public static final String XPATH_INCLUDE_UI = "/art:action/art:include-ui"; | 80 public static final String XPATH_INCLUDE_UI = "/art:action/art:include-ui"; |
81 | 81 |
82 public static final String XPATH_TARGET_NAME = "/art:action/art:target/@name"; | 82 public static final String XPATH_TARGET_NAME = "/art:action/art:target/@name"; |
83 | 83 |
84 public static final String XPATH_OUTPUT_NAME = "/art:action/art:out/@name"; | 84 public static final String XPATH_OUTPUT_NAME = "/art:action/art:out/@name"; |
85 | 85 |
86 public static final String XPATH_OUTPUT_PARAMS = "/art:action/art:out/art:params/art:input"; | 86 public static final String XPATH_OUTPUT_PARAMS = "/art:action/art:out/art:params/art:input"; |
87 | 87 |
88 public static final String INITIAL_STATE = "product"; | 88 public static final String INITIAL_STATE = "product"; |
89 | 89 |
90 /** | 90 /** |
91 * The current State | 91 * The current State |
94 | 94 |
95 /** | 95 /** |
96 * The States that can be used | 96 * The States that can be used |
97 */ | 97 */ |
98 protected Map<String, State> states = null; | 98 protected Map<String, State> states = null; |
99 | 99 |
100 /** | 100 /** |
101 * The Transitions which can switch between the different States. | 101 * The Transitions which can switch between the different States. |
102 */ | 102 */ |
103 protected Collection<Transition> transitions = null; | 103 protected Collection<Transition> transitions = null; |
104 | 104 |
158 if (isStateCurrentlyReachable(targetState)) { | 158 if (isStateCurrentlyReachable(targetState)) { |
159 | 159 |
160 next = states.get(targetState); | 160 next = states.get(targetState); |
161 | 161 |
162 boolean success = go2NextState(context, result, next); | 162 boolean success = go2NextState(context, result, next); |
163 | 163 |
164 if (success){ | 164 if (success){ |
165 result = createReport( | 165 result = createReport( |
166 result, "result", "success", "Advance success" | 166 result, "result", "success", "Advance success" |
167 ); | 167 ); |
168 }else{ | 168 }else{ |
169 result = ArtifactXMLUtilities. | 169 result = ArtifactXMLUtilities. |
170 createExceptionReport("Error while going to next State.", | 170 createExceptionReport("Error while going to next State.", |
171 XMLUtils.newDocument()); | 171 XMLUtils.newDocument()); |
172 } | 172 } |
173 } | 173 } |
174 | 174 |
175 // step backward | 175 // step backward |
307 } | 307 } |
308 } | 308 } |
309 } | 309 } |
310 return false; | 310 return false; |
311 } | 311 } |
312 | 312 |
313 public Document initialize (CallContext context) { | 313 public Document initialize (CallContext context) { |
314 Document result = XMLUtils.newDocument(); | 314 Document result = XMLUtils.newDocument(); |
315 try { | 315 try { |
316 this.current.initialize(super.identifier, context); | 316 this.current.initialize(super.identifier, context); |
317 | 317 |
318 if (this.current instanceof AutoResumeState){ | 318 if (this.current instanceof AutoResumeState){ |
319 // Jump to next State using the Transitions. | 319 // Jump to next State using the Transitions. |
320 State next = this.getNextReachableState(this.current); | 320 State next = this.getNextReachableState(this.current); |
321 if (next != null){ | 321 if (next != null){ |
322 boolean success = go2NextState(context, result, next); | 322 boolean success = go2NextState(context, result, next); |
325 .createSuccessReport("Initialize success", | 325 .createSuccessReport("Initialize success", |
326 XMLUtils.newDocument()); | 326 XMLUtils.newDocument()); |
327 }else{ | 327 }else{ |
328 result = ArtifactXMLUtilities. | 328 result = ArtifactXMLUtilities. |
329 createExceptionReport( | 329 createExceptionReport( |
330 "Error while going to next State.", | 330 "Error while going to next State.", |
331 XMLUtils.newDocument()); | 331 XMLUtils.newDocument()); |
332 } | 332 } |
333 }else{ | 333 }else{ |
334 result = ArtifactXMLUtilities. | 334 result = ArtifactXMLUtilities. |
335 createExceptionReport("No propper State found.", | 335 createExceptionReport("No propper State found.", |
336 XMLUtils.newDocument()); | 336 XMLUtils.newDocument()); |
337 } | 337 } |
338 }else{ | 338 }else{ |
339 result = ArtifactXMLUtilities | 339 result = ArtifactXMLUtilities |
340 .createSuccessReport("Initialize success", | 340 .createSuccessReport("Initialize success", |
345 result = ArtifactXMLUtilities.createExceptionReport(e | 345 result = ArtifactXMLUtilities.createExceptionReport(e |
346 .getLocalizedMessage(), XMLUtils.newDocument()); | 346 .getLocalizedMessage(), XMLUtils.newDocument()); |
347 } | 347 } |
348 return result; | 348 return result; |
349 } | 349 } |
350 | 350 |
351 protected State getNextReachableState(State current){ | 351 protected State getNextReachableState(State current){ |
352 Iterator<Transition> it = this.transitions.iterator(); | 352 Iterator<Transition> it = this.transitions.iterator(); |
353 String from = current.getID(); | 353 String from = current.getID(); |
354 while (it.hasNext()){ | 354 while (it.hasNext()){ |
355 Transition transition = it.next(); | 355 Transition transition = it.next(); |
370 | 370 |
371 protected Node getConfigurationFragment(Document document) { | 371 protected Node getConfigurationFragment(Document document) { |
372 log.debug("GNVArtifactBase.getConfigurationFragment"); | 372 log.debug("GNVArtifactBase.getConfigurationFragment"); |
373 String xpathQuery = XPATH_ARTIFACT_CONFIGURATION.replaceAll( | 373 String xpathQuery = XPATH_ARTIFACT_CONFIGURATION.replaceAll( |
374 XPATH_IDENTIFIER_REPLACE, this.name); | 374 XPATH_IDENTIFIER_REPLACE, this.name); |
375 | 375 |
376 Element configurationNode = (Element)Config.getNodeXPath(document, xpathQuery); | 376 Element configurationNode = (Element)Config.getNodeXPath(document, xpathQuery); |
377 | 377 |
378 String link = configurationNode.getAttribute("xlink:href"); | 378 String link = configurationNode.getAttribute("xlink:href"); |
379 if (link != null ){ | 379 if (link != null ){ |
380 String absolutFileName = Config.replaceConfigDir(link); | 380 String absolutFileName = Config.replaceConfigDir(link); |
381 configurationNode = (Element)new ArtifactXMLUtilities().readConfiguration(absolutFileName); | 381 configurationNode = (Element)new ArtifactXMLUtilities().readConfiguration(absolutFileName); |
382 } | 382 } |
383 | 383 |
384 return configurationNode; | 384 return configurationNode; |
385 } | 385 } |
386 | 386 |
387 /** | 387 /** |
388 * @see de.intevation.artifactdatabase.DefaultArtifact#feed(org.w3c.dom.Document, | 388 * @see de.intevation.artifactdatabase.DefaultArtifact#feed(org.w3c.dom.Document, |
449 | 449 |
450 /** | 450 /** |
451 * @see de.intevation.artifactdatabase.DefaultArtifact#setup(java.lang.String, de.intevation.artifacts.ArtifactFactory, java.lang.Object, org.w3c.dom.Document) | 451 * @see de.intevation.artifactdatabase.DefaultArtifact#setup(java.lang.String, de.intevation.artifacts.ArtifactFactory, java.lang.Object, org.w3c.dom.Document) |
452 */ | 452 */ |
453 @Override | 453 @Override |
454 public void setup(String identifier, ArtifactFactory factory, | 454 public void setup(String identifier, ArtifactFactory factory, |
455 Object context,Document data) { | 455 Object context,Document data) { |
456 log.debug("GNVArtifactBase.setup"); | 456 log.debug("GNVArtifactBase.setup"); |
457 super.setup(identifier, factory, context, data); | 457 super.setup(identifier, factory, context, data); |
458 | 458 |
459 Object localContext = context; | 459 Object localContext = context; |
464 | 464 |
465 if (localContext instanceof GNVArtifactContext) { | 465 if (localContext instanceof GNVArtifactContext) { |
466 GNVArtifactContext gnvContext = (GNVArtifactContext) localContext; | 466 GNVArtifactContext gnvContext = (GNVArtifactContext) localContext; |
467 Document doc = gnvContext.getConfig(); | 467 Document doc = gnvContext.getConfig(); |
468 Node artifactNode = this.getConfigurationFragment(doc); | 468 Node artifactNode = this.getConfigurationFragment(doc); |
469 | 469 |
470 NodeList stateList = Config.getNodeSetXPath(artifactNode, | 470 NodeList stateList = Config.getNodeSetXPath(artifactNode, |
471 "states/state"); | 471 "states/state"); |
472 this.states = new HashMap<String, State>(stateList | 472 this.states = new HashMap<String, State>(stateList |
473 .getLength()); | 473 .getLength()); |
474 for (int i = 0; i < stateList.getLength(); i++) { | 474 for (int i = 0; i < stateList.getLength(); i++) { |
480 if (this.current == null) { | 480 if (this.current == null) { |
481 this.current = tmpState; | 481 this.current = tmpState; |
482 } | 482 } |
483 } | 483 } |
484 } | 484 } |
485 | 485 |
486 NodeList transitionList = Config.getNodeSetXPath(artifactNode, | 486 NodeList transitionList = Config.getNodeSetXPath(artifactNode, |
487 "states/transition"); | 487 "states/transition"); |
488 this.transitions = new ArrayList<Transition>(transitionList.getLength()); | 488 this.transitions = new ArrayList<Transition>(transitionList.getLength()); |
489 for (int i = 0; i < transitionList.getLength(); i++) { | 489 for (int i = 0; i < transitionList.getLength(); i++) { |
490 Transition tmpTransition = TransitionFactory.getInstance() | 490 Transition tmpTransition = TransitionFactory.getInstance() |
521 this.createUserInterface(creator, rootNode, document, context, uuid); | 521 this.createUserInterface(creator, rootNode, document, context, uuid); |
522 } | 522 } |
523 | 523 |
524 return document; | 524 return document; |
525 } | 525 } |
526 | 526 |
527 protected boolean getIncludeUIFromDocument(Document document){ | 527 protected boolean getIncludeUIFromDocument(Document document){ |
528 String value = XMLUtils.xpathString( | 528 String value = XMLUtils.xpathString( |
529 document, XPATH_INCLUDE_UI, ArtifactNamespaceContext.INSTANCE); | 529 document, XPATH_INCLUDE_UI, ArtifactNamespaceContext.INSTANCE); |
530 | 530 |
531 boolean includeUI = false; | 531 boolean includeUI = false; |
869 | 869 |
870 if (current != null) { | 870 if (current != null) { |
871 current.endOfLife(globalContext); | 871 current.endOfLife(globalContext); |
872 } | 872 } |
873 } | 873 } |
874 | 874 |
875 /** | 875 /** |
876 * @see de.intevation.gnv.artifacts.PreSettingArtifact#getPreSettings() | 876 * @see de.intevation.gnv.artifacts.PreSettingArtifact#getPreSettings() |
877 */ | 877 */ |
878 public Map<String, InputData> getPreSettings() { | 878 public Map<String, InputData> getPreSettings() { |
879 return this.preSettings; | 879 return this.preSettings; |
880 } | 880 } |
881 | 881 |
882 /** | 882 /** |
883 * @see de.intevation.gnv.artifacts.PreSettingArtifact#setPreSettings(java.util.Map) | 883 * @see de.intevation.gnv.artifacts.PreSettingArtifact#setPreSettings(java.util.Map) |
884 */ | 884 */ |
885 public void setPreSettings(Map<String, InputData> preSettings) { | 885 public void setPreSettings(Map<String, InputData> preSettings) { |
886 this.preSettings = preSettings; | 886 this.preSettings = preSettings; |