ingo@105: package de.intevation.flys.artifacts; ingo@105: ingo@109: import java.util.List; ingo@109: ingo@105: import org.w3c.dom.Document; ingo@110: import org.w3c.dom.Element; ingo@105: ingo@105: import org.apache.log4j.Logger; ingo@105: ingo@105: import de.intevation.artifacts.ArtifactFactory; ingo@110: import de.intevation.artifacts.ArtifactNamespaceContext; ingo@105: import de.intevation.artifacts.CallContext; ingo@105: ingo@110: import de.intevation.artifactdatabase.DefaultArtifact; ingo@110: import de.intevation.artifactdatabase.ProtocolUtils; ingo@110: import de.intevation.artifactdatabase.state.State; ingo@110: import de.intevation.artifactdatabase.state.StateEngine; ingo@112: import de.intevation.artifactdatabase.transition.TransitionEngine; ingo@110: ingo@109: import de.intevation.artifacts.common.utils.XMLUtils; ingo@109: ingo@109: import de.intevation.flys.artifacts.context.FLYSContext; ingo@105: ingo@105: ingo@105: /** ingo@105: * The default WINFO artifact. ingo@105: * ingo@105: * @author Ingo Weinzierl ingo@105: */ ingo@105: public class WINFOArtifact extends DefaultArtifact { ingo@105: ingo@105: /** The logger for this class */ ingo@105: private static Logger logger = Logger.getLogger(WINFOArtifact.class); ingo@105: ingo@109: /** The name of the artifact. */ ingo@109: public static final String ARTIFACT_NAME = "winfo"; ingo@109: ingo@109: /** The XPath to the name of the artifact in its configuration. */ ingo@109: public static final String XPATH_ARTIFACT_NAME = "@name"; ingo@109: ingo@109: /** The current state. */ ingo@109: protected State currentState; ingo@109: ingo@105: ingo@105: /** ingo@105: * The default constructor. ingo@105: */ ingo@105: public WINFOArtifact() { ingo@105: } ingo@105: ingo@105: ingo@105: /** ingo@109: * Set the current state of this artifact. ingo@109: * ingo@109: * @param state The new current state. ingo@109: */ ingo@109: protected void setCurrentState(State state) { ingo@109: currentState = state; ingo@109: } ingo@109: ingo@109: ingo@109: /** ingo@105: * Initialize the artifact and insert new data if data contains ingo@105: * information necessary for this artifact. ingo@105: * ingo@105: * @param identifier The UUID. ingo@105: * @param factory The factory that is used to create this artifact. ingo@105: * @param context The CallContext. ingo@105: * @param data Some optional data. ingo@105: */ ingo@105: @Override ingo@105: public void setup( ingo@105: String identifier, ingo@105: ArtifactFactory factory, ingo@105: Object context, ingo@105: Document data) ingo@105: { ingo@105: logger.debug("Setup this artifact with the uuid: " + identifier); ingo@105: ingo@105: super.setup(identifier, factory, context, data); ingo@105: ingo@109: FLYSContext flysContext = (FLYSContext) context; ingo@109: StateEngine engine = (StateEngine) flysContext.get( ingo@109: FLYSContext.STATE_ENGINE_KEY); ingo@105: ingo@109: List states = engine.getStates(ARTIFACT_NAME); ingo@105: ingo@109: setCurrentState(states.get(0)); ingo@105: } ingo@105: ingo@105: ingo@105: /** ingo@105: * This method returns a description of this artifact. ingo@105: * ingo@105: * @param data Some data. ingo@105: * @param CallContext The CallContext. ingo@105: * ingo@105: * @return the description of this artifact. ingo@105: */ ingo@105: public Document describe(Document data, CallContext context) { ingo@110: logger.debug("Describe: the current state is: " + currentState.getID()); ingo@105: ingo@112: FLYSContext flysContext = null; ingo@112: if (context instanceof FLYSContext) { ingo@112: flysContext = (FLYSContext) context; ingo@112: } ingo@112: else { ingo@112: flysContext = (FLYSContext) context.globalContext(); ingo@112: } ingo@110: ingo@112: StateEngine stateEngine = (StateEngine) flysContext.get( ingo@112: FLYSContext.STATE_ENGINE_KEY); ingo@112: ingo@112: TransitionEngine transitionEngine = (TransitionEngine) flysContext.get( ingo@112: FLYSContext.TRANSITION_ENGINE_KEY); ingo@112: ingo@112: List reachable = transitionEngine.getReachableStates( ingo@112: currentState, stateEngine); ingo@112: ingo@112: Document description = XMLUtils.newDocument(); ingo@110: XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator( ingo@110: description, ingo@110: ArtifactNamespaceContext.NAMESPACE_URI, ingo@110: ArtifactNamespaceContext.NAMESPACE_PREFIX); ingo@110: ingo@110: Element root = ProtocolUtils.createRootNode(creator); ingo@115: description.appendChild(root); ingo@115: ingo@110: ProtocolUtils.appendDescribeHeader(creator, root, identifier(), hash()); ingo@112: ProtocolUtils.appendState(creator, root, currentState); ingo@112: ProtocolUtils.appendReachableStates(creator, root, reachable); ingo@110: ingo@115: currentState.describe(description, root, context, identifier()); ingo@110: ingo@110: return description; ingo@105: } ingo@105: } ingo@105: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :