comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java @ 119:84c0b151203e

Added a FLYSArtifact that serves as the default artifact for the FLYS application. flys-artifacts/trunk@1438 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Wed, 09 Mar 2011 11:29:07 +0000
parents b51e92fef704
children e0ded17a4846
comparison
equal deleted inserted replaced
118:888e3b1dcdd9 119:84c0b151203e
5 import org.w3c.dom.Document; 5 import org.w3c.dom.Document;
6 import org.w3c.dom.Element; 6 import org.w3c.dom.Element;
7 7
8 import org.apache.log4j.Logger; 8 import org.apache.log4j.Logger;
9 9
10 import de.intevation.artifacts.ArtifactFactory;
11 import de.intevation.artifacts.ArtifactNamespaceContext; 10 import de.intevation.artifacts.ArtifactNamespaceContext;
12 import de.intevation.artifacts.CallContext; 11 import de.intevation.artifacts.CallContext;
13 12
14 import de.intevation.artifactdatabase.DefaultArtifact;
15 import de.intevation.artifactdatabase.ProtocolUtils; 13 import de.intevation.artifactdatabase.ProtocolUtils;
16 import de.intevation.artifactdatabase.state.State; 14 import de.intevation.artifactdatabase.state.State;
17 import de.intevation.artifactdatabase.state.StateEngine; 15 import de.intevation.artifactdatabase.state.StateEngine;
18 import de.intevation.artifactdatabase.transition.TransitionEngine; 16 import de.intevation.artifactdatabase.transition.TransitionEngine;
19 17
25 /** 23 /**
26 * The default WINFO artifact. 24 * The default WINFO artifact.
27 * 25 *
28 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> 26 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
29 */ 27 */
30 public class WINFOArtifact extends DefaultArtifact { 28 public class WINFOArtifact extends FLYSArtifact {
31 29
32 /** The logger for this class */ 30 /** The logger for this class */
33 private static Logger logger = Logger.getLogger(WINFOArtifact.class); 31 private static Logger logger = Logger.getLogger(WINFOArtifact.class);
34
35 /** The name of the artifact. */
36 public static final String ARTIFACT_NAME = "winfo";
37
38 /** The XPath to the name of the artifact in its configuration. */
39 public static final String XPATH_ARTIFACT_NAME = "@name";
40
41 /** The current state. */
42 protected State currentState;
43 32
44 33
45 /** 34 /**
46 * The default constructor. 35 * The default constructor.
47 */ 36 */
48 public WINFOArtifact() { 37 public WINFOArtifact() {
49 }
50
51
52 /**
53 * Set the current state of this artifact.
54 *
55 * @param state The new current state.
56 */
57 protected void setCurrentState(State state) {
58 currentState = state;
59 }
60
61
62 /**
63 * Initialize the artifact and insert new data if <code>data</code> contains
64 * information necessary for this artifact.
65 *
66 * @param identifier The UUID.
67 * @param factory The factory that is used to create this artifact.
68 * @param context The CallContext.
69 * @param data Some optional data.
70 */
71 @Override
72 public void setup(
73 String identifier,
74 ArtifactFactory factory,
75 Object context,
76 Document data)
77 {
78 logger.debug("Setup this artifact with the uuid: " + identifier);
79
80 super.setup(identifier, factory, context, data);
81
82 FLYSContext flysContext = (FLYSContext) context;
83 StateEngine engine = (StateEngine) flysContext.get(
84 FLYSContext.STATE_ENGINE_KEY);
85
86 List<State> states = engine.getStates(ARTIFACT_NAME);
87
88 setCurrentState(states.get(0));
89 } 38 }
90 39
91 40
92 /** 41 /**
93 * This method returns a description of this artifact. 42 * This method returns a description of this artifact.
96 * @param CallContext The CallContext. 45 * @param CallContext The CallContext.
97 * 46 *
98 * @return the description of this artifact. 47 * @return the description of this artifact.
99 */ 48 */
100 public Document describe(Document data, CallContext context) { 49 public Document describe(Document data, CallContext context) {
101 logger.debug("Describe: the current state is: " + currentState.getID()); 50 logger.debug("Describe: the current state is: " + getCurrentStateId());
102 51
103 FLYSContext flysContext = null; 52 FLYSContext flysContext = null;
104 if (context instanceof FLYSContext) { 53 if (context instanceof FLYSContext) {
105 flysContext = (FLYSContext) context; 54 flysContext = (FLYSContext) context;
106 } 55 }
113 62
114 TransitionEngine transitionEngine = (TransitionEngine) flysContext.get( 63 TransitionEngine transitionEngine = (TransitionEngine) flysContext.get(
115 FLYSContext.TRANSITION_ENGINE_KEY); 64 FLYSContext.TRANSITION_ENGINE_KEY);
116 65
117 List<State> reachable = transitionEngine.getReachableStates( 66 List<State> reachable = transitionEngine.getReachableStates(
118 currentState, stateEngine); 67 getCurrentState(context), stateEngine);
119 68
120 Document description = XMLUtils.newDocument(); 69 Document description = XMLUtils.newDocument();
121 XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator( 70 XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator(
122 description, 71 description,
123 ArtifactNamespaceContext.NAMESPACE_URI, 72 ArtifactNamespaceContext.NAMESPACE_URI,
124 ArtifactNamespaceContext.NAMESPACE_PREFIX); 73 ArtifactNamespaceContext.NAMESPACE_PREFIX);
125 74
126 Element root = ProtocolUtils.createRootNode(creator); 75 Element root = ProtocolUtils.createRootNode(creator);
127 description.appendChild(root); 76 description.appendChild(root);
128 77
78 State current = getCurrentState(context);
79
129 ProtocolUtils.appendDescribeHeader(creator, root, identifier(), hash()); 80 ProtocolUtils.appendDescribeHeader(creator, root, identifier(), hash());
130 ProtocolUtils.appendState(creator, root, currentState); 81 ProtocolUtils.appendState(creator, root, current);
131 ProtocolUtils.appendReachableStates(creator, root, reachable); 82 ProtocolUtils.appendReachableStates(creator, root, reachable);
132 83
133 currentState.describe(description, root, context, identifier()); 84 current.describe(description, root, context, identifier());
134 85
135 return description; 86 return description;
136 } 87 }
137 } 88 }
138 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : 89 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org