comparison gnv-artifacts/src/main/java/de/intevation/gnv/transition/PresettingsValueCompareTransition.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.Map;
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
20 /**
21 * Class which supports the possibility to validate if a
22 * Transition could be done using simple Valuecompare Operations.
23 * The Compareoperations will use the preSettings of an Artifact.
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 PresettingsValueCompareTransition extends TransitionBase {
30
31 /**
32 * the logger, used to log exceptions and additonaly information
33 */
34 private static Logger log = Logger.getLogger(PresettingsValueCompareTransition.class);
35
36 /**
37 * The Name of the Datafield the Value that should be compared
38 * should be fetched from.
39 */
40 private String dataName = null;
41 /**
42 * The Value that should be set to the State.
43 */
44 private String dataValue = null;
45 /**
46 * The Operation that should be used (equal notequal)
47 */
48 private String operator = null;
49
50 /**
51 * The UID of this Class.
52 */
53 private static final long serialVersionUID = -7846722158776823205L;
54
55 /**
56 * Constructor
57 */
58 public PresettingsValueCompareTransition() {
59 super();
60 }
61
62
63 public boolean isValid(State state) {
64 Map<String, InputData> preSettings = state.getPreSettings();
65 if (preSettings != null){
66 boolean dataAvailable = preSettings.containsKey(dataName);
67 if (dataAvailable){
68 if (operator.equals("equal")){
69 return preSettings.get(dataName).getValue().startsWith(dataValue);
70 }else if (operator.equals("notequal")){
71 return !preSettings.get(dataName).getValue().startsWith(dataValue);
72 }
73 }
74 }
75 if (operator.equals("notequal")){
76 return true;
77 }
78 return false;
79 }
80
81
82 @Override
83 public void setup(Node configuration) {
84 super.setup(configuration);
85 this.dataName = Config.getStringXPath(configuration,"condition/@inputvalue");
86 this.dataValue = Config.getStringXPath(configuration,"condition/@value");
87 this.operator = Config.getStringXPath(configuration,"condition/@operator");
88 }
89 }
90 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org