comparison artifacts/src/main/java/org/dive4elements/river/artifacts/FlowVelocityMeasurementArtifact.java @ 5838:5aa05a7a34b7

Rename modules to more fitting names.
author Sascha L. Teichmann <teichmann@intevation.de>
date Thu, 25 Apr 2013 15:23:37 +0200
parents flys-artifacts/src/main/java/org/dive4elements/river/artifacts/FlowVelocityMeasurementArtifact.java@bd047b71ab37
children 4897a58c8746
comparison
equal deleted inserted replaced
5837:d9901a08d0a6 5838:5aa05a7a34b7
1 package org.dive4elements.river.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 org.dive4elements.artifactdatabase.state.DefaultOutput;
10 import org.dive4elements.artifactdatabase.state.Facet;
11 import org.dive4elements.artifactdatabase.state.FacetActivity;
12 import org.dive4elements.artifactdatabase.state.State;
13 import org.dive4elements.artifacts.Artifact;
14 import org.dive4elements.artifacts.ArtifactFactory;
15 import org.dive4elements.artifacts.CallMeta;
16 import org.dive4elements.artifacts.common.utils.XMLUtils;
17 import org.dive4elements.river.model.FlowVelocityMeasurementValue;
18 import org.dive4elements.river.artifacts.model.minfo.FlowVelocityMeasurementFacet;
19 import org.dive4elements.river.artifacts.model.minfo.FlowVelocityMeasurementFactory;
20 import org.dive4elements.river.artifacts.states.StaticState;
21
22 import org.dive4elements.river.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 protected String DATA_NAME = "ID";
52
53 /**
54 * Trivial Constructor.
55 */
56 public FlowVelocityMeasurementArtifact() {
57 logger.debug("FlowVelocityMeasurementArtifact.FlowVelocityMeasurementArtifact");
58 }
59
60
61 /** Get artifact key name. */
62 @Override
63 public String getName() {
64 return NAME;
65 }
66
67
68 /** Create a new state with bogus output. */
69 protected State spawnState() {
70 state = new StaticState(STATIC_STATE_NAME);
71 List<Facet> fs = getFacets(STATIC_STATE_NAME);
72 DefaultOutput output = new DefaultOutput(
73 "general",
74 "general",
75 "image/png",
76 fs,
77 "chart");
78
79 state.getOutputs().add(output);
80
81 return state;
82 }
83
84
85 /**
86 * Gets called from factory, to set things up.
87 */
88 @Override
89 public void setup(
90 String identifier,
91 ArtifactFactory factory,
92 Object context,
93 CallMeta callMeta,
94 Document data)
95 {
96 logger.debug("FlowVelocityMeasurementArtifact.setup");
97
98 state = new StaticState(STATIC_STATE_NAME);
99
100 if (logger.isDebugEnabled()) {
101 logger.debug(XMLUtils.toString(data));
102 }
103
104 List<Facet> fs = new ArrayList<Facet>();
105 String code = getDatacageIDValue(data);
106
107 if (code != null) {
108 // parse code, interact with factory, add real facets.
109 // store relevant parts of code as data.
110 Facet facet = new FlowVelocityMeasurementFacet(
111 FLOW_VELOCITY_MEASUREMENT,
112 "flowvelocity-name");
113 fs.add(facet);
114 addFacets(state.getID(), fs);
115 addStringData(DATA_NAME, code);
116 }
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
185 /** Get the db-unbound flow velocity measurement value with given
186 * id. */
187 public FlowVelocityMeasurementValue.FastFlowVelocityMeasurementValue
188 getFlowVelocityMeasurementValue()
189 {
190 return FlowVelocityMeasurementFactory.getFlowVelocityMeasurement(
191 Integer.parseInt(getDataAsString(DATA_NAME)));
192 }
193 }
194 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org