Mercurial > dive4elements > gnv-client
annotate gnv-artifacts/src/main/java/de/intevation/gnv/transition/ValueCompareTransition.java @ 1117:dec4257ad570
Changed imports to fit new positions of XMLUtils and Config
gnv-artifacts/trunk@1478 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Tue, 15 Mar 2011 16:13:39 +0000 |
parents | f953c9a559d8 |
children |
rev | line source |
---|---|
1115
f953c9a559d8
Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
836
diff
changeset
|
1 /* |
f953c9a559d8
Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
836
diff
changeset
|
2 * Copyright (c) 2010 by Intevation GmbH |
f953c9a559d8
Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
836
diff
changeset
|
3 * |
f953c9a559d8
Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
836
diff
changeset
|
4 * This program is free software under the LGPL (>=v2.1) |
f953c9a559d8
Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
836
diff
changeset
|
5 * Read the file LGPL.txt coming with the software for details |
f953c9a559d8
Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
836
diff
changeset
|
6 * or visit http://www.gnu.org/licenses/ if it does not exist. |
f953c9a559d8
Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
836
diff
changeset
|
7 */ |
f953c9a559d8
Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
836
diff
changeset
|
8 |
337
a887074460b6
Last Step of the Refactoring Work on the Transition Model.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
9 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
|
10 |
a887074460b6
Last Step of the Refactoring Work on the Transition Model.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
11 import java.util.Iterator; |
a887074460b6
Last Step of the Refactoring Work on the Transition Model.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
12 |
a887074460b6
Last Step of the Refactoring Work on the Transition Model.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
13 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
|
14 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
|
15 |
1117
dec4257ad570
Changed imports to fit new positions of XMLUtils and Config
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1115
diff
changeset
|
16 import de.intevation.artifacts.common.utils.Config; |
824
7e5995c47125
Added more Javadoc.
Tim Englich <tim.englich@intevation.de>
parents:
813
diff
changeset
|
17 import de.intevation.gnv.state.InputData; |
7e5995c47125
Added more Javadoc.
Tim Englich <tim.englich@intevation.de>
parents:
813
diff
changeset
|
18 import de.intevation.gnv.state.State; |
7e5995c47125
Added more Javadoc.
Tim Englich <tim.englich@intevation.de>
parents:
813
diff
changeset
|
19 import de.intevation.gnv.state.exception.StateException; |
7e5995c47125
Added more Javadoc.
Tim Englich <tim.englich@intevation.de>
parents:
813
diff
changeset
|
20 |
337
a887074460b6
Last Step of the Refactoring Work on the Transition Model.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
21 /** |
824
7e5995c47125
Added more Javadoc.
Tim Englich <tim.englich@intevation.de>
parents:
813
diff
changeset
|
22 * Class which supports the possibility to validate if a |
7e5995c47125
Added more Javadoc.
Tim Englich <tim.englich@intevation.de>
parents:
813
diff
changeset
|
23 * Transition could be done using simple Valuecompare Operations. |
7e5995c47125
Added more Javadoc.
Tim Englich <tim.englich@intevation.de>
parents:
813
diff
changeset
|
24 * At this Time equal and notequal-operations are supported. |
7e5995c47125
Added more Javadoc.
Tim Englich <tim.englich@intevation.de>
parents:
813
diff
changeset
|
25 * 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
|
26 * @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
|
27 * |
a887074460b6
Last Step of the Refactoring Work on the Transition Model.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
28 */ |
a887074460b6
Last Step of the Refactoring Work on the Transition Model.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
29 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
|
30 |
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 * 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
|
33 */ |
a887074460b6
Last Step of the Refactoring Work on the Transition Model.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
34 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
|
35 /** |
a887074460b6
Last Step of the Refactoring Work on the Transition Model.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
36 * 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
|
37 */ |
a887074460b6
Last Step of the Refactoring Work on the Transition Model.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
38 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
|
39 |
a887074460b6
Last Step of the Refactoring Work on the Transition Model.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
40 /** |
835
2423cefe7d39
Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
824
diff
changeset
|
41 * 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
|
42 * should be fetched from. |
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 dataName = 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 * The Value that should be set to the State. |
7e5995c47125
Added more Javadoc.
Tim Englich <tim.englich@intevation.de>
parents:
813
diff
changeset
|
47 */ |
7e5995c47125
Added more Javadoc.
Tim Englich <tim.englich@intevation.de>
parents:
813
diff
changeset
|
48 private String dataValue = null; |
7e5995c47125
Added more Javadoc.
Tim Englich <tim.englich@intevation.de>
parents:
813
diff
changeset
|
49 /** |
7e5995c47125
Added more Javadoc.
Tim Englich <tim.englich@intevation.de>
parents:
813
diff
changeset
|
50 * The Operation that should be used (equal notequal) |
7e5995c47125
Added more Javadoc.
Tim Englich <tim.englich@intevation.de>
parents:
813
diff
changeset
|
51 */ |
7e5995c47125
Added more Javadoc.
Tim Englich <tim.englich@intevation.de>
parents:
813
diff
changeset
|
52 private String operator = null; |
7e5995c47125
Added more Javadoc.
Tim Englich <tim.englich@intevation.de>
parents:
813
diff
changeset
|
53 |
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 /** |
337
a887074460b6
Last Step of the Refactoring Work on the Transition Model.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
56 * Constructor |
a887074460b6
Last Step of the Refactoring Work on the Transition Model.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
57 */ |
a887074460b6
Last Step of the Refactoring Work on the Transition Model.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
58 public ValueCompareTransition() { |
a887074460b6
Last Step of the Refactoring Work on the Transition Model.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
59 super(); |
a887074460b6
Last Step of the Refactoring Work on the Transition Model.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
60 } |
a887074460b6
Last Step of the Refactoring Work on the Transition Model.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
61 |
824
7e5995c47125
Added more Javadoc.
Tim Englich <tim.englich@intevation.de>
parents:
813
diff
changeset
|
62 /** |
7e5995c47125
Added more Javadoc.
Tim Englich <tim.englich@intevation.de>
parents:
813
diff
changeset
|
63 * 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
|
64 * Comparevalue-Operations. |
7e5995c47125
Added more Javadoc.
Tim Englich <tim.englich@intevation.de>
parents:
813
diff
changeset
|
65 * @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
|
66 */ |
337
a887074460b6
Last Step of the Refactoring Work on the Transition Model.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
67 public boolean isValid(State state) { |
778
9a828e5a2390
Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
337
diff
changeset
|
68 |
337
a887074460b6
Last Step of the Refactoring Work on the Transition Model.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
69 try { |
a887074460b6
Last Step of the Refactoring Work on the Transition Model.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
70 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
|
71 while (it.hasNext()){ |
a887074460b6
Last Step of the Refactoring Work on the Transition Model.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
72 InputData inputData = it.next(); |
a887074460b6
Last Step of the Refactoring Work on the Transition Model.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
73 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
|
74 boolean returnValue = false; |
a887074460b6
Last Step of the Refactoring Work on the Transition Model.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
75 if (operator.equals("equal")){ |
a887074460b6
Last Step of the Refactoring Work on the Transition Model.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
76 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
|
77 }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
|
78 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
|
79 } |
a887074460b6
Last Step of the Refactoring Work on the Transition Model.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
80 return returnValue; |
a887074460b6
Last Step of the Refactoring Work on the Transition Model.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
81 } |
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 if (operator.equals("notequal")){ |
a887074460b6
Last Step of the Refactoring Work on the Transition Model.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
84 // 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
|
85 return true; |
a887074460b6
Last Step of the Refactoring Work on the Transition Model.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
86 } |
a887074460b6
Last Step of the Refactoring Work on the Transition Model.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
87 } catch (StateException e) { |
a887074460b6
Last Step of the Refactoring Work on the Transition Model.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
88 log.error(e,e); |
a887074460b6
Last Step of the Refactoring Work on the Transition Model.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
89 return false; |
a887074460b6
Last Step of the Refactoring Work on the Transition Model.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
90 } |
a887074460b6
Last Step of the Refactoring Work on the Transition Model.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
91 return false; |
a887074460b6
Last Step of the Refactoring Work on the Transition Model.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
92 } |
a887074460b6
Last Step of the Refactoring Work on the Transition Model.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
93 |
835
2423cefe7d39
Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
824
diff
changeset
|
94 |
337
a887074460b6
Last Step of the Refactoring Work on the Transition Model.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
95 @Override |
a887074460b6
Last Step of the Refactoring Work on the Transition Model.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
96 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
|
97 super.setup(configuration); |
a887074460b6
Last Step of the Refactoring Work on the Transition Model.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
98 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
|
99 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
|
100 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
|
101 } |
a887074460b6
Last Step of the Refactoring Work on the Transition Model.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
102 } |
836
05bf8534a35a
Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
835
diff
changeset
|
103 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |