Mercurial > dive4elements > gnv-client
comparison gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/GNVArtifactBase.java @ 789:0dc115cbef0d
Added javadoc for artifact package.
gnv-artifacts/trunk@871 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Wed, 31 Mar 2010 09:09:05 +0000 |
parents | c4156275c1e1 |
children | feae2f9d6c6f |
comparison
equal
deleted
inserted
replaced
788:e8a9e84a0328 | 789:0dc115cbef0d |
---|---|
53 import org.w3c.dom.Element; | 53 import org.w3c.dom.Element; |
54 import org.w3c.dom.Node; | 54 import org.w3c.dom.Node; |
55 import org.w3c.dom.NodeList; | 55 import org.w3c.dom.NodeList; |
56 | 56 |
57 /** | 57 /** |
58 * This is the major gnv artifact and handles the requests specified in | |
59 * {@link de.intevation.artifactdatabase.Artifact}. | |
60 * | |
58 * @author <a href="mailto:tim.englich@intevation.de">Tim Englich</a> | 61 * @author <a href="mailto:tim.englich@intevation.de">Tim Englich</a> |
59 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> | 62 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> |
60 * @author <a href="mailto:sascha.teichmann@intevation.de">Sascha L. Teichmann</a> | 63 * @author <a href="mailto:sascha.teichmann@intevation.de">Sascha L. Teichmann</a> |
61 */ | 64 */ |
62 public abstract class GNVArtifactBase extends GNVDefaultArtifact | 65 public abstract class GNVArtifactBase extends GNVDefaultArtifact |
81 */ | 84 */ |
82 public static final String XPATH_ARTIFACT_CONFIGURATION = "/artifact-database/artifacts/artifact[@name='" | 85 public static final String XPATH_ARTIFACT_CONFIGURATION = "/artifact-database/artifacts/artifact[@name='" |
83 + XPATH_IDENTIFIER_REPLACE | 86 + XPATH_IDENTIFIER_REPLACE |
84 + "']"; | 87 + "']"; |
85 | 88 |
89 /** | |
90 * | |
91 */ | |
86 public static final String XPATH_STATIC_NODE = "/art:result/art:ui/art:static"; | 92 public static final String XPATH_STATIC_NODE = "/art:result/art:ui/art:static"; |
87 | 93 |
94 /** | |
95 * | |
96 */ | |
88 public static final String XPATH_INPUT_DATA = "/art:action/art:data/art:input"; | 97 public static final String XPATH_INPUT_DATA = "/art:action/art:data/art:input"; |
89 | 98 |
99 /** | |
100 * | |
101 */ | |
90 public static final String XPATH_INCLUDE_UI = "/art:action/art:include-ui"; | 102 public static final String XPATH_INCLUDE_UI = "/art:action/art:include-ui"; |
91 | 103 |
104 /** | |
105 * | |
106 */ | |
92 public static final String XPATH_TARGET_NAME = "/art:action/art:target/@name"; | 107 public static final String XPATH_TARGET_NAME = "/art:action/art:target/@name"; |
93 | 108 |
109 /** | |
110 * | |
111 */ | |
94 public static final String XPATH_OUTPUT_NAME = "/art:action/art:out/@name"; | 112 public static final String XPATH_OUTPUT_NAME = "/art:action/art:out/@name"; |
95 | 113 |
114 /** | |
115 * | |
116 */ | |
96 public static final String XPATH_OUTPUT_PARAMS = "/art:action/art:out/art:params/art:input"; | 117 public static final String XPATH_OUTPUT_PARAMS = "/art:action/art:out/art:params/art:input"; |
97 | 118 |
119 /** | |
120 * | |
121 */ | |
98 public static final String INITIAL_STATE = "product"; | 122 public static final String INITIAL_STATE = "product"; |
99 | 123 |
100 /** | 124 /** |
101 * The current State | 125 * The current State |
102 */ | 126 */ |
135 public GNVArtifactBase() { | 159 public GNVArtifactBase() { |
136 super(); | 160 super(); |
137 } | 161 } |
138 | 162 |
139 | 163 |
164 /** | |
165 * This method handles request for changing the current state of an | |
166 * artifact. It is possible to step forward, backward, or to the initial | |
167 * state for choosing a fis. | |
168 * | |
169 * @param target | |
170 * @param context | |
171 * @return | |
172 */ | |
140 @Override | 173 @Override |
141 public Document advance(Document target, CallContext context) { | 174 public Document advance(Document target, CallContext context) { |
142 log.debug("GNVArtifactBase.advance()"); | 175 log.debug("GNVArtifactBase.advance()"); |
143 | 176 |
144 Document result = XMLUtils.newDocument(); | 177 Document result = XMLUtils.newDocument(); |
266 | 299 |
267 return true; | 300 return true; |
268 } | 301 } |
269 | 302 |
270 | 303 |
304 /** | |
305 * | |
306 * @param document | |
307 * @param nodeName | |
308 * @param state | |
309 * @param msg | |
310 * @return | |
311 */ | |
271 protected Document createReport( | 312 protected Document createReport( |
272 Document document, | 313 Document document, |
273 String nodeName, | 314 String nodeName, |
274 String state, | 315 String state, |
275 String msg | 316 String msg |
290 return document; | 331 return document; |
291 | 332 |
292 } | 333 } |
293 | 334 |
294 | 335 |
336 /** | |
337 * Step back to the previous state specified by <code>name</code>. | |
338 * @param current | |
339 * @param name | |
340 * @return | |
341 */ | |
295 protected State getPreviousState(State current, String name) { | 342 protected State getPreviousState(State current, String name) { |
296 if (current == null) { | 343 if (current == null) { |
297 return null; | 344 return null; |
298 } | 345 } |
299 | 346 |
318 } | 365 } |
319 } | 366 } |
320 return false; | 367 return false; |
321 } | 368 } |
322 | 369 |
323 public Document initialize (CallContext context) { | 370 /** |
371 * | |
372 * @param context | |
373 * @return | |
374 */ | |
375 public Document initialize(CallContext context) { | |
324 Document result = XMLUtils.newDocument(); | 376 Document result = XMLUtils.newDocument(); |
325 try { | 377 try { |
326 this.current.initialize(super.identifier, context); | 378 this.current.initialize(super.identifier, context); |
327 | 379 |
328 if (this.current instanceof AutoResumeState){ | 380 if (this.current instanceof AutoResumeState){ |
356 .getLocalizedMessage(), XMLUtils.newDocument()); | 408 .getLocalizedMessage(), XMLUtils.newDocument()); |
357 } | 409 } |
358 return result; | 410 return result; |
359 } | 411 } |
360 | 412 |
413 /** | |
414 * Step forward to the next reachable state. | |
415 * @param current Current state. | |
416 * @return Reachable state. | |
417 */ | |
361 protected State getNextReachableState(State current){ | 418 protected State getNextReachableState(State current){ |
362 Iterator<Transition> it = this.transitions.iterator(); | 419 Iterator<Transition> it = this.transitions.iterator(); |
363 String from = current.getID(); | 420 String from = current.getID(); |
364 while (it.hasNext()){ | 421 while (it.hasNext()){ |
365 Transition transition = it.next(); | 422 Transition transition = it.next(); |
370 } | 427 } |
371 } | 428 } |
372 return null; | 429 return null; |
373 } | 430 } |
374 | 431 |
432 /** | |
433 * | |
434 * @param document | |
435 * @return | |
436 */ | |
375 protected String readStateName(Document document) { | 437 protected String readStateName(Document document) { |
376 String returnValue = XMLUtils.xpathString( | 438 String returnValue = XMLUtils.xpathString( |
377 document, XPATH_TARGET_NAME, ArtifactNamespaceContext.INSTANCE); | 439 document, XPATH_TARGET_NAME, ArtifactNamespaceContext.INSTANCE); |
378 return returnValue; | 440 return returnValue; |
379 } | 441 } |
380 | 442 |
443 /** | |
444 * | |
445 * @param document | |
446 * @return | |
447 */ | |
381 protected Node getConfigurationFragment(Document document) { | 448 protected Node getConfigurationFragment(Document document) { |
382 log.debug("GNVArtifactBase.getConfigurationFragment"); | 449 log.debug("GNVArtifactBase.getConfigurationFragment"); |
383 String xpathQuery = XPATH_ARTIFACT_CONFIGURATION.replaceAll( | 450 String xpathQuery = XPATH_ARTIFACT_CONFIGURATION.replaceAll( |
384 XPATH_IDENTIFIER_REPLACE, this.name); | 451 XPATH_IDENTIFIER_REPLACE, this.name); |
385 | 452 |
393 | 460 |
394 return configurationNode; | 461 return configurationNode; |
395 } | 462 } |
396 | 463 |
397 /** | 464 /** |
465 * Insert new data included in <code>target</code> into the current state. | |
466 * @param target XML document which contains data. | |
467 * @param context CallContext | |
468 * @return XML document with success or error message. | |
398 * @see de.intevation.artifactdatabase.DefaultArtifact#feed(org.w3c.dom.Document, | 469 * @see de.intevation.artifactdatabase.DefaultArtifact#feed(org.w3c.dom.Document, |
399 * de.intevation.artifacts.CallContext) | 470 * de.intevation.artifacts.CallContext) |
400 */ | 471 */ |
401 @Override | 472 @Override |
402 public Document feed(Document target, CallContext context) { | 473 public Document feed(Document target, CallContext context) { |
440 return result; | 511 return result; |
441 } | 512 } |
442 | 513 |
443 | 514 |
444 /** | 515 /** |
516 * Describe the current artifact. | |
517 * @param data | |
518 * @param context | |
519 * @return The description of the current artifact. | |
445 * @see de.intevation.artifactdatabase.DefaultArtifact#describe(org.w3c.dom.Document, de.intevation.artifacts.CallContext) | 520 * @see de.intevation.artifactdatabase.DefaultArtifact#describe(org.w3c.dom.Document, de.intevation.artifacts.CallContext) |
446 */ | 521 */ |
447 @Override | 522 @Override |
448 public Document describe(Document data, CallContext context) { | 523 public Document describe(Document data, CallContext context) { |
449 log.debug("GNVArtifactBase.describe"); | 524 log.debug("GNVArtifactBase.describe"); |
456 | 531 |
457 return document; | 532 return document; |
458 } | 533 } |
459 | 534 |
460 /** | 535 /** |
536 * Initialse this artifact and insert some data if <code>data</code> | |
537 * contains necessary information for this artifact. | |
538 * @param identifier | |
539 * @param context | |
540 * @param factory | |
541 * @param data | |
461 * @see de.intevation.artifactdatabase.DefaultArtifact#setup(java.lang.String, de.intevation.artifacts.ArtifactFactory, java.lang.Object, org.w3c.dom.Document) | 542 * @see de.intevation.artifactdatabase.DefaultArtifact#setup(java.lang.String, de.intevation.artifacts.ArtifactFactory, java.lang.Object, org.w3c.dom.Document) |
462 */ | 543 */ |
463 @Override | 544 @Override |
464 public void setup(String identifier, ArtifactFactory factory, | 545 public void setup(String identifier, ArtifactFactory factory, |
465 Object context,Document data) { | 546 Object context,Document data) { |
506 | 587 |
507 } | 588 } |
508 } | 589 } |
509 | 590 |
510 | 591 |
592 /** | |
593 * Create the xml document returned in {@link #describe(org.w3c.dom.Document, | |
594 * de.intevation.artifacts.CallContext)} | |
595 * | |
596 * @param context | |
597 * @param uuid | |
598 * @param incudeUI | |
599 * @return | |
600 */ | |
511 protected Document createDescibeOutput( | 601 protected Document createDescibeOutput( |
512 CallContext context, | 602 CallContext context, |
513 String uuid, | 603 String uuid, |
514 boolean incudeUI | 604 boolean incudeUI |
515 ) { | 605 ) { |
532 } | 622 } |
533 | 623 |
534 return document; | 624 return document; |
535 } | 625 } |
536 | 626 |
627 /** | |
628 * Determine the wish to append the user interface description to the | |
629 * describe document. | |
630 * | |
631 * @param document | |
632 * @return True, if the user interface description should be appended, | |
633 * otherwise false. | |
634 */ | |
537 protected boolean getIncludeUIFromDocument(Document document){ | 635 protected boolean getIncludeUIFromDocument(Document document){ |
538 String value = XMLUtils.xpathString( | 636 String value = XMLUtils.xpathString( |
539 document, XPATH_INCLUDE_UI, ArtifactNamespaceContext.INSTANCE); | 637 document, XPATH_INCLUDE_UI, ArtifactNamespaceContext.INSTANCE); |
540 | 638 |
541 boolean includeUI = false; | 639 boolean includeUI = false; |
543 includeUI = Boolean.parseBoolean(value); | 641 includeUI = Boolean.parseBoolean(value); |
544 } | 642 } |
545 return includeUI; | 643 return includeUI; |
546 } | 644 } |
547 | 645 |
646 /** | |
647 * | |
648 * @param creator | |
649 * @param document | |
650 * @return | |
651 */ | |
548 protected Element createRootNode( | 652 protected Element createRootNode( |
549 XMLUtils.ElementCreator creator, | 653 XMLUtils.ElementCreator creator, |
550 Document document | 654 Document document |
551 ) { | 655 ) { |
552 Element rootNode = creator.create("result"); | 656 Element rootNode = creator.create("result"); |
553 document.appendChild(rootNode); | 657 document.appendChild(rootNode); |
554 return rootNode; | 658 return rootNode; |
555 } | 659 } |
556 | 660 |
661 /** | |
662 * Append information about the current artifact (uuid, hash). | |
663 * | |
664 * @param creator | |
665 * @param parent | |
666 * @param document | |
667 * @param documentType | |
668 */ | |
557 protected void createHeader( | 669 protected void createHeader( |
558 XMLUtils.ElementCreator creator, | 670 XMLUtils.ElementCreator creator, |
559 Element parent, | 671 Element parent, |
560 Document document, | 672 Document document, |
561 String documentType | 673 String documentType |
571 Element hashNode = creator.create("hash"); | 683 Element hashNode = creator.create("hash"); |
572 creator.addAttr(hashNode, "value", this.hash()); | 684 creator.addAttr(hashNode, "value", this.hash()); |
573 parent.appendChild(hashNode); | 685 parent.appendChild(hashNode); |
574 } | 686 } |
575 | 687 |
688 /** | |
689 * Create the fis select box. | |
690 * | |
691 * @param artCreator | |
692 * @param creator | |
693 * @param document | |
694 * @param context | |
695 * @return | |
696 */ | |
576 protected Element createSelectBox( | 697 protected Element createSelectBox( |
577 XMLUtils.ElementCreator artCreator, | 698 XMLUtils.ElementCreator artCreator, |
578 XMLUtils.ElementCreator creator, | 699 XMLUtils.ElementCreator creator, |
579 Document document, | 700 Document document, |
580 CallContext context | 701 CallContext context |
617 | 738 |
618 return selectNode; | 739 return selectNode; |
619 } | 740 } |
620 | 741 |
621 | 742 |
743 /** | |
744 * Insert all reachable states into the describe document returned by | |
745 * {@link #describe(org.w3c.dom.Document, de.intevation.artifacts.CallContext)} | |
746 * | |
747 * @param creator | |
748 * @param parent | |
749 * @param document | |
750 */ | |
622 protected void createReachableStates( | 751 protected void createReachableStates( |
623 XMLUtils.ElementCreator creator, | 752 XMLUtils.ElementCreator creator, |
624 Element parent, | 753 Element parent, |
625 Document document | 754 Document document |
626 ) { | 755 ) { |
649 } | 778 } |
650 parent.appendChild(stateNode); | 779 parent.appendChild(stateNode); |
651 } | 780 } |
652 | 781 |
653 | 782 |
783 /** | |
784 * Insert states which have been visited by this artifact into the xml | |
785 * document returned by {@link #describe(org.w3c.dom.Document, | |
786 * de.intevation.artifacts.CallContext)} | |
787 * | |
788 * @param creator | |
789 * @param parent | |
790 * @param state | |
791 */ | |
654 protected void appendOldReachableStates( | 792 protected void appendOldReachableStates( |
655 XMLUtils.ElementCreator creator, | 793 XMLUtils.ElementCreator creator, |
656 Element parent, | 794 Element parent, |
657 State state | 795 State state |
658 ) { | 796 ) { |
668 state = state.getParent(); | 806 state = state.getParent(); |
669 } | 807 } |
670 } | 808 } |
671 | 809 |
672 | 810 |
811 /** | |
812 * Insert the current state into the xml document returned by | |
813 * {@link #describe(org.w3c.dom.Document, de.intevation.artifacts.CallContext)} | |
814 * @param creator | |
815 * @param parent | |
816 * @param document | |
817 */ | |
673 protected void createCurrentState( | 818 protected void createCurrentState( |
674 XMLUtils.ElementCreator creator, | 819 XMLUtils.ElementCreator creator, |
675 Element parent, | 820 Element parent, |
676 Document document | 821 Document document |
677 ) { | 822 ) { |
679 creator.addAttr(stateNode, "name", this.current.getID()); | 824 creator.addAttr(stateNode, "name", this.current.getID()); |
680 creator.addAttr(stateNode, "description", this.current.getDescription()); | 825 creator.addAttr(stateNode, "description", this.current.getDescription()); |
681 parent.appendChild(stateNode); | 826 parent.appendChild(stateNode); |
682 } | 827 } |
683 | 828 |
829 /** | |
830 * | |
831 * @param creator | |
832 * @param parent | |
833 * @param document | |
834 */ | |
684 protected void createModel( | 835 protected void createModel( |
685 XMLUtils.ElementCreator creator, | 836 XMLUtils.ElementCreator creator, |
686 Element parent, | 837 Element parent, |
687 Document document | 838 Document document |
688 ) { | 839 ) { |
702 } | 853 } |
703 } | 854 } |
704 parent.appendChild(modelNode); | 855 parent.appendChild(modelNode); |
705 } | 856 } |
706 | 857 |
858 /** | |
859 * Append the user interface description to the document returned by | |
860 * {@link #describe(org.w3c.dom.Document, de.intevation.artifacts.CallContext)} | |
861 * @param creator XML element creator. | |
862 * @param parent New elements are appended to this node. | |
863 * @param document Current document. | |
864 * @param context CallContext | |
865 * @param uuid The uuid of the artifact. | |
866 */ | |
707 protected void createUserInterface( | 867 protected void createUserInterface( |
708 XMLUtils.ElementCreator creator, | 868 XMLUtils.ElementCreator creator, |
709 Element parent, | 869 Element parent, |
710 Document document, | 870 Document document, |
711 CallContext context, | 871 CallContext context, |
740 ); | 900 ); |
741 } | 901 } |
742 } | 902 } |
743 | 903 |
744 | 904 |
905 /** | |
906 * Append possible output targets to the document returned by | |
907 * {@link #describe(org.w3c.dom.Document, de.intevation.artifacts.CallContext)} | |
908 * @param creator Used to create xml elements. | |
909 * @param parent New elements are appended to this node. | |
910 * @param document The current document. | |
911 */ | |
745 protected void createOutputs( | 912 protected void createOutputs( |
746 XMLUtils.ElementCreator creator, | 913 XMLUtils.ElementCreator creator, |
747 Element parent, | 914 Element parent, |
748 Document document | 915 Document document |
749 ) { | 916 ) { |
810 } | 977 } |
811 } | 978 } |
812 parent.appendChild(outputsNode); | 979 parent.appendChild(outputsNode); |
813 } | 980 } |
814 | 981 |
982 /** | |
983 * Parse input data from feed-document. | |
984 * @param document Feed-document | |
985 * @param xPath Path to input data. | |
986 * @return A collection with InputData objects. | |
987 */ | |
815 protected Collection<InputData> parseInputData(Document document, | 988 protected Collection<InputData> parseInputData(Document document, |
816 String xPath) { | 989 String xPath) { |
817 HashMap<String, InputData> returnValue = null; | 990 HashMap<String, InputData> returnValue = null; |
818 | 991 |
819 NodeList inputElemets = (NodeList) XMLUtils.xpath(document, xPath, | 992 NodeList inputElemets = (NodeList) XMLUtils.xpath(document, xPath, |
840 } | 1013 } |
841 return returnValue.values(); | 1014 return returnValue.values(); |
842 } | 1015 } |
843 | 1016 |
844 /** | 1017 /** |
1018 * Call an output target (e.g. chart, wms, etc.) | |
1019 * @param format XML document which contains some further information about | |
1020 * the desired output. | |
1021 * @param outputStream Stream used for writing the output. | |
1022 * @param context CallContext | |
1023 * @throws IOException If an error occured while writing the result to the | |
1024 * output stream. | |
845 * @see de.intevation.artifactdatabase.DefaultArtifact#out(org.w3c.dom.Document, | 1025 * @see de.intevation.artifactdatabase.DefaultArtifact#out(org.w3c.dom.Document, |
846 * java.io.OutputStream, de.intevation.artifacts.CallContext) | 1026 * java.io.OutputStream, de.intevation.artifacts.CallContext) |
847 */ | 1027 */ |
848 @Override | 1028 @Override |
849 public void out(Document format, OutputStream outputStream, | 1029 public void out(Document format, OutputStream outputStream, |
861 log.error(e, e); | 1041 log.error(e, e); |
862 throw new IOException(e.getMessage()); | 1042 throw new IOException(e.getMessage()); |
863 } | 1043 } |
864 } | 1044 } |
865 | 1045 |
1046 /** | |
1047 * | |
1048 * @param document | |
1049 * @return | |
1050 */ | |
866 protected static String readOutputType(Document document) { | 1051 protected static String readOutputType(Document document) { |
867 String value = XMLUtils.xpathString( | 1052 String value = XMLUtils.xpathString( |
868 document, XPATH_OUTPUT_NAME, ArtifactNamespaceContext.INSTANCE); | 1053 document, XPATH_OUTPUT_NAME, ArtifactNamespaceContext.INSTANCE); |
869 return value; | 1054 return value; |
870 } | 1055 } |
871 | 1056 |
872 | 1057 |
1058 /** | |
1059 * The the current product. | |
1060 * @param product New product. | |
1061 */ | |
873 public void setProduct(Product product) { | 1062 public void setProduct(Product product) { |
874 this.product = product; | 1063 this.product = product; |
875 } | 1064 } |
876 | 1065 |
1066 /** | |
1067 * Call endOfLife of parent class and the current state. | |
1068 * @param globalContext | |
1069 */ | |
1070 @Override | |
877 public void endOfLife(Object globalContext) { | 1071 public void endOfLife(Object globalContext) { |
878 super.endOfLife(globalContext); | 1072 super.endOfLife(globalContext); |
879 | 1073 |
880 if (current != null) { | 1074 if (current != null) { |
881 current.endOfLife(globalContext); | 1075 current.endOfLife(globalContext); |
882 } | 1076 } |
883 } | 1077 } |
884 | 1078 |
885 /** | 1079 /** |
1080 * Retrieves a map with given InputData which have been inserted into the | |
1081 * current artifact before the parameterization began. | |
1082 * @return | |
886 * @see de.intevation.gnv.artifacts.PreSettingArtifact#getPreSettings() | 1083 * @see de.intevation.gnv.artifacts.PreSettingArtifact#getPreSettings() |
887 */ | 1084 */ |
888 public Map<String, InputData> getPreSettings() { | 1085 public Map<String, InputData> getPreSettings() { |
889 return this.preSettings; | 1086 return this.preSettings; |
890 } | 1087 } |
891 | 1088 |
892 /** | 1089 /** |
1090 * Set InputData which are used in later states. | |
1091 * @param preSettings | |
893 * @see de.intevation.gnv.artifacts.PreSettingArtifact#setPreSettings(java.util.Map) | 1092 * @see de.intevation.gnv.artifacts.PreSettingArtifact#setPreSettings(java.util.Map) |
894 */ | 1093 */ |
895 public void setPreSettings(Map<String, InputData> preSettings) { | 1094 public void setPreSettings(Map<String, InputData> preSettings) { |
896 this.preSettings = preSettings; | 1095 this.preSettings = preSettings; |
897 if (this.current != null){ | 1096 if (this.current != null){ |
898 this.current.setPreSettings(preSettings); | 1097 this.current.setPreSettings(preSettings); |
899 } | 1098 } |
900 } | 1099 } |
901 } | 1100 } |
902 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8: | 1101 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |