comparison gnv-artifacts/src/main/java/de/intevation/gnv/transition/ValueCompareTransition.java @ 875:5e9efdda6894

merged gnv-artifacts/1.0
author Thomas Arendsen Hein <thomas@intevation.de>
date Fri, 28 Sep 2012 12:13:56 +0200
parents 05bf8534a35a
children f953c9a559d8
comparison
equal deleted inserted replaced
722:bb3ffe7d719e 875:5e9efdda6894
1 package de.intevation.gnv.transition;
2
3 import java.util.Iterator;
4
5 import org.apache.log4j.Logger;
6 import org.w3c.dom.Node;
7
8 import de.intevation.artifactdatabase.Config;
9 import de.intevation.gnv.state.InputData;
10 import de.intevation.gnv.state.State;
11 import de.intevation.gnv.state.exception.StateException;
12
13 /**
14 * Class which supports the possibility to validate if a
15 * Transition could be done using simple Valuecompare Operations.
16 * At this Time equal and notequal-operations are supported.
17 * The Comparation is casesensitive.
18 * @author <a href="mailto:tim.englich@intevation.de">Tim Englich</a>
19 *
20 */
21 public class ValueCompareTransition extends TransitionBase {
22
23 /**
24 * the logger, used to log exceptions and additonaly information
25 */
26 private static Logger log = Logger.getLogger(ValueCompareTransition.class);
27 /**
28 * The UID of this Class.
29 */
30 private static final long serialVersionUID = -7846722158776823205L;
31
32 /**
33 * The Name of the Datafield the Value that should be compared
34 * should be fetched from.
35 */
36 private String dataName = null;
37 /**
38 * The Value that should be set to the State.
39 */
40 private String dataValue = null;
41 /**
42 * The Operation that should be used (equal notequal)
43 */
44 private String operator = null;
45
46
47 /**
48 * Constructor
49 */
50 public ValueCompareTransition() {
51 super();
52 }
53
54 /**
55 * validates if a Transition is valid and could be used using simple
56 * Comparevalue-Operations.
57 * @see de.intevation.gnv.transition.Transition#isValid(de.intevation.gnv.state.State)
58 */
59 public boolean isValid(State state) {
60
61 try {
62 Iterator<InputData> it = state.getInputData().iterator();
63 while (it.hasNext()){
64 InputData inputData = it.next();
65 if (inputData.getName().equals(this.dataName)){
66 boolean returnValue = false;
67 if (operator.equals("equal")){
68 returnValue = this.dataValue.equals(inputData.getValue());
69 }else if (operator.equals("notequal")){
70 returnValue = !this.dataValue.equals(inputData.getValue());
71 }
72 return returnValue;
73 }
74 }
75 if (operator.equals("notequal")){
76 // data is not given. So the constraint not Equals is fullfilled.
77 return true;
78 }
79 } catch (StateException e) {
80 log.error(e,e);
81 return false;
82 }
83 return false;
84 }
85
86
87 @Override
88 public void setup(Node configuration) {
89 super.setup(configuration);
90 this.dataName = Config.getStringXPath(configuration,"condition/@inputvalue");
91 this.dataValue = Config.getStringXPath(configuration,"condition/@value");
92 this.operator = Config.getStringXPath(configuration,"condition/@operator");
93 }
94 }
95 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org