ingo@105: /* ingo@105: * Copyright (c) 2011 by Intevation GmbH ingo@105: * ingo@105: * This program is free software under the LGPL (>=v2.1) ingo@105: * Read the file LGPL.txt coming with the software for details ingo@105: * or visit http://www.gnu.org/licenses/ if it does not exist. ingo@105: */ ingo@105: package de.intevation.artifactdatabase.state; ingo@105: ingo@105: import java.util.HashMap; ingo@105: import java.util.Map; ingo@105: ingo@106: import javax.xml.xpath.XPathConstants; ingo@106: ingo@105: import org.w3c.dom.Document; ingo@105: import org.w3c.dom.Node; ingo@105: ingo@105: import de.intevation.artifacts.CallContext; ingo@105: ingo@106: import de.intevation.artifacts.common.utils.XMLUtils; ingo@106: ingo@105: import de.intevation.artifactdatabase.data.StateData; ingo@105: ingo@105: ingo@105: /** ingo@105: * An abstract implementation of a {@link State}. It implements some basic ingo@105: * methods that return the id, description and data. The methods ingo@105: * describe() and setup() depend on the concrete class ingo@105: * and need to be implemented by those. ingo@105: */ ingo@105: public abstract class AbstractState implements State { ingo@105: ingo@106: /** The XPath to the ID of the state relative to the state node in the ingo@106: * configuration. */ ingo@106: public static final String XPATH_ID = "@id"; ingo@106: ingo@106: /** The XPath to the description of the state relative to the state node in ingo@106: * the configuration. */ ingo@106: public static final String XPATH_DESCRIPTION = "@description"; ingo@106: ingo@106: ingo@105: /** The ID of the state. */ ingo@105: protected String id; ingo@105: ingo@105: /** The description of the state. */ ingo@105: protected String description; ingo@105: ingo@105: /** The data provided by this state. */ ingo@105: protected Map data; ingo@105: ingo@105: ingo@105: /** ingo@105: * The default constructor. ingo@105: * ingo@105: * @param id The ID of the state. ingo@105: * @param description The description of the state. ingo@105: */ ingo@105: public AbstractState(String id, String description) { ingo@105: this.id = id; ingo@105: this.description = description; ingo@105: } ingo@105: ingo@105: ingo@105: /** ingo@105: * Returns the ID of the state. ingo@105: * ingo@105: * @return the ID of the state. ingo@105: */ ingo@105: public String getID() { ingo@105: return id; ingo@105: } ingo@105: ingo@105: ingo@105: /** ingo@105: * Set the ID of the state. ingo@105: * ingo@105: * @param id The ID of the state. ingo@105: */ ingo@105: public void setID(String id) { ingo@105: this.id = id; ingo@105: } ingo@105: ingo@105: ingo@105: /** ingo@105: * Returns the description of the state. ingo@105: * ingo@105: * @return the description of the state. ingo@105: */ ingo@105: public String getDescription() { ingo@105: return description; ingo@105: } ingo@105: ingo@105: ingo@105: /** ingo@105: * Set the description of the state. ingo@105: * ingo@105: * @param description The description of the state. ingo@105: */ ingo@105: public void setDescription(String description) { ingo@105: this.description = description; ingo@105: } ingo@105: ingo@105: ingo@105: /** ingo@105: * Returns the data of the state. ingo@105: * ingo@105: * @return the data of the state. ingo@105: */ ingo@105: public Map getData() { ingo@105: return data; ingo@105: } ingo@105: ingo@105: ingo@105: /** ingo@105: * Add new data to the state. NOTE: If there is already an object existing ingo@105: * with the key name, this object is overwritten by the new value. ingo@105: * ingo@105: * @param name The name of the data object. ingo@105: * @param StateData The data object. ingo@105: */ ingo@105: public void addData(String name, StateData data) { ingo@105: if (this.data == null) { ingo@105: this.data = new HashMap(); ingo@105: } ingo@105: ingo@105: this.data.put(name, data); ingo@105: } ingo@105: ingo@105: ingo@105: /** ingo@106: * Initialize the state based on the state node in the configuration. ingo@105: * ingo@105: * @param config The state configuration node. ingo@105: */ ingo@106: public void setup(Node config) { ingo@106: id = (String) XMLUtils.xpath(config, XPATH_ID, XPathConstants.STRING); ingo@106: ingo@106: description = (String) XMLUtils.xpath( ingo@106: config, XPATH_DESCRIPTION, XPathConstants.STRING); ingo@106: } ingo@105: ingo@105: ingo@105: /** ingo@105: * Describes the UI of the state. This method needs to be implemented by ingo@105: * concrete subclasses. ingo@105: * ingo@105: * @param document Describe doucment. ingo@105: * @param rootNode Parent node for all new elements. ingo@105: * @param context The CallContext. ingo@105: * @param uuid The uuid of an artifact. ingo@105: */ ingo@105: public abstract void describe( ingo@105: Document document, ingo@105: Node rootNode, ingo@105: CallContext context, ingo@105: String uuid ingo@105: ); ingo@105: } ingo@105: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :