annotate flys-artifacts/src/main/java/de/intevation/flys/artifacts/transitions/ValueCompareTransition.java @ 2416:5144369d5961

Partial Fix flys/issue500: text-orientation for texts. flys-artifacts/trunk@4048 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Tue, 14 Feb 2012 09:00:50 +0000
parents 22e9574c8b1b
children eb5564662e19
rev   line source
356
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
1 package de.intevation.flys.artifacts.transitions;
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
2
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
3 import javax.xml.xpath.XPathConstants;
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
4
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
5 import org.apache.log4j.Logger;
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
6
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
7 import org.w3c.dom.Node;
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
8
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
9 import de.intevation.artifacts.Artifact;
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
10
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
11 import de.intevation.artifactdatabase.data.StateData;
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
12 import de.intevation.artifactdatabase.state.State;
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
13
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
14 import de.intevation.artifacts.common.utils.XMLUtils;
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
15
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
16 import de.intevation.flys.artifacts.FLYSArtifact;
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
17
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
18
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
19 /**
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
20 * This transition compares data objects with a <i>equal</i> or <i>notequal</i>
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
21 * operator.
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
22 *
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
23 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
24 */
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
25 public class ValueCompareTransition extends DefaultTransition {
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
26
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
27 /** The logger that is used in this transition.*/
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
28 private static Logger log = Logger.getLogger(ValueCompareTransition.class);
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
29
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
30
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
31 /** XPath that points to the condition's operator.*/
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
32 public static final String XPATH_OPERATOR = "condition/@operator";
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
33
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
34 /** XPath that points to the condition's value.*/
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
35 public static final String XPATH_VALUE = "condition/@value";
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
36
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
37 /** XPath that points to the condition's dataname.*/
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
38 public static final String XPATH_DATANAME = "condition/@data";
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
39
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
40 /** The value of the 'equal' operator.*/
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
41 public static final String OPERATOR_EQUAL = "equal";
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
42
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
43 /** The value of the 'not equal' operator.*/
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
44 public static final String OPERATOR_NOTEQUAL = "notequal";
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
45
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
46
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
47 /** The operator.*/
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
48 protected String operator;
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
49
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
50 /** The value used for comparison.*/
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
51 protected String value;
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
52
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
53 /** The name of the data used for the comparison.*/
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
54 protected String dataname;
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
55
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
56
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
57
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
58 public ValueCompareTransition() {
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
59 }
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
60
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
61
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
62 public ValueCompareTransition(String from, String to) {
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
63 super(from, to);
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
64 }
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
65
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
66
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
67 @Override
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
68 public void init(Node config) {
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
69 log.debug("ValueCompareTransition.init");
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
70
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
71 String tmp = (String) XMLUtils.xpath(
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
72 config,
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
73 XPATH_OPERATOR,
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
74 XPathConstants.STRING);
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
75 operator = tmp.trim().toLowerCase();
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
76
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
77 value = (String) XMLUtils.xpath(
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
78 config,
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
79 XPATH_VALUE,
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
80 XPathConstants.STRING);
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
81
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
82 dataname = (String) XMLUtils.xpath(
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
83 config,
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
84 XPATH_DATANAME,
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
85 XPathConstants.STRING);
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
86 }
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
87
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
88
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
89 @Override
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
90 public boolean isValid(Artifact artifact, State a, State b) {
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
91 log.debug("ValueCompareTransition.isValid");
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
92
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
93 FLYSArtifact flysArtifact = (FLYSArtifact) artifact;
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
94
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
95 StateData dataObj = flysArtifact.getData(dataname);
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
96 String dataVal = dataObj != null ? (String) dataObj.getValue() : "";
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
97
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
98 if (log.isDebugEnabled()) {
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
99 log.debug("Compare settings:");
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
100 log.debug("-- dataname: " + dataname);
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
101 log.debug("-- operator: " + operator);
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
102 log.debug("-- compare value: " + value);
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
103 log.debug("-- state value: " + dataVal);
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
104 }
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
105
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
106 if (operator.equals(OPERATOR_EQUAL)) {
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
107 return value.equals(dataVal);
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
108 }
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
109 else if (operator.equals(OPERATOR_NOTEQUAL)) {
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
110 return !(value.equals(dataVal));
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
111 }
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
112
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
113 log.error("Wrong operator set! No comparison takes place.");
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
114
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
115 return false;
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
116 }
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
117 }
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
118 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org