ingo@1115: /* ingo@1115: * Copyright (c) 2010 by Intevation GmbH ingo@1115: * ingo@1115: * This program is free software under the LGPL (>=v2.1) ingo@1115: * Read the file LGPL.txt coming with the software for details ingo@1115: * or visit http://www.gnu.org/licenses/ if it does not exist. ingo@1115: */ ingo@1115: tim@612: package de.intevation.gnv.transition; tim@612: tim@612: import java.util.Map; tim@612: tim@612: import org.apache.log4j.Logger; sascha@779: import org.w3c.dom.Node; tim@612: tim@824: import de.intevation.artifactdatabase.Config; tim@824: import de.intevation.gnv.state.InputData; tim@824: import de.intevation.gnv.state.State; tim@824: tim@612: /** tim@824: * Class which supports the possibility to validate if a tim@824: * Transition could be done using simple Valuecompare Operations. tim@824: * The Compareoperations will use the preSettings of an Artifact. tim@824: * At this Time equal and notequal-operations are supported. tim@824: * The Comparation is casesensitive. 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@824: /** sascha@835: * The Name of the Datafield the Value that should be compared tim@824: * should be fetched from. tim@824: */ tim@612: private String dataName = null; tim@824: /** tim@824: * The Value that should be set to the State. tim@824: */ tim@612: private String dataValue = null; tim@824: /** tim@824: * The Operation that should be used (equal notequal) tim@824: */ 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: ingo@813: 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: ingo@813: 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: } tim@612: } ingo@813: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :