Mercurial > dive4elements > gnv-client
annotate gnv-artifacts/src/main/java/de/intevation/gnv/transition/ValueCompareTransition.java @ 1064:026b936290bc
Removed needless imports.
gnv-artifacts/trunk@1151 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Thu, 03 Jun 2010 16:12:35 +0000 |
parents | 05bf8534a35a |
children | f953c9a559d8 |
rev | line source |
---|---|
337
a887074460b6
Last Step of the Refactoring Work on the Transition Model.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
1 package de.intevation.gnv.transition; |
a887074460b6
Last Step of the Refactoring Work on the Transition Model.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
2 |
a887074460b6
Last Step of the Refactoring Work on the Transition Model.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
3 import java.util.Iterator; |
a887074460b6
Last Step of the Refactoring Work on the Transition Model.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
4 |
a887074460b6
Last Step of the Refactoring Work on the Transition Model.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
5 import org.apache.log4j.Logger; |
779
b1f5f2a8840f
Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
6 import org.w3c.dom.Node; |
337
a887074460b6
Last Step of the Refactoring Work on the Transition Model.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
7 |
824
7e5995c47125
Added more Javadoc.
Tim Englich <tim.englich@intevation.de>
parents:
813
diff
changeset
|
8 import de.intevation.artifactdatabase.Config; |
7e5995c47125
Added more Javadoc.
Tim Englich <tim.englich@intevation.de>
parents:
813
diff
changeset
|
9 import de.intevation.gnv.state.InputData; |
7e5995c47125
Added more Javadoc.
Tim Englich <tim.englich@intevation.de>
parents:
813
diff
changeset
|
10 import de.intevation.gnv.state.State; |
7e5995c47125
Added more Javadoc.
Tim Englich <tim.englich@intevation.de>
parents:
813
diff
changeset
|
11 import de.intevation.gnv.state.exception.StateException; |
7e5995c47125
Added more Javadoc.
Tim Englich <tim.englich@intevation.de>
parents:
813
diff
changeset
|
12 |
337
a887074460b6
Last Step of the Refactoring Work on the Transition Model.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
13 /** |
824
7e5995c47125
Added more Javadoc.
Tim Englich <tim.englich@intevation.de>
parents:
813
diff
changeset
|
14 * Class which supports the possibility to validate if a |
7e5995c47125
Added more Javadoc.
Tim Englich <tim.englich@intevation.de>
parents:
813
diff
changeset
|
15 * Transition could be done using simple Valuecompare Operations. |
7e5995c47125
Added more Javadoc.
Tim Englich <tim.englich@intevation.de>
parents:
813
diff
changeset
|
16 * At this Time equal and notequal-operations are supported. |
7e5995c47125
Added more Javadoc.
Tim Englich <tim.englich@intevation.de>
parents:
813
diff
changeset
|
17 * The Comparation is casesensitive. |
780
c4156275c1e1
Bring @author javadoc tags in form '@author <a href="john.doe@example.com">John Doe</a>'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
779
diff
changeset
|
18 * @author <a href="mailto:tim.englich@intevation.de">Tim Englich</a> |
337
a887074460b6
Last Step of the Refactoring Work on the Transition Model.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
19 * |
a887074460b6
Last Step of the Refactoring Work on the Transition Model.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
20 */ |
a887074460b6
Last Step of the Refactoring Work on the Transition Model.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
21 public class ValueCompareTransition extends TransitionBase { |
a887074460b6
Last Step of the Refactoring Work on the Transition Model.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
22 |
a887074460b6
Last Step of the Refactoring Work on the Transition Model.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
23 /** |
a887074460b6
Last Step of the Refactoring Work on the Transition Model.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
24 * the logger, used to log exceptions and additonaly information |
a887074460b6
Last Step of the Refactoring Work on the Transition Model.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
25 */ |
a887074460b6
Last Step of the Refactoring Work on the Transition Model.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
26 private static Logger log = Logger.getLogger(ValueCompareTransition.class); |
a887074460b6
Last Step of the Refactoring Work on the Transition Model.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
27 /** |
a887074460b6
Last Step of the Refactoring Work on the Transition Model.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
28 * The UID of this Class. |
a887074460b6
Last Step of the Refactoring Work on the Transition Model.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
29 */ |
a887074460b6
Last Step of the Refactoring Work on the Transition Model.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
30 private static final long serialVersionUID = -7846722158776823205L; |
a887074460b6
Last Step of the Refactoring Work on the Transition Model.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
31 |
a887074460b6
Last Step of the Refactoring Work on the Transition Model.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
32 /** |
835
2423cefe7d39
Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
824
diff
changeset
|
33 * The Name of the Datafield the Value that should be compared |
824
7e5995c47125
Added more Javadoc.
Tim Englich <tim.englich@intevation.de>
parents:
813
diff
changeset
|
34 * should be fetched from. |
7e5995c47125
Added more Javadoc.
Tim Englich <tim.englich@intevation.de>
parents:
813
diff
changeset
|
35 */ |
7e5995c47125
Added more Javadoc.
Tim Englich <tim.englich@intevation.de>
parents:
813
diff
changeset
|
36 private String dataName = null; |
7e5995c47125
Added more Javadoc.
Tim Englich <tim.englich@intevation.de>
parents:
813
diff
changeset
|
37 /** |
7e5995c47125
Added more Javadoc.
Tim Englich <tim.englich@intevation.de>
parents:
813
diff
changeset
|
38 * The Value that should be set to the State. |
7e5995c47125
Added more Javadoc.
Tim Englich <tim.englich@intevation.de>
parents:
813
diff
changeset
|
39 */ |
7e5995c47125
Added more Javadoc.
Tim Englich <tim.englich@intevation.de>
parents:
813
diff
changeset
|
40 private String dataValue = null; |
7e5995c47125
Added more Javadoc.
Tim Englich <tim.englich@intevation.de>
parents:
813
diff
changeset
|
41 /** |
7e5995c47125
Added more Javadoc.
Tim Englich <tim.englich@intevation.de>
parents:
813
diff
changeset
|
42 * The Operation that should be used (equal notequal) |
7e5995c47125
Added more Javadoc.
Tim Englich <tim.englich@intevation.de>
parents:
813
diff
changeset
|
43 */ |
7e5995c47125
Added more Javadoc.
Tim Englich <tim.englich@intevation.de>
parents:
813
diff
changeset
|
44 private String operator = null; |
7e5995c47125
Added more Javadoc.
Tim Englich <tim.englich@intevation.de>
parents:
813
diff
changeset
|
45 |
7e5995c47125
Added more Javadoc.
Tim Englich <tim.englich@intevation.de>
parents:
813
diff
changeset
|
46 |
7e5995c47125
Added more Javadoc.
Tim Englich <tim.englich@intevation.de>
parents:
813
diff
changeset
|
47 /** |
337
a887074460b6
Last Step of the Refactoring Work on the Transition Model.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
48 * Constructor |
a887074460b6
Last Step of the Refactoring Work on the Transition Model.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
49 */ |
a887074460b6
Last Step of the Refactoring Work on the Transition Model.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
50 public ValueCompareTransition() { |
a887074460b6
Last Step of the Refactoring Work on the Transition Model.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
51 super(); |
a887074460b6
Last Step of the Refactoring Work on the Transition Model.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
52 } |
a887074460b6
Last Step of the Refactoring Work on the Transition Model.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
53 |
824
7e5995c47125
Added more Javadoc.
Tim Englich <tim.englich@intevation.de>
parents:
813
diff
changeset
|
54 /** |
7e5995c47125
Added more Javadoc.
Tim Englich <tim.englich@intevation.de>
parents:
813
diff
changeset
|
55 * validates if a Transition is valid and could be used using simple |
7e5995c47125
Added more Javadoc.
Tim Englich <tim.englich@intevation.de>
parents:
813
diff
changeset
|
56 * Comparevalue-Operations. |
7e5995c47125
Added more Javadoc.
Tim Englich <tim.englich@intevation.de>
parents:
813
diff
changeset
|
57 * @see de.intevation.gnv.transition.Transition#isValid(de.intevation.gnv.state.State) |
7e5995c47125
Added more Javadoc.
Tim Englich <tim.englich@intevation.de>
parents:
813
diff
changeset
|
58 */ |
337
a887074460b6
Last Step of the Refactoring Work on the Transition Model.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
59 public boolean isValid(State state) { |
778
9a828e5a2390
Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
337
diff
changeset
|
60 |
337
a887074460b6
Last Step of the Refactoring Work on the Transition Model.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
61 try { |
a887074460b6
Last Step of the Refactoring Work on the Transition Model.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
62 Iterator<InputData> it = state.getInputData().iterator(); |
a887074460b6
Last Step of the Refactoring Work on the Transition Model.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
63 while (it.hasNext()){ |
a887074460b6
Last Step of the Refactoring Work on the Transition Model.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
64 InputData inputData = it.next(); |
a887074460b6
Last Step of the Refactoring Work on the Transition Model.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
65 if (inputData.getName().equals(this.dataName)){ |
a887074460b6
Last Step of the Refactoring Work on the Transition Model.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
66 boolean returnValue = false; |
a887074460b6
Last Step of the Refactoring Work on the Transition Model.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
67 if (operator.equals("equal")){ |
a887074460b6
Last Step of the Refactoring Work on the Transition Model.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
68 returnValue = this.dataValue.equals(inputData.getValue()); |
a887074460b6
Last Step of the Refactoring Work on the Transition Model.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
69 }else if (operator.equals("notequal")){ |
a887074460b6
Last Step of the Refactoring Work on the Transition Model.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
70 returnValue = !this.dataValue.equals(inputData.getValue()); |
a887074460b6
Last Step of the Refactoring Work on the Transition Model.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
71 } |
a887074460b6
Last Step of the Refactoring Work on the Transition Model.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
72 return returnValue; |
a887074460b6
Last Step of the Refactoring Work on the Transition Model.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
73 } |
a887074460b6
Last Step of the Refactoring Work on the Transition Model.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
74 } |
a887074460b6
Last Step of the Refactoring Work on the Transition Model.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
75 if (operator.equals("notequal")){ |
a887074460b6
Last Step of the Refactoring Work on the Transition Model.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
76 // data is not given. So the constraint not Equals is fullfilled. |
a887074460b6
Last Step of the Refactoring Work on the Transition Model.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
77 return true; |
a887074460b6
Last Step of the Refactoring Work on the Transition Model.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
78 } |
a887074460b6
Last Step of the Refactoring Work on the Transition Model.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
79 } catch (StateException e) { |
a887074460b6
Last Step of the Refactoring Work on the Transition Model.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
80 log.error(e,e); |
a887074460b6
Last Step of the Refactoring Work on the Transition Model.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
81 return false; |
a887074460b6
Last Step of the Refactoring Work on the Transition Model.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
82 } |
a887074460b6
Last Step of the Refactoring Work on the Transition Model.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
83 return false; |
a887074460b6
Last Step of the Refactoring Work on the Transition Model.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
84 } |
a887074460b6
Last Step of the Refactoring Work on the Transition Model.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
85 |
835
2423cefe7d39
Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
824
diff
changeset
|
86 |
337
a887074460b6
Last Step of the Refactoring Work on the Transition Model.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
87 @Override |
a887074460b6
Last Step of the Refactoring Work on the Transition Model.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
88 public void setup(Node configuration) { |
a887074460b6
Last Step of the Refactoring Work on the Transition Model.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
89 super.setup(configuration); |
a887074460b6
Last Step of the Refactoring Work on the Transition Model.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
90 this.dataName = Config.getStringXPath(configuration,"condition/@inputvalue"); |
a887074460b6
Last Step of the Refactoring Work on the Transition Model.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
91 this.dataValue = Config.getStringXPath(configuration,"condition/@value"); |
a887074460b6
Last Step of the Refactoring Work on the Transition Model.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
92 this.operator = Config.getStringXPath(configuration,"condition/@operator"); |
a887074460b6
Last Step of the Refactoring Work on the Transition Model.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
93 } |
a887074460b6
Last Step of the Refactoring Work on the Transition Model.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
94 } |
836
05bf8534a35a
Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
835
diff
changeset
|
95 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |