Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/transitions/ValueCompareTransition.java @ 5838:5aa05a7a34b7
Rename modules to more fitting names.
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Thu, 25 Apr 2013 15:23:37 +0200 |
parents | flys-artifacts/src/main/java/org/dive4elements/river/artifacts/transitions/ValueCompareTransition.java@bd047b71ab37 |
children | 4897a58c8746 |
comparison
equal
deleted
inserted
replaced
5837:d9901a08d0a6 | 5838:5aa05a7a34b7 |
---|---|
1 package org.dive4elements.river.artifacts.transitions; | |
2 | |
3 import javax.xml.xpath.XPathConstants; | |
4 | |
5 import org.apache.log4j.Logger; | |
6 | |
7 import org.w3c.dom.Node; | |
8 | |
9 import org.dive4elements.artifacts.Artifact; | |
10 | |
11 import org.dive4elements.artifactdatabase.data.StateData; | |
12 import org.dive4elements.artifactdatabase.state.State; | |
13 | |
14 import org.dive4elements.artifacts.common.utils.XMLUtils; | |
15 | |
16 import org.dive4elements.river.artifacts.FLYSArtifact; | |
17 | |
18 | |
19 /** | |
20 * This transition compares data objects with a <i>equal</i> or <i>notequal</i> | |
21 * operator. | |
22 * | |
23 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> | |
24 */ | |
25 public class ValueCompareTransition extends DefaultTransition { | |
26 | |
27 /** The logger that is used in this transition.*/ | |
28 private static Logger log = Logger.getLogger(ValueCompareTransition.class); | |
29 | |
30 | |
31 /** XPath that points to the condition's operator.*/ | |
32 public static final String XPATH_OPERATOR = "condition/@operator"; | |
33 | |
34 /** XPath that points to the condition's value.*/ | |
35 public static final String XPATH_VALUE = "condition/@value"; | |
36 | |
37 /** XPath that points to the condition's dataname.*/ | |
38 public static final String XPATH_DATANAME = "condition/@data"; | |
39 | |
40 /** The value of the 'equal' operator.*/ | |
41 public static final String OPERATOR_EQUAL = "equal"; | |
42 | |
43 /** The value of the 'not equal' operator.*/ | |
44 public static final String OPERATOR_NOTEQUAL = "notequal"; | |
45 | |
46 | |
47 /** The operator.*/ | |
48 protected String operator; | |
49 | |
50 /** The value used for comparison.*/ | |
51 protected String value; | |
52 | |
53 /** The name of the data used for the comparison.*/ | |
54 protected String dataname; | |
55 | |
56 | |
57 | |
58 public ValueCompareTransition() { | |
59 } | |
60 | |
61 | |
62 public ValueCompareTransition(String from, String to) { | |
63 super(from, to); | |
64 } | |
65 | |
66 | |
67 /** Setup member values from the document. */ | |
68 @Override | |
69 public void init(Node config) { | |
70 log.debug("ValueCompareTransition.init"); | |
71 | |
72 String tmp = (String) XMLUtils.xpath( | |
73 config, | |
74 XPATH_OPERATOR, | |
75 XPathConstants.STRING); | |
76 operator = tmp.trim().toLowerCase(); | |
77 | |
78 value = (String) XMLUtils.xpath( | |
79 config, | |
80 XPATH_VALUE, | |
81 XPathConstants.STRING); | |
82 | |
83 dataname = (String) XMLUtils.xpath( | |
84 config, | |
85 XPATH_DATANAME, | |
86 XPathConstants.STRING); | |
87 } | |
88 | |
89 | |
90 @Override | |
91 public boolean isValid(Artifact artifact, State a, State b) { | |
92 log.debug("ValueCompareTransition.isValid"); | |
93 | |
94 FLYSArtifact flysArtifact = (FLYSArtifact) artifact; | |
95 | |
96 StateData dataObj = flysArtifact.getData(dataname); | |
97 String dataVal = dataObj != null ? (String) dataObj.getValue() : ""; | |
98 | |
99 if (log.isDebugEnabled()) { | |
100 log.debug("Compare settings:"); | |
101 log.debug("-- dataname: " + dataname); | |
102 log.debug("-- operator: " + operator); | |
103 log.debug("-- compare value: " + value); | |
104 log.debug("-- state value: " + dataVal); | |
105 } | |
106 | |
107 if (operator.equals(OPERATOR_EQUAL)) { | |
108 return value.equals(dataVal); | |
109 } | |
110 else if (operator.equals(OPERATOR_NOTEQUAL)) { | |
111 return !(value.equals(dataVal)); | |
112 } | |
113 | |
114 log.error("Wrong operator set! No comparison takes place."); | |
115 | |
116 return false; | |
117 } | |
118 } | |
119 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |