Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/SedimentYieldArtifact.java @ 7182:87c32adb7088
Initial commit for untested standalone sediment yield artifact.
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Thu, 26 Sep 2013 22:03:27 +0200 |
parents | |
children | 644b2f461272 |
comparison
equal
deleted
inserted
replaced
7181:805021c04861 | 7182:87c32adb7088 |
---|---|
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde | |
2 * Software engineering by Intevation GmbH | |
3 * | |
4 * This file is Free Software under the GNU AGPL (>=v3) | |
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the | |
6 * documentation coming with Dive4Elements River for details. | |
7 */ | |
8 | |
9 package org.dive4elements.river.artifacts; | |
10 | |
11 import java.util.ArrayList; | |
12 import java.util.List; | |
13 | |
14 import org.apache.log4j.Logger; | |
15 import org.w3c.dom.Document; | |
16 | |
17 import org.dive4elements.artifactdatabase.state.DefaultOutput; | |
18 import org.dive4elements.artifactdatabase.state.Facet; | |
19 import org.dive4elements.artifactdatabase.state.FacetActivity; | |
20 import org.dive4elements.artifactdatabase.state.State; | |
21 import org.dive4elements.artifacts.Artifact; | |
22 import org.dive4elements.artifacts.ArtifactFactory; | |
23 import org.dive4elements.artifacts.CallMeta; | |
24 import org.dive4elements.artifacts.common.utils.XMLUtils; | |
25 import org.dive4elements.river.artifacts.states.DefaultState.ComputeType; | |
26 import org.dive4elements.river.artifacts.model.minfo.SedimentLoad; | |
27 import org.dive4elements.river.artifacts.model.minfo.SedimentLoadFacet; | |
28 import org.dive4elements.river.artifacts.model.minfo.SedimentLoadFactory; | |
29 import org.dive4elements.river.artifacts.states.StaticState; | |
30 | |
31 import org.dive4elements.river.artifacts.model.FacetTypes; | |
32 | |
33 import org.dive4elements.river.utils.Formatter; | |
34 | |
35 | |
36 /** Artifact to access sediment yield measurements (inspired from flow velocity artifact). */ | |
37 public class SedimentYieldArtifact | |
38 extends StaticD4EArtifact | |
39 implements FacetTypes | |
40 { | |
41 /** The logger for this class. */ | |
42 private static Logger logger = | |
43 Logger.getLogger(SedimentYieldArtifact.class); | |
44 | |
45 /** Artifact key name. */ | |
46 private static final String NAME = "sedimentyield"; | |
47 | |
48 /** Spawn only inactive facets. */ | |
49 static { | |
50 // TODO: Move to configuration. | |
51 FacetActivity.Registry.getInstance() | |
52 .register(NAME, FacetActivity.INACTIVE); | |
53 } | |
54 | |
55 /** Need to give the state an id. */ | |
56 public static final String STATIC_STATE_NAME = | |
57 "state.sedimentyield.static"; | |
58 | |
59 /** One and only state to be in. */ | |
60 protected transient State state = null; | |
61 | |
62 protected String DATA_NAME = "ID"; | |
63 | |
64 /** | |
65 * Trivial Constructor. | |
66 */ | |
67 public SedimentYieldArtifact() { | |
68 logger.debug("SedimentYieldArtifact.SedimentYieldArtifact"); | |
69 } | |
70 | |
71 | |
72 /** Get artifact key name. */ | |
73 @Override | |
74 public String getName() { | |
75 return NAME; | |
76 } | |
77 | |
78 | |
79 /** Create a new state with bogus output. */ | |
80 protected State spawnState() { | |
81 state = new StaticState(STATIC_STATE_NAME); | |
82 List<Facet> fs = getFacets(STATIC_STATE_NAME); | |
83 DefaultOutput output = new DefaultOutput( | |
84 "general", | |
85 "general", | |
86 "image/png", | |
87 fs, | |
88 "chart"); | |
89 | |
90 state.getOutputs().add(output); | |
91 | |
92 return state; | |
93 } | |
94 | |
95 | |
96 /** | |
97 * Gets called from factory, to set things up. | |
98 */ | |
99 @Override | |
100 public void setup( | |
101 String identifier, | |
102 ArtifactFactory factory, | |
103 Object context, | |
104 CallMeta callMeta, | |
105 Document data) | |
106 { | |
107 logger.debug("SedimentYieldArtifact.setup"); | |
108 | |
109 // Store id, yield yields. | |
110 state = new StaticState(STATIC_STATE_NAME); | |
111 | |
112 if (logger.isDebugEnabled()) { | |
113 logger.debug(XMLUtils.toString(data)); | |
114 } | |
115 | |
116 List<Facet> fs = new ArrayList<Facet>(); | |
117 String code = getDatacageIDValue(data); | |
118 | |
119 // TODO need river, too. | |
120 // | |
121 if (code != null) { | |
122 // parse code, interact with factory, add real facets. | |
123 // store relevant parts of code as data. | |
124 // TODO no fakes | |
125 String fakeRiver = "Elbe"; | |
126 SedimentLoad myLoad = SedimentLoadFactory.getSedimentLoadWithDataUncached(code, fakeRiver); | |
127 String name = myLoad.getDescription(); | |
128 | |
129 Facet facet = new SedimentLoadFacet( | |
130 0, name, | |
131 SEDIMENT_LOAD_COARSE, | |
132 //???? | |
133 ComputeType.ADVANCE, state.getID(), "hash" | |
134 ); | |
135 fs.add(facet); | |
136 addFacets(state.getID(), fs); | |
137 addStringData(DATA_NAME, code); | |
138 } | |
139 | |
140 spawnState(); | |
141 super.setup(identifier, factory, context, callMeta, data); | |
142 } | |
143 | |
144 | |
145 /** | |
146 * Get a list containing the one and only State. | |
147 * @param context ignored. | |
148 * @return list with one and only state. | |
149 */ | |
150 @Override | |
151 protected List<State> getStates(Object context) { | |
152 ArrayList<State> states = new ArrayList<State>(); | |
153 states.add(getState()); | |
154 return states; | |
155 } | |
156 | |
157 | |
158 /** | |
159 * Get the "current" state (there is but one). | |
160 * @param cc ignored. | |
161 * @return the "current" (only possible) state. | |
162 */ | |
163 @Override | |
164 public State getCurrentState(Object cc) { | |
165 return getState(); | |
166 } | |
167 | |
168 | |
169 /** | |
170 * Get the only possible state. | |
171 * @return the state. | |
172 */ | |
173 protected State getState() { | |
174 return getState(null, null); | |
175 } | |
176 | |
177 | |
178 /** | |
179 * Get the state. | |
180 * @param context ignored. | |
181 * @param stateID ignored. | |
182 * @return the state. | |
183 */ | |
184 @Override | |
185 protected State getState(Object context, String stateID) { | |
186 return (state != null) | |
187 ? state | |
188 : spawnState(); | |
189 } | |
190 | |
191 | |
192 /** | |
193 * Called via setup. Overridden to avoid cloning all data. | |
194 * | |
195 * @param artifact The master-artifact. | |
196 */ | |
197 @Override | |
198 protected void initialize( | |
199 Artifact artifact, | |
200 Object context, | |
201 CallMeta meta) | |
202 { | |
203 logger.debug("initialize"); | |
204 // TODO Copy river data! | |
205 } | |
206 } | |
207 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : |