comparison gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/GNVArtifactBase.java @ 88:1b12021905b9

Some CodeCleanup done. ExceptionDocument will now be returned gnv-artifacts/trunk@125 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Tim Englich <tim.englich@intevation.de>
date Thu, 24 Sep 2009 10:45:24 +0000
parents 969faa37a11b
children cde042a0a395
comparison
equal deleted inserted replaced
87:ce398a7a99fc 88:1b12021905b9
90 * @see de.intevation.artifactdatabase.DefaultArtifact#advance(org.w3c.dom.Document, de.intevation.artifacts.CallContext) 90 * @see de.intevation.artifactdatabase.DefaultArtifact#advance(org.w3c.dom.Document, de.intevation.artifacts.CallContext)
91 */ 91 */
92 @Override 92 @Override
93 public Document advance(Document target, CallContext context) { 93 public Document advance(Document target, CallContext context) {
94 Document result = XMLUtils.newDocument(); 94 Document result = XMLUtils.newDocument();
95 if (this.current != null){ 95 try {
96 String transitionName = this.readTransitionName(target); 96 if (this.current != null){
97 if (this.current.isTransitionReachable(transitionName)){ 97 String transitionName = this.readTransitionName(target);
98 // 1. Prüfung ob Transition valide ist 98 if (this.current.isTransitionReachable(transitionName)){
99 if (this.current.validate()){ 99 // 1. Prüfung ob Transition valide ist
100 100 if (this.current.validate()){
101 try { 101
102 Transition nextStep = this.transitions.get(transitionName); 102 try {
103 // 2.Ergebnisse Berechnen 103 Transition nextStep = this.transitions.get(transitionName);
104 this.current.advance(); 104 // 2.Ergebnisse Berechnen
105 // 3. Ergebnisse übergeben 105 this.current.advance();
106 nextStep.setDescibeData(this.current.getDescibeData()); 106 // 3. Ergebnisse übergeben
107 nextStep.putInputData(this.current.getInputData()); 107 nextStep.setDescibeData(this.current.getDescibeData());
108 // 4. Umschalten auf neue Transistion 108 nextStep.putInputData(this.current.getInputData());
109 this.current = nextStep; 109 // 4. Umschalten auf neue Transistion
110 } catch (TransitionException e) { 110 this.current = nextStep;
111 log.error(e,e); 111 } catch (TransitionException e) {
112 // TODO: Errormmessage senden. 112 log.error(e,e);
113 result = new ArtifactXMLUtilities().createExceptionReport(e.getLocalizedMessage(), XMLUtils.newDocument());
114 }
115
116 }else{
117 String msg = "Advance nicht möglich, da die Bedingungen für den Übergang " +
118 "in den neuen Zustand noch nicht gegeben ist.";
119 log.error(msg);
120 result = new ArtifactXMLUtilities().createExceptionReport(msg, XMLUtils.newDocument());
113 } 121 }
114 122
115 }else{ 123 }else{
116 log.error("Advance nicht möglich, da die Bedingungen für den Übergang " + 124 String msg = "Transitionsübergang wird nicht unterstützt.";
117 "in den neuen Zustand noch nicht gegeben ist."); 125 log.error(msg);
118 // TODO: Errormmessage senden. 126 result = new ArtifactXMLUtilities().createExceptionReport(msg, XMLUtils.newDocument());
119 } 127 }
120
121 }else{ 128 }else{
122 log.error("Transitionsübergang wird nicht unterstützt."); 129 String msg = "Kein Transitionsschritt aktiviert.";
123 // TODO: Errormmessage senden. 130 log.error(msg);
124 } 131 result = new ArtifactXMLUtilities().createExceptionReport(msg, XMLUtils.newDocument());
125 }else{ 132 }
126 log.error("Kein Transitionsschritt aktiviert."); 133 } catch (Exception e) {
127 // TODO: Errormmessage senden. 134 log.error(e,e);
135 result = new ArtifactXMLUtilities().createExceptionReport(e.getLocalizedMessage(), XMLUtils.newDocument());
128 } 136 }
129 return result; 137 return result;
130 } 138 }
131 139
132 protected String readTransitionName(Document document) { 140 protected String readTransitionName(Document document) {
152 this.current.putInputData(this.parseInputData(target)); 160 this.current.putInputData(this.parseInputData(target));
153 // TODO Ergebnisdokument erzeugen. 161 // TODO Ergebnisdokument erzeugen.
154 } 162 }
155 } catch (TransitionException e) { 163 } catch (TransitionException e) {
156 log.error(e,e); 164 log.error(e,e);
157 //TODO: Fehlerdokumenterzeugen. 165 return new ArtifactXMLUtilities().createExceptionReport(e.getLocalizedMessage(), XMLUtils.newDocument());
158 } 166 }
159 return result; 167 return result;
160 } 168 }
161 169
162 /** 170 /**
194 202
195 203
196 protected Document createDescibeOutput(){ 204 protected Document createDescibeOutput(){
197 log.debug("GNVArtifactBase.createDescibeOutput"); 205 log.debug("GNVArtifactBase.createDescibeOutput");
198 Document document = XMLUtils.newDocument(); 206 Document document = XMLUtils.newDocument();
199 Element rootNode = this.createRootNode(document); 207 Element rootNode = this.createRootNode(document);
200 this.createHeader(rootNode, document, "describe"); 208 this.createHeader(rootNode, document, "describe");
201 this.createOutputs(rootNode, document); 209 this.createOutputs(rootNode, document);
202 this.createCurrentState(rootNode, document); 210 this.createCurrentState(rootNode, document);
203 this.createReachableStates(rootNode, document); 211 this.createReachableStates(rootNode, document);
204 this.createModel(rootNode, document); 212 this.createModel(rootNode, document);
205 this.createUserInterface(rootNode, document); 213 this.createUserInterface(rootNode, document);
206
207 return document; 214 return document;
208 } 215 }
209 216
210 protected Element createRootNode(Document document){ 217 protected Element createRootNode(Document document){
211 Element rootNode = xmlUtilities.createArtifactElement(document,"result"); 218 Element rootNode = xmlUtilities.createArtifactElement(document,"result");
234 Iterator<String> states = this.current.reachableTransitions().iterator(); 241 Iterator<String> states = this.current.reachableTransitions().iterator();
235 while(states.hasNext()){ 242 while(states.hasNext()){
236 String value = states.next(); 243 String value = states.next();
237 Element currentNode = xmlUtilities.createArtifactElement(document,"state"); 244 Element currentNode = xmlUtilities.createArtifactElement(document,"state");
238 currentNode.setAttribute("name", value); 245 currentNode.setAttribute("name", value);
246 log.debug("Reachable State: "+value);
239 currentNode.setAttribute("description", transitions.get(value).getDescription()); 247 currentNode.setAttribute("description", transitions.get(value).getDescription());
240 stateNode.appendChild(currentNode); 248 stateNode.appendChild(currentNode);
241 } 249 }
242 } 250 }
243 parent.appendChild(stateNode); 251 parent.appendChild(stateNode);

http://dive4elements.wald.intevation.org