annotate flys-artifacts/src/main/java/de/intevation/flys/artifacts/transitions/ValueCompareTransition.java @ 4491:302f5da348bb

Fixed problem with mapserver fonts
author Sascha L. Teichmann <teichmann@intevation.de>
date Wed, 14 Nov 2012 10:51:21 +0100
parents eb5564662e19
children
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
4043
eb5564662e19 Cosmetics, documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 356
diff changeset
67 /** Setup member values from the document. */
356
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
68 @Override
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
69 public void init(Node config) {
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
70 log.debug("ValueCompareTransition.init");
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
71
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
72 String tmp = (String) XMLUtils.xpath(
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
73 config,
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
74 XPATH_OPERATOR,
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
75 XPathConstants.STRING);
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
76 operator = tmp.trim().toLowerCase();
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
77
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
78 value = (String) XMLUtils.xpath(
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
79 config,
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
80 XPATH_VALUE,
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
81 XPathConstants.STRING);
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
82
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
83 dataname = (String) XMLUtils.xpath(
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
84 config,
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
85 XPATH_DATANAME,
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
86 XPathConstants.STRING);
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
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
90 @Override
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
91 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
92 log.debug("ValueCompareTransition.isValid");
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
93
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
94 FLYSArtifact flysArtifact = (FLYSArtifact) artifact;
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
95
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
96 StateData dataObj = flysArtifact.getData(dataname);
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
97 String dataVal = dataObj != null ? (String) dataObj.getValue() : "";
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
98
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
99 if (log.isDebugEnabled()) {
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
100 log.debug("Compare settings:");
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
101 log.debug("-- dataname: " + dataname);
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
102 log.debug("-- operator: " + operator);
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
103 log.debug("-- compare value: " + value);
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
104 log.debug("-- state value: " + dataVal);
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
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
107 if (operator.equals(OPERATOR_EQUAL)) {
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
108 return value.equals(dataVal);
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
109 }
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
110 else if (operator.equals(OPERATOR_NOTEQUAL)) {
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
111 return !(value.equals(dataVal));
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
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
114 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
115
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
116 return false;
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 }
22e9574c8b1b Added a new Transition to compare values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
119 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org