comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/FixationArtifact.java @ 2651:9e9eb9d97548

Initial transition configuration and artifact/state stubs for fixation analysis. flys-artifacts/trunk@4312 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Raimund Renkert <raimund.renkert@intevation.de>
date Thu, 26 Apr 2012 15:08:51 +0000
parents
children 0ca00d547f35
comparison
equal deleted inserted replaced
2650:a6fa128e4654 2651:9e9eb9d97548
1 package de.intevation.flys.artifacts;
2
3 import java.util.List;
4
5 import org.apache.log4j.Logger;
6
7 import org.w3c.dom.Element;
8 import org.w3c.dom.Document;
9 import org.w3c.dom.Node;
10
11 import de.intevation.artifacts.CallContext;
12 import de.intevation.artifacts.common.utils.XMLUtils;
13 import de.intevation.artifacts.common.utils.XMLUtils.ElementCreator;
14 import de.intevation.artifacts.common.ArtifactNamespaceContext;
15
16 import de.intevation.artifactdatabase.ProtocolUtils;
17 import de.intevation.artifactdatabase.data.StateData;
18 import de.intevation.artifactdatabase.state.State;
19 import de.intevation.artifactdatabase.state.StateEngine;
20 import de.intevation.artifactdatabase.state.Output;
21 import de.intevation.artifactdatabase.transition.TransitionEngine;
22
23 import de.intevation.flys.artifacts.model.FacetTypes;
24 import de.intevation.flys.artifacts.context.FLYSContext;
25 import de.intevation.flys.artifacts.states.DefaultState;
26
27 import de.intevation.flys.utils.FLYSUtils;
28
29 /**
30 * The default fixation analysis artifact.
31 *
32 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
33 */
34 public class FixationArtifact
35 extends FLYSArtifact
36 implements FacetTypes {
37
38 /** The logger for this class. */
39 private static Logger logger = Logger.getLogger(FixationArtifact.class);
40
41 /** The name of the artifact. */
42 public static final String ARTIFACT_NAME = "fixanalysis";
43
44 /**
45 * The default constructor.
46 */
47 public FixationArtifact() {
48 }
49
50 /**
51 * Returns the name of the concrete artifact.
52 *
53 * @return the name of the concrete artifact.
54 */
55 public String getName() {
56 return ARTIFACT_NAME;
57 }
58
59 public Document describe(Document data, CallContext context) {
60 logger.debug("Describe: the current state is: " + getCurrentStateId());
61
62 if (logger.isDebugEnabled()) {
63 dumpArtifact();
64 }
65
66 FLYSContext flysContext = FLYSUtils.getFlysContext(context);
67
68 StateEngine stateEngine = (StateEngine) flysContext.get(
69 FLYSContext.STATE_ENGINE_KEY);
70
71 TransitionEngine transitionEngine = (TransitionEngine) flysContext.get(
72 FLYSContext.TRANSITION_ENGINE_KEY);
73
74 List<State> reachable = transitionEngine.getReachableStates(
75 this, getCurrentState(context), stateEngine);
76
77 Document description = XMLUtils.newDocument();
78 XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator(
79 description,
80 ArtifactNamespaceContext.NAMESPACE_URI,
81 ArtifactNamespaceContext.NAMESPACE_PREFIX);
82
83 Element root = ProtocolUtils.createRootNode(creator);
84 description.appendChild(root);
85
86 State current = getCurrentState(context);
87
88 ProtocolUtils.appendDescribeHeader(creator, root, identifier(), hash());
89 ProtocolUtils.appendState(creator, root, current);
90 ProtocolUtils.appendReachableStates(creator, root, reachable);
91
92 Element ui = ProtocolUtils.createArtNode(
93 creator, "ui", null, null);
94
95 Element staticUI = ProtocolUtils.createArtNode(
96 creator, "static", null, null);
97
98 Element outs = ProtocolUtils.createArtNode(
99 creator, "outputmodes", null, null);
100 appendOutputModes(description, outs, context, identifier());
101
102 appendStaticUI(description, staticUI, context, identifier());
103
104
105 Element name = ProtocolUtils.createArtNode(
106 creator, "name",
107 new String[] { "value" },
108 new String[] { getName() });
109
110 Element dynamic = current.describe(
111 this,
112 description,
113 root,
114 context,
115 identifier());
116
117 if (dynamic != null) {
118 ui.appendChild(dynamic);
119 }
120
121 ui.appendChild(staticUI);
122
123 root.appendChild(name);
124 root.appendChild(ui);
125 root.appendChild(outs);
126
127 return description;
128 }
129
130
131 /**
132 * Append output mode nodes to a document.
133 */
134 protected void appendOutputModes(
135 Document doc,
136 Element outs,
137 CallContext context,
138 String uuid)
139 {
140 List<Output> generated = getOutputs(context);
141 logger.debug("This Artifact has " + generated.size() + " Outputs.");
142
143 ProtocolUtils.appendOutputModes(doc, outs, generated);
144 }
145
146
147 /**
148 * This method appends the static data - that has already been inserted by
149 * the user - to the static node of the DESCRIBE document.
150 *
151 * @param doc The document.
152 * @param ui The root node.
153 * @param context The CallContext.
154 * @param uuid The identifier of the artifact.
155 */
156 protected void appendStaticUI(
157 Document doc,
158 Node ui,
159 CallContext context,
160 String uuid)
161 {
162 List<String> stateIds = getPreviousStateIds();
163
164 FLYSContext flysContext = FLYSUtils.getFlysContext(context);
165 StateEngine engine = (StateEngine) flysContext.get(
166 FLYSContext.STATE_ENGINE_KEY);
167
168 for (String stateId: stateIds) {
169 logger.debug("Append static data for state: " + stateId);
170 DefaultState state = (DefaultState) engine.getState(stateId);
171
172 ui.appendChild(state.describeStatic(this, doc, ui, context, uuid));
173 }
174 }
175
176 }

http://dive4elements.wald.intevation.org