Mercurial > dive4elements > river
view flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java @ 114:394b9580ceae
Added mockup classes for working with rivers.
flys-artifacts/trunk@1303 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Tue, 08 Feb 2011 09:02:18 +0000 |
parents | 0fab16cb4d44 |
children | b51e92fef704 |
line wrap: on
line source
package de.intevation.flys.artifacts; import java.util.List; import org.w3c.dom.Document; import org.w3c.dom.Element; 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; import de.intevation.artifactdatabase.transition.TransitionEngine; import de.intevation.artifacts.common.utils.XMLUtils; import de.intevation.flys.artifacts.context.FLYSContext; /** * The default WINFO artifact. * * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> */ public class WINFOArtifact extends DefaultArtifact { /** 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. */ public WINFOArtifact() { } /** * 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 <code>data</code> 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<State> states = engine.getStates(ARTIFACT_NAME); setCurrentState(states.get(0)); } /** * This method returns a description of this artifact. * * @param data Some data. * @param CallContext The CallContext. * * @return the description of this artifact. */ public Document describe(Document data, CallContext context) { logger.debug("Describe: the current state is: " + currentState.getID()); FLYSContext flysContext = null; if (context instanceof FLYSContext) { flysContext = (FLYSContext) context; } else { flysContext = (FLYSContext) context.globalContext(); } StateEngine stateEngine = (StateEngine) flysContext.get( FLYSContext.STATE_ENGINE_KEY); TransitionEngine transitionEngine = (TransitionEngine) flysContext.get( FLYSContext.TRANSITION_ENGINE_KEY); List<State> reachable = transitionEngine.getReachableStates( currentState, stateEngine); Document description = XMLUtils.newDocument(); XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator( description, ArtifactNamespaceContext.NAMESPACE_URI, ArtifactNamespaceContext.NAMESPACE_PREFIX); Element root = ProtocolUtils.createRootNode(creator); ProtocolUtils.appendDescribeHeader(creator, root, identifier(), hash()); ProtocolUtils.appendState(creator, root, currentState); ProtocolUtils.appendReachableStates(creator, root, reachable); logger.warn("TODO: Implement the model and ui description!"); description.appendChild(root); return description; } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :