tim@337: package de.intevation.gnv.transition;
tim@337:
sascha@779: import de.intevation.artifactdatabase.Config;
sascha@779:
sascha@779: import de.intevation.gnv.state.InputData;
sascha@779: import de.intevation.gnv.state.State;
sascha@779:
sascha@779: import de.intevation.gnv.state.exception.StateException;
sascha@779:
tim@337: import java.util.Iterator;
tim@337:
tim@337: import org.apache.log4j.Logger;
tim@337:
sascha@779: import org.w3c.dom.Node;
tim@337:
tim@337: /**
sascha@780: * @author Tim Englich
tim@337: *
tim@337: */
tim@337: public class ValueCompareTransition extends TransitionBase {
tim@337:
tim@337: /**
tim@337: * the logger, used to log exceptions and additonaly information
tim@337: */
tim@337: private static Logger log = Logger.getLogger(ValueCompareTransition.class);
sascha@778:
tim@337: private String dataName = null;
tim@337: private String dataValue = null;
tim@337: private String operator = null;
sascha@778:
tim@337: /**
tim@337: * The UID of this Class.
tim@337: */
tim@337: private static final long serialVersionUID = -7846722158776823205L;
tim@337:
tim@337: /**
tim@337: * Constructor
tim@337: */
tim@337: public ValueCompareTransition() {
tim@337: super();
tim@337: }
tim@337:
tim@337: /**
tim@337: * @see de.intevation.gnv.transition.Transition#isValid(de.intevation.gnv.state.State)
tim@337: */
tim@337: public boolean isValid(State state) {
sascha@778:
tim@337: try {
tim@337: Iterator it = state.getInputData().iterator();
tim@337: while (it.hasNext()){
tim@337: InputData inputData = it.next();
tim@337: if (inputData.getName().equals(this.dataName)){
tim@337: boolean returnValue = false;
tim@337: if (operator.equals("equal")){
tim@337: returnValue = this.dataValue.equals(inputData.getValue());
tim@337: }else if (operator.equals("notequal")){
tim@337: returnValue = !this.dataValue.equals(inputData.getValue());
tim@337: }
tim@337: return returnValue;
tim@337: }
tim@337: }
tim@337: if (operator.equals("notequal")){
tim@337: // data is not given. So the constraint not Equals is fullfilled.
tim@337: return true;
tim@337: }
tim@337: } catch (StateException e) {
tim@337: log.error(e,e);
tim@337: return false;
tim@337: }
tim@337: return false;
tim@337: }
tim@337:
tim@337: @Override
tim@337: public void setup(Node configuration) {
tim@337: super.setup(configuration);
tim@337: this.dataName = Config.getStringXPath(configuration,"condition/@inputvalue");
tim@337: this.dataValue = Config.getStringXPath(configuration,"condition/@value");
tim@337: this.operator = Config.getStringXPath(configuration,"condition/@operator");
tim@337: }
sascha@778:
tim@337:
tim@337: }