Mercurial > dive4elements > gnv-client
comparison gnv-artifacts/src/main/java/de/intevation/gnv/transition/ValueCompareTransition.java @ 657:af3f56758f59
merged gnv-artifacts/0.5
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Fri, 28 Sep 2012 12:13:53 +0200 |
parents | a887074460b6 |
children | 9a828e5a2390 |
comparison
equal
deleted
inserted
replaced
590:5f5f273c8566 | 657:af3f56758f59 |
---|---|
1 /** | |
2 * | |
3 */ | |
4 package de.intevation.gnv.transition; | |
5 | |
6 import java.util.Iterator; | |
7 | |
8 import org.apache.log4j.Logger; | |
9 import org.w3c.dom.Node; | |
10 | |
11 import de.intevation.artifactdatabase.Config; | |
12 import de.intevation.gnv.state.InputData; | |
13 import de.intevation.gnv.state.State; | |
14 import de.intevation.gnv.state.exception.StateException; | |
15 | |
16 /** | |
17 * @author Tim Englich <tim.englich@intevation.de> | |
18 * | |
19 */ | |
20 public class ValueCompareTransition extends TransitionBase { | |
21 | |
22 /** | |
23 * the logger, used to log exceptions and additonaly information | |
24 */ | |
25 private static Logger log = Logger.getLogger(ValueCompareTransition.class); | |
26 | |
27 private String dataName = null; | |
28 private String dataValue = null; | |
29 private String operator = null; | |
30 | |
31 /** | |
32 * The UID of this Class. | |
33 */ | |
34 private static final long serialVersionUID = -7846722158776823205L; | |
35 | |
36 /** | |
37 * Constructor | |
38 */ | |
39 public ValueCompareTransition() { | |
40 super(); | |
41 } | |
42 | |
43 /** | |
44 * @see de.intevation.gnv.transition.Transition#isValid(de.intevation.gnv.state.State) | |
45 */ | |
46 public boolean isValid(State state) { | |
47 | |
48 try { | |
49 Iterator<InputData> it = state.getInputData().iterator(); | |
50 while (it.hasNext()){ | |
51 InputData inputData = it.next(); | |
52 if (inputData.getName().equals(this.dataName)){ | |
53 boolean returnValue = false; | |
54 if (operator.equals("equal")){ | |
55 returnValue = this.dataValue.equals(inputData.getValue()); | |
56 }else if (operator.equals("notequal")){ | |
57 returnValue = !this.dataValue.equals(inputData.getValue()); | |
58 } | |
59 return returnValue; | |
60 } | |
61 } | |
62 if (operator.equals("notequal")){ | |
63 // data is not given. So the constraint not Equals is fullfilled. | |
64 return true; | |
65 } | |
66 } catch (StateException e) { | |
67 log.error(e,e); | |
68 return false; | |
69 } | |
70 return false; | |
71 } | |
72 | |
73 @Override | |
74 public void setup(Node configuration) { | |
75 super.setup(configuration); | |
76 this.dataName = Config.getStringXPath(configuration,"condition/@inputvalue"); | |
77 this.dataValue = Config.getStringXPath(configuration,"condition/@value"); | |
78 this.operator = Config.getStringXPath(configuration,"condition/@operator"); | |
79 } | |
80 | |
81 | |
82 } |