comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/ChartArtifact.java @ 3193:2f922be407ea

Moved common code of the *Artifacts into FLYSArtifact. flys-artifacts/trunk@4809 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Wed, 27 Jun 2012 13:45:55 +0000
parents 4bd3d8bbb60c
children b1912514e0f5
comparison
equal deleted inserted replaced
3192:cd309f8597f6 3193:2f922be407ea
4 4
5 import java.util.List; 5 import java.util.List;
6 6
7 import org.w3c.dom.Document; 7 import org.w3c.dom.Document;
8 import org.w3c.dom.Element; 8 import org.w3c.dom.Element;
9 import org.w3c.dom.Node;
10 9
11 import de.intevation.artifacts.Artifact; 10 import de.intevation.artifacts.Artifact;
12 11
13 import de.intevation.artifacts.ArtifactFactory; 12 import de.intevation.artifacts.ArtifactFactory;
14 import de.intevation.artifacts.CallMeta; 13 import de.intevation.artifacts.CallMeta;
21 import de.intevation.artifactdatabase.ProtocolUtils; 20 import de.intevation.artifactdatabase.ProtocolUtils;
22 import de.intevation.artifactdatabase.state.Facet; 21 import de.intevation.artifactdatabase.state.Facet;
23 import de.intevation.artifactdatabase.state.State; 22 import de.intevation.artifactdatabase.state.State;
24 import de.intevation.artifactdatabase.state.StateEngine; 23 import de.intevation.artifactdatabase.state.StateEngine;
25 import de.intevation.artifactdatabase.state.Output; 24 import de.intevation.artifactdatabase.state.Output;
26 import de.intevation.artifactdatabase.transition.TransitionEngine;
27 25
28 import de.intevation.flys.utils.FLYSUtils; 26 import de.intevation.flys.utils.FLYSUtils;
29 27
30 import de.intevation.flys.artifacts.states.DefaultState; 28 import de.intevation.flys.artifacts.states.DefaultState;
31 import de.intevation.flys.artifacts.context.FLYSContext; 29 import de.intevation.flys.artifacts.context.FLYSContext;
52 List<State> states = getStates(context); 50 List<State> states = getStates(context);
53 51
54 setCurrentState(states.get(0)); 52 setCurrentState(states.get(0));
55 } 53 }
56 54
57
58 @Override 55 @Override
59 public Document describe(Document data, CallContext context) { 56 protected void appendBackgroundActivity(
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 appendBackgroundActivity(creator, root, context);
93
94 Element name = ProtocolUtils.createArtNode(
95 creator, "name",
96 new String[] { "value" },
97 new String[] { getName() });
98
99 Element ui = ProtocolUtils.createArtNode(
100 creator, "ui", null, null);
101
102 Element staticUI = ProtocolUtils.createArtNode(
103 creator, "static", null, null);
104
105 Element outs = ProtocolUtils.createArtNode(
106 creator, "outputmodes", null, null);
107 appendOutputModes(description, outs, context, identifier());
108
109 appendStaticUI(description, staticUI, context, identifier());
110
111 Element dynamic = current.describe(
112 this,
113 description,
114 root,
115 context,
116 identifier());
117
118 if (dynamic != null) {
119 ui.appendChild(dynamic);
120 }
121
122 ui.appendChild(staticUI);
123
124 root.appendChild(name);
125 root.appendChild(ui);
126 root.appendChild(outs);
127
128 return description;
129
130 }
131
132
133 protected static void appendBackgroundActivity(
134 ElementCreator cr, 57 ElementCreator cr,
135 Element root, 58 Element root,
136 CallContext context 59 CallContext context
137 ) { 60 ) {
138 Element inBackground = cr.create("background-processing"); 61 Element inBackground = cr.create("background-processing");
147 70
148 71
149 /** 72 /**
150 * Append output mode nodes to a document. 73 * Append output mode nodes to a document.
151 */ 74 */
75 @Override
152 protected void appendOutputModes( 76 protected void appendOutputModes(
153 Document doc, 77 Document doc,
154 Element outs, 78 Element outs,
155 CallContext context, 79 CallContext context,
156 String uuid) 80 String uuid)
216 catch (IllegalArgumentException iae) { 140 catch (IllegalArgumentException iae) {
217 // state is not valid, so we do not append its outputs. 141 // state is not valid, so we do not append its outputs.
218 } 142 }
219 } 143 }
220 144
221
222 /**
223 * This method appends the static data - that has already been inserted by
224 * the user - to the static node of the DESCRIBE document.
225 *
226 * @param doc The document.
227 * @param ui The root node.
228 * @param context The CallContext.
229 * @param uuid The identifier of the artifact.
230 */
231 protected void appendStaticUI(
232 Document doc,
233 Node ui,
234 CallContext context,
235 String uuid)
236 {
237 List<String> stateIds = getPreviousStateIds();
238
239 logger.debug("previous states: " + stateIds);
240 FLYSContext flysContext = FLYSUtils.getFlysContext(context);
241 StateEngine engine = (StateEngine) flysContext.get(
242 FLYSContext.STATE_ENGINE_KEY);
243
244 for (String stateId: stateIds) {
245 logger.debug("Append static data for state: " + stateId);
246 DefaultState state = (DefaultState) engine.getState(stateId);
247
248 ui.appendChild(state.describeStatic(this, doc, ui, context, uuid));
249 }
250 }
251
252
253 public static class ChartState extends DefaultState { 145 public static class ChartState extends DefaultState {
254 146
255 public static final String FIELD_MODE = "chart_type"; 147 public static final String FIELD_MODE = "chart_type";
256 148
257 public static final String DURATION_CURVE = 149 public static final String DURATION_CURVE =

http://dive4elements.wald.intevation.org