tim@612: package de.intevation.gnv.transition;
tim@612:
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:
tim@612: import java.util.Map;
tim@612:
tim@612: import org.apache.log4j.Logger;
tim@612:
sascha@779: import org.w3c.dom.Node;
tim@612:
tim@612: /**
sascha@780: * @author Tim Englich
tim@612: *
tim@612: */
tim@612: public class PresettingsValueCompareTransition extends TransitionBase {
tim@612:
tim@612: /**
tim@612: * the logger, used to log exceptions and additonaly information
tim@612: */
tim@612: private static Logger log = Logger.getLogger(PresettingsValueCompareTransition.class);
sascha@778:
tim@612: private String dataName = null;
tim@612: private String dataValue = null;
tim@612: private String operator = null;
sascha@778:
tim@612: /**
tim@612: * The UID of this Class.
tim@612: */
tim@612: private static final long serialVersionUID = -7846722158776823205L;
tim@612:
tim@612: /**
tim@612: * Constructor
tim@612: */
tim@612: public PresettingsValueCompareTransition() {
tim@612: super();
tim@612: }
tim@612:
tim@612: /**
tim@612: * @see de.intevation.gnv.transition.Transition#isValid(de.intevation.gnv.state.State)
tim@612: */
tim@612: public boolean isValid(State state) {
tim@612: Map preSettings = state.getPreSettings();
tim@612: if (preSettings != null){
tim@612: boolean dataAvailable = preSettings.containsKey(dataName);
tim@612: if (dataAvailable){
tim@612: if (operator.equals("equal")){
tim@612: return preSettings.get(dataName).getValue().startsWith(dataValue);
tim@612: }else if (operator.equals("notequal")){
tim@612: return !preSettings.get(dataName).getValue().startsWith(dataValue);
tim@612: }
tim@612: }
tim@612: }
tim@612: if (operator.equals("notequal")){
tim@612: return true;
tim@612: }
tim@612: return false;
tim@612: }
tim@612:
tim@612: @Override
tim@612: public void setup(Node configuration) {
tim@612: super.setup(configuration);
tim@612: this.dataName = Config.getStringXPath(configuration,"condition/@inputvalue");
tim@612: this.dataValue = Config.getStringXPath(configuration,"condition/@value");
tim@612: this.operator = Config.getStringXPath(configuration,"condition/@operator");
tim@612: }
sascha@778:
tim@612:
tim@612: }