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