comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/MainValuesArtifact.java @ 1047:38088c982db6

Added stub implementation of new MainValuesArtifact. flys-artifacts/trunk@2509 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Fri, 19 Aug 2011 10:17:08 +0000
parents
children eccf966fb677
comparison
equal deleted inserted replaced
1046:0a5eff5511b1 1047:38088c982db6
1 package de.intevation.flys.artifacts;
2
3 import java.util.ArrayList;
4 import java.util.List;
5
6 import org.apache.log4j.Logger;
7
8 import org.w3c.dom.Document;
9 import org.w3c.dom.Element;
10 import org.w3c.dom.Node;
11
12 import de.intevation.artifacts.Artifact;
13 import de.intevation.artifacts.ArtifactFactory;
14 import de.intevation.artifacts.ArtifactNamespaceContext;
15 import de.intevation.artifacts.CallContext;
16 import de.intevation.artifacts.CallMeta;
17
18 import de.intevation.flys.artifacts.context.FLYSContext;
19
20 import de.intevation.flys.artifacts.states.DefaultState;
21 import de.intevation.artifactdatabase.ProtocolUtils;
22 import de.intevation.artifacts.Artifact;
23 import de.intevation.artifactdatabase.state.Facet;
24 import de.intevation.artifactdatabase.state.DefaultOutput;
25 import de.intevation.artifactdatabase.state.Output;
26 import de.intevation.artifactdatabase.state.DefaultFacet;
27 import de.intevation.artifacts.common.utils.XMLUtils;
28
29 /**
30 * Artifact to access names of Points Of Interest along a segment of a river.
31 */
32 public class MainValuesArtifact
33 extends StaticFLYSArtifact
34 implements Facet {
35
36 /** The logger for this class. */
37 private static Logger logger = Logger.getLogger(WINFOArtifact.class);
38
39 /** The name of the artifact. */
40 public static final String ARTIFACT_NAME = "annotation";
41
42 public MainValuesArtifact() {
43 logger.warn("MainValuesArtifact.MainValuesartifact()");
44 }
45
46 /**
47 * Gets called from factory, to set things up.
48 * Do nothing.
49 */
50 @Override
51 public void setup(
52 String identifier,
53 ArtifactFactory factory,
54 Object context,
55 CallMeta callMeta,
56 Document data)
57 {
58 logger.warn("MainValuesArtifact.setup");
59 ;
60 }
61
62 /**
63 * Create the description of this MainValuesArtiface-instance.
64 *
65 * @param data some data.
66 * @param context the CallContext.
67 *
68 * @return the description of this artifact.
69 */
70 @Override
71 public Document describe(Document data, CallContext context) {
72 logger.debug("MainValuesArtifact.describe");
73
74 if (logger.isDebugEnabled()) {
75 dumpArtifact();
76 }
77
78 FLYSContext flysContext = getFlysContext(context);
79
80 Document description = XMLUtils.newDocument();
81 XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator(
82 description,
83 ArtifactNamespaceContext.NAMESPACE_URI,
84 ArtifactNamespaceContext.NAMESPACE_PREFIX);
85
86 Element root = ProtocolUtils.createRootNode(creator);
87 description.appendChild(root);
88
89 ProtocolUtils.appendDescribeHeader(creator, root, identifier(), hash());
90
91 Element name = ProtocolUtils.createArtNode(
92 creator, "name",
93 new String[] { "value" },
94 new String[] { getName() });
95
96 Element outs = ProtocolUtils.createArtNode(
97 creator, "outputmodes", null, null);
98 appendOutputModes(description, outs, context);
99
100 root.appendChild(name);
101 root.appendChild(outs);
102
103 return description;
104 }
105
106
107 /**
108 * Append outputmode elements to given document.
109 *
110 * @param doc Document to add outputmodes to.
111 * @param outs Element to add outputmode elements to.
112 * @param context The given CallContext (mostly for internationalization).
113 */
114 protected void appendOutputModes(
115 Document doc,
116 Element outs,
117 CallContext context)
118 {
119 // TODO outputmodes
120 XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator(
121 doc,
122 ArtifactNamespaceContext.NAMESPACE_URI,
123 ArtifactNamespaceContext.NAMESPACE_PREFIX);
124
125 FLYSContext flysContext = getFlysContext(context);
126
127 for (int i = 0; i < 1; i++) {
128 logger.debug("Append output mode.");
129
130 // TODO create outputs.
131 /*
132 List<Output> list = state.getOutputs();
133 if (list == null || list.size() == 0) {
134 logger.debug("-> No output modes for this state.");
135 continue;
136 }*/
137 List<Facet> fs = new ArrayList<Facet>();
138 DefaultOutput mainValuesOutput = new DefaultOutput(
139 "discharge_curve", "output.discharge_curve", "image/png",
140 fs,
141 "chart");
142
143 // Create facets.
144 if (fs == null || fs.size() == 0) {
145 logger.debug("No facets found.");
146 continue;
147 }
148 logger.debug("Built stateless facets.");
149 // TODO remember issues here.
150 //List<Output> generated = generateOutputs(list, fs);
151 //ProtocolUtils.appendOutputModes(doc, outs, generated);
152 }
153
154 try {
155 DefaultState cur = (DefaultState) getCurrentState(context);
156 if (cur.validate(this, context)) {
157 List<Output> list = cur.getOutputs();
158 if (list != null && list.size() > 0) {
159 logger.debug(
160 "Append output modes for state: " + cur.getID());
161
162 List<Facet> fs = facets.get(cur.getID());
163 if (fs != null && fs.size() > 0) {
164 List<Output> generated = generateOutputs(list, fs);
165
166 logger.debug("Found " + fs.size() + " current facets.");
167 if (!generated.isEmpty()) {
168 ProtocolUtils.appendOutputModes(
169 doc, outs, generated);
170 }
171 else{
172 logger.debug("Cannot append output to generated document.");
173 }
174 }
175 else {
176 logger.debug("No facets found for the current state.");
177 }
178 }
179 }
180 }
181 catch (IllegalArgumentException iae) {
182 // state is not valid, so we do not append its outputs.
183 }
184 }
185
186
187 /* FACET IMPLEMENTATION */
188
189
190 // TODO implement; what is index used for?
191 /**
192 * Returns the index of this facet.
193 *
194 * @return the index of this facet.
195 */
196 public int getIndex() {
197 return 0;
198 }
199
200
201 /**
202 * Returns the name of this facet.
203 *
204 * @return the name of this facet.
205 */
206 public String getName() {
207 // TODO define, static
208 return "FACETNAME";
209 }
210
211
212 /**
213 * Returns the description of this facet.
214 *
215 * @return the description of this facet.
216 */
217 public String getDescription() {
218 return null;
219 }
220
221
222 /**
223 * Returns the data this facet requires.
224 *
225 * @param artifact The owner artifact.
226 * @param context The CallContext.
227 *
228 * @return the data.
229 */
230 public Object getData(Artifact artifact, CallContext context) {
231 return null;
232 }
233
234
235 /**
236 * Write the internal representation of a facet to a node.
237 *
238 * @param doc A Document.
239 *
240 * @return the representation as Node.
241 */
242 public Node toXML(Document doc) {
243 return null;
244 }
245
246 }

http://dive4elements.wald.intevation.org