comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/FlowVelocityMeasurementArtifact.java @ 4452:bdf321802d3d

Add FlowVelocityMeasurementArtifact and -facet. Yet dummies.
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Thu, 08 Nov 2012 16:50:46 +0100
parents
children b66285ece774
comparison
equal deleted inserted replaced
4451:e2d8f344491e 4452:bdf321802d3d
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 import org.w3c.dom.Document;
8
9 import de.intevation.artifactdatabase.state.DefaultOutput;
10 import de.intevation.artifactdatabase.state.Facet;
11 import de.intevation.artifactdatabase.state.FacetActivity;
12 import de.intevation.artifactdatabase.state.State;
13 import de.intevation.artifacts.Artifact;
14 import de.intevation.artifacts.ArtifactFactory;
15 import de.intevation.artifacts.CallMeta;
16 import de.intevation.artifacts.common.utils.XMLUtils;
17 import de.intevation.flys.model.FlowVelocityMeasurement;
18 import de.intevation.flys.artifacts.model.minfo.FlowVelocityMeasurementFacet;
19 import de.intevation.flys.artifacts.model.minfo.FlowVelocityMeasurementFactory;
20 import de.intevation.flys.artifacts.states.StaticState;
21
22 import de.intevation.flys.artifacts.model.FacetTypes;
23
24
25 /** Artefact to access flow velocity measurements. */
26 public class FlowVelocityMeasurementArtifact
27 extends StaticFLYSArtifact
28 implements FacetTypes
29 {
30 /** The logger for this class. */
31 private static Logger logger =
32 Logger.getLogger(FlowVelocityMeasurementArtifact.class);
33
34 /** Artifact key name. */
35 private static final String NAME = "flowvelocitymeasurement";
36
37 /** Spawn only inactive facets. */
38 static {
39 // TODO: Move to configuration.
40 FacetActivity.Registry.getInstance()
41 .register(NAME, FacetActivity.INACTIVE);
42 }
43
44 /** Need to give the state an id. */
45 public static final String STATIC_STATE_NAME =
46 "state.flowvelocitymeasurement.static";
47
48 /** One and only state to be in. */
49 protected transient State state = null;
50
51
52 /**
53 * Trivial Constructor.
54 */
55 public FlowVelocityMeasurementArtifact() {
56 logger.debug("FlowVelocityMeasurementArtifact.FlowVelocityMeasurementArtifact");
57 }
58
59
60 /** Get artifact key name. */
61 @Override
62 public String getName() {
63 return NAME;
64 }
65
66
67 /** Create a new state with bogus output. */
68 protected State spawnState() {
69 state = new StaticState(STATIC_STATE_NAME);
70 List<Facet> fs = facets.get(STATIC_STATE_NAME);
71 DefaultOutput output = new DefaultOutput(
72 "general",
73 "general",
74 "image/png",
75 fs,
76 "chart");
77
78 state.getOutputs().add(output);
79
80 return state;
81 }
82
83
84 /**
85 * Gets called from factory, to set things up.
86 */
87 @Override
88 public void setup(
89 String identifier,
90 ArtifactFactory factory,
91 Object context,
92 CallMeta callMeta,
93 Document data)
94 {
95 logger.debug("FlowVelocityMeasurementArtifact.setup");
96
97 state = new StaticState(STATIC_STATE_NAME);
98
99 if (logger.isDebugEnabled()) {
100 logger.debug(XMLUtils.toString(data));
101 }
102
103 List<Facet> fs = new ArrayList<Facet>();
104 String code = getDatacageIDValue(data);
105
106 if (code != null) {
107 // parse code, interact with factory, add real facets.
108 // store relevant parts of code as data.
109 }
110
111 Facet facet = new FlowVelocityMeasurementFacet(
112 FLOW_VELOCITY_MEASUREMENT,
113 "flowvelocity-name");
114
115 fs.add(facet);
116 facets.put(state.getID(), fs);
117
118 spawnState();
119 super.setup(identifier, factory, context, callMeta, data);
120 }
121
122
123 /**
124 * Get a list containing the one and only State.
125 * @param context ignored.
126 * @return list with one and only state.
127 */
128 @Override
129 protected List<State> getStates(Object context) {
130 ArrayList<State> states = new ArrayList<State>();
131 states.add(getState());
132 return states;
133 }
134
135
136 /**
137 * Get the "current" state (there is but one).
138 * @param cc ignored.
139 * @return the "current" (only possible) state.
140 */
141 @Override
142 public State getCurrentState(Object cc) {
143 return getState();
144 }
145
146
147 /**
148 * Get the only possible state.
149 * @return the state.
150 */
151 protected State getState() {
152 return getState(null, null);
153 }
154
155
156 /**
157 * Get the state.
158 * @param context ignored.
159 * @param stateID ignored.
160 * @return the state.
161 */
162 @Override
163 protected State getState(Object context, String stateID) {
164 return (state != null)
165 ? state
166 : spawnState();
167 }
168
169
170 /**
171 * Called via setup. Overridden to avoid cloning all data.
172 *
173 * @param artifact The master-artifact.
174 */
175 @Override
176 protected void initialize(
177 Artifact artifact,
178 Object context,
179 CallMeta meta)
180 {
181 logger.debug("initialize");
182 }
183 }
184 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org