Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/FixationArtifact.java @ 2793:6310b1582f2d
merged flys-artifacts/2.7
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Fri, 28 Sep 2012 12:14:30 +0200 |
parents | 306b9d0f0fb3 |
children | 2f922be407ea |
comparison
equal
deleted
inserted
replaced
2548:ada02bbd3b7f | 2793:6310b1582f2d |
---|---|
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.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 | |
28 /** | |
29 * The default fixation analysis artifact. | |
30 * | |
31 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> | |
32 */ | |
33 public class FixationArtifact | |
34 extends FLYSArtifact | |
35 implements FacetTypes { | |
36 | |
37 /** The logger for this class. */ | |
38 private static Logger logger = Logger.getLogger(FixationArtifact.class); | |
39 | |
40 /** The name of the artifact. */ | |
41 public static final String ARTIFACT_NAME = "fixanalysis"; | |
42 | |
43 /** | |
44 * The default constructor. | |
45 */ | |
46 public FixationArtifact() { | |
47 } | |
48 | |
49 /** | |
50 * Returns the name of the concrete artifact. | |
51 * | |
52 * @return the name of the concrete artifact. | |
53 */ | |
54 public String getName() { | |
55 return ARTIFACT_NAME; | |
56 } | |
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 } | |
176 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |