# HG changeset patch # User Ingo Weinzierl # Date 1299670147 0 # Node ID 84c0b151203e2c25281a28d78b8cbccc6e0e2d7b # Parent 888e3b1dcdd9c4b92ad18695e3b465d5d7cd4831 Added a FLYSArtifact that serves as the default artifact for the FLYS application. flys-artifacts/trunk@1438 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 888e3b1dcdd9 -r 84c0b151203e flys-artifacts/ChangeLog --- a/flys-artifacts/ChangeLog Tue Mar 08 17:22:37 2011 +0000 +++ b/flys-artifacts/ChangeLog Wed Mar 09 11:29:07 2011 +0000 @@ -1,3 +1,14 @@ +2011-03-09 Ingo Weinzierl + + * src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java: New. This + artifact serves as the default artifact for the FLYS application. + + * src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java: This + artifact now inherits from FLYSArtifact. Furthermore, there is one big + change: we don't store the State objects itself in the artifact, but + just the identifier of those. This makes the artifact smaller and more + compatible agains previous versions of the software. + 2011-03-08 Ingo Weinzierl * src/main/java/de/intevation/flys/artifacts/services/RiverService.java: diff -r 888e3b1dcdd9 -r 84c0b151203e flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java Wed Mar 09 11:29:07 2011 +0000 @@ -0,0 +1,180 @@ +package de.intevation.flys.artifacts; + +import java.util.List; + +import org.apache.log4j.Logger; + +import org.w3c.dom.Document; + +import de.intevation.artifacts.ArtifactFactory; +import de.intevation.artifacts.CallContext; + +import de.intevation.artifacts.common.ArtifactNamespaceContext; +import de.intevation.artifacts.common.utils.XMLUtils; + +import de.intevation.artifactdatabase.DefaultArtifact; +import de.intevation.artifactdatabase.data.StateData; +import de.intevation.artifactdatabase.state.State; +import de.intevation.artifactdatabase.state.StateEngine; + +import de.intevation.flys.artifacts.context.FLYSContext; + + +/** + * The defaul FLYS artifact. + * + * @author Ingo Weinzierl + */ +public abstract class FLYSArtifact extends DefaultArtifact { + + /** The logger that is used in this artifact.*/ + private static Logger logger = Logger.getLogger(FLYSArtifact.class); + + + /** The XPath to the name of the artifact in its configuration. */ + public static final String XPATH_ARTIFACT_NAME = "@name"; + + + /** The identifier of the current state. */ + protected String currentStateId; + + /** The name of the artifact.*/ + protected String name; + + + /** + * Initialize the artifact and insert new data if data contains + * information necessary for this artifact. + * + * @param identifier The UUID. + * @param factory The factory that is used to create this artifact. + * @param context The CallContext. + * @param data Some optional data. + */ + @Override + public void setup( + String identifier, + ArtifactFactory factory, + Object context, + Document data) + { + logger.debug("Setup this artifact with the uuid: " + identifier); + + super.setup(identifier, factory, context, data); + + String name = XMLUtils.xpathString( + data, XPATH_ARTIFACT_NAME, ArtifactNamespaceContext.INSTANCE); + setName(name); + + FLYSContext flysContext = (FLYSContext) context; + StateEngine engine = (StateEngine) flysContext.get( + FLYSContext.STATE_ENGINE_KEY); + + List states = engine.getStates(name); + + setCurrentState(states.get(0)); + } + + + /** + * Insert new data included in input into the current state. + * + * @param target XML document that contains new data. + * @param context The CallContext. + * + * @return a document that contains a SUCCESS or FAILURE message. + */ + @Override + public Document feed(Document target, CallContext context) { + Document result = XMLUtils.newDocument(); + + // TODO IMPLEMENT ME + + return result; + } + + + /** + * This method returns the name of the concrete artifact. + * + * @return the name of the concrete artifact. + */ + public String getName() { + return name; + } + + + + /** + * This method sets the name of this artifact. + * + * @param name the name for this artifact. + */ + protected void setName(String name) { + this.name = name; + } + + + /** + * Returns the identifier of the current state. + * + * @return the identifier of the current state. + */ + protected String getCurrentStateId() { + return currentStateId; + } + + + /** + * Sets the identifier of the current state. + * + * @param id the identifier of a state. + */ + protected void setCurrentStateId(String id) { + currentStateId = id; + } + + + + /** + * Set the current state of this artifact. NOTEWe don't store the + * State object itself - which is not necessary - but its identifier. So + * this method will just call the setCurrentStateId() method with the + * identifier of state. + * + * @param state The new current state. + */ + protected void setCurrentState(State state) { + setCurrentStateId(state.getID()); + } + + + /** + * Returns the current state of the artifact. + * + * @return the current State of the artifact. + */ + protected State getCurrentState(Object context) { + FLYSContext flysContext = (FLYSContext) context; + StateEngine engine = (StateEngine) flysContext.get( + FLYSContext.STATE_ENGINE_KEY); + + return engine.getState(getCurrentStateId()); + } + + + /** + * This method extracts the data that is contained in the FEED document. + * + * @param feed The FEED document. + * @param xpath The XPath that points to the data nodes. + * + * @return a StateData array. + */ + public StateData[] extractData(Document feed, String xpath) { + + // TODO IMPLEMENT ME + return null; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r 888e3b1dcdd9 -r 84c0b151203e flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java --- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java Tue Mar 08 17:22:37 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java Wed Mar 09 11:29:07 2011 +0000 @@ -7,11 +7,9 @@ import org.apache.log4j.Logger; -import de.intevation.artifacts.ArtifactFactory; import de.intevation.artifacts.ArtifactNamespaceContext; import de.intevation.artifacts.CallContext; -import de.intevation.artifactdatabase.DefaultArtifact; import de.intevation.artifactdatabase.ProtocolUtils; import de.intevation.artifactdatabase.state.State; import de.intevation.artifactdatabase.state.StateEngine; @@ -27,20 +25,11 @@ * * @author Ingo Weinzierl */ -public class WINFOArtifact extends DefaultArtifact { +public class WINFOArtifact extends FLYSArtifact { /** The logger for this class */ private static Logger logger = Logger.getLogger(WINFOArtifact.class); - /** The name of the artifact. */ - public static final String ARTIFACT_NAME = "winfo"; - - /** The XPath to the name of the artifact in its configuration. */ - public static final String XPATH_ARTIFACT_NAME = "@name"; - - /** The current state. */ - protected State currentState; - /** * The default constructor. @@ -50,46 +39,6 @@ /** - * Set the current state of this artifact. - * - * @param state The new current state. - */ - protected void setCurrentState(State state) { - currentState = state; - } - - - /** - * Initialize the artifact and insert new data if data contains - * information necessary for this artifact. - * - * @param identifier The UUID. - * @param factory The factory that is used to create this artifact. - * @param context The CallContext. - * @param data Some optional data. - */ - @Override - public void setup( - String identifier, - ArtifactFactory factory, - Object context, - Document data) - { - logger.debug("Setup this artifact with the uuid: " + identifier); - - super.setup(identifier, factory, context, data); - - FLYSContext flysContext = (FLYSContext) context; - StateEngine engine = (StateEngine) flysContext.get( - FLYSContext.STATE_ENGINE_KEY); - - List states = engine.getStates(ARTIFACT_NAME); - - setCurrentState(states.get(0)); - } - - - /** * This method returns a description of this artifact. * * @param data Some data. @@ -98,7 +47,7 @@ * @return the description of this artifact. */ public Document describe(Document data, CallContext context) { - logger.debug("Describe: the current state is: " + currentState.getID()); + logger.debug("Describe: the current state is: " + getCurrentStateId()); FLYSContext flysContext = null; if (context instanceof FLYSContext) { @@ -115,7 +64,7 @@ FLYSContext.TRANSITION_ENGINE_KEY); List reachable = transitionEngine.getReachableStates( - currentState, stateEngine); + getCurrentState(context), stateEngine); Document description = XMLUtils.newDocument(); XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator( @@ -126,11 +75,13 @@ Element root = ProtocolUtils.createRootNode(creator); description.appendChild(root); + State current = getCurrentState(context); + ProtocolUtils.appendDescribeHeader(creator, root, identifier(), hash()); - ProtocolUtils.appendState(creator, root, currentState); + ProtocolUtils.appendState(creator, root, current); ProtocolUtils.appendReachableStates(creator, root, reachable); - currentState.describe(description, root, context, identifier()); + current.describe(description, root, context, identifier()); return description; }