comparison gnv-artifacts/src/main/java/de/intevation/gnv/transition/ValueCompareTransition.java @ 1119:7c4f81f74c47

merged gnv-artifacts
author Thomas Arendsen Hein <thomas@intevation.de>
date Fri, 28 Sep 2012 12:14:00 +0200
parents dec4257ad570
children
comparison
equal deleted inserted replaced
1027:fca4b5eb8d2f 1119:7c4f81f74c47
1 /*
2 * Copyright (c) 2010 by Intevation GmbH
3 *
4 * This program is free software under the LGPL (>=v2.1)
5 * Read the file LGPL.txt coming with the software for details
6 * or visit http://www.gnu.org/licenses/ if it does not exist.
7 */
8
9 package de.intevation.gnv.transition;
10
11 import java.util.Iterator;
12
13 import org.apache.log4j.Logger;
14 import org.w3c.dom.Node;
15
16 import de.intevation.artifacts.common.utils.Config;
17 import de.intevation.gnv.state.InputData;
18 import de.intevation.gnv.state.State;
19 import de.intevation.gnv.state.exception.StateException;
20
21 /**
22 * Class which supports the possibility to validate if a
23 * Transition could be done using simple Valuecompare Operations.
24 * At this Time equal and notequal-operations are supported.
25 * The Comparation is casesensitive.
26 * @author <a href="mailto:tim.englich@intevation.de">Tim Englich</a>
27 *
28 */
29 public class ValueCompareTransition extends TransitionBase {
30
31 /**
32 * the logger, used to log exceptions and additonaly information
33 */
34 private static Logger log = Logger.getLogger(ValueCompareTransition.class);
35 /**
36 * The UID of this Class.
37 */
38 private static final long serialVersionUID = -7846722158776823205L;
39
40 /**
41 * The Name of the Datafield the Value that should be compared
42 * should be fetched from.
43 */
44 private String dataName = null;
45 /**
46 * The Value that should be set to the State.
47 */
48 private String dataValue = null;
49 /**
50 * The Operation that should be used (equal notequal)
51 */
52 private String operator = null;
53
54
55 /**
56 * Constructor
57 */
58 public ValueCompareTransition() {
59 super();
60 }
61
62 /**
63 * validates if a Transition is valid and could be used using simple
64 * Comparevalue-Operations.
65 * @see de.intevation.gnv.transition.Transition#isValid(de.intevation.gnv.state.State)
66 */
67 public boolean isValid(State state) {
68
69 try {
70 Iterator<InputData> it = state.getInputData().iterator();
71 while (it.hasNext()){
72 InputData inputData = it.next();
73 if (inputData.getName().equals(this.dataName)){
74 boolean returnValue = false;
75 if (operator.equals("equal")){
76 returnValue = this.dataValue.equals(inputData.getValue());
77 }else if (operator.equals("notequal")){
78 returnValue = !this.dataValue.equals(inputData.getValue());
79 }
80 return returnValue;
81 }
82 }
83 if (operator.equals("notequal")){
84 // data is not given. So the constraint not Equals is fullfilled.
85 return true;
86 }
87 } catch (StateException e) {
88 log.error(e,e);
89 return false;
90 }
91 return false;
92 }
93
94
95 @Override
96 public void setup(Node configuration) {
97 super.setup(configuration);
98 this.dataName = Config.getStringXPath(configuration,"condition/@inputvalue");
99 this.dataValue = Config.getStringXPath(configuration,"condition/@value");
100 this.operator = Config.getStringXPath(configuration,"condition/@operator");
101 }
102 }
103 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org