comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/StaticWQKmsArtifact.java @ 3468:f37e7e8907cb

merged flys-artifacts/2.8.1
author Thomas Arendsen Hein <thomas@intevation.de>
date Fri, 28 Sep 2012 12:14:39 +0200
parents b0ba96bbf01d
children afc7bfb4800b
comparison
equal deleted inserted replaced
3387:5ffad8bde8ad 3468:f37e7e8907cb
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
10 import de.intevation.artifactdatabase.state.Facet;
11
12 import de.intevation.artifacts.Artifact;
13 import de.intevation.artifacts.ArtifactFactory;
14 import de.intevation.artifacts.CallMeta;
15
16 import de.intevation.artifacts.common.utils.XMLUtils;
17
18 import de.intevation.flys.artifacts.model.FacetTypes;
19 import de.intevation.flys.artifacts.model.WQKms;
20 import de.intevation.flys.artifacts.model.WKmsFactory;
21 import de.intevation.flys.artifacts.model.WQKmsFactory;
22
23 import de.intevation.flys.artifacts.states.DefaultState;
24
25
26 /**
27 * Artifact to access additional "waterlevel/discharge"-type of data, like
28 * fixation measurements.
29 *
30 * This artifact neglects (Static)FLYSArtifacts capabilities of interaction
31 * with the StateEngine by overriding the getState*-methods.
32 */
33 public class StaticWQKmsArtifact
34 extends StaticFLYSArtifact
35 implements FacetTypes
36 {
37 /** The logger for this class. */
38 private static Logger logger =
39 Logger.getLogger(StaticWQKmsArtifact.class);
40
41 public static final String STATIC_STATE_NAME =
42 "state.additional_wqkms.static";
43
44
45 /**
46 * Trivial Constructor.
47 */
48 public StaticWQKmsArtifact() {
49 logger.debug("StaticWQKmsArtifact.StaticWQKmsArtifact");
50 }
51
52
53 /**
54 * Gets called from factory, to set things up.
55 */
56 @Override
57 public void setup(
58 String identifier,
59 ArtifactFactory factory,
60 Object context,
61 CallMeta callMeta,
62 Document data)
63 {
64 logger.debug("StaticWQKmsArtifact.setup");
65
66 // Store the 'ids' (from datacage).
67 if (logger.isDebugEnabled()) {
68 logger.debug("StaticWQKmsArtiact.setup" + XMLUtils.toString(data));
69 }
70
71 String code = getDatacageIDValue(data);
72 addStringData("ids", code);
73 if (code != null) {
74 String [] parts = code.split("-");
75
76 if (parts.length >= 4) {
77 int col = Integer.parseInt(parts[2]);
78 int wst = Integer.parseInt(parts[3]);
79
80 addStringData("col_pos", parts[2]);
81 addStringData("wst_id", parts[3]);
82 }
83 }
84
85 // Do this AFTER we have set the col_pos etc.
86 super.setup(identifier, factory, context, callMeta, data);
87 }
88
89
90 /**
91 * Called via setup.
92 *
93 * @param artifact The master-artifact.
94 */
95 @Override
96 protected void initialize(
97 Artifact artifact,
98 Object context,
99 CallMeta meta)
100 {
101 logger.debug("StaticWQKmsArtifact.initialize");
102 WINFOArtifact winfo = (WINFOArtifact) artifact;
103 // TODO: The river is of no interest, so far., also use importData
104 importData(winfo, "river");
105
106 List<Facet> fs = new ArrayList<Facet>();
107
108 DefaultState state = (DefaultState) getCurrentState(context);
109 state.computeInit(this, hash(), context, meta, fs);
110 if (!fs.isEmpty()) {
111 logger.debug("Facets to add in StaticWQKmsArtifact.initialize .");
112 facets.put(getCurrentStateId(), fs);
113 }
114 else {
115 logger.debug("No facets to add in StaticWQKmsArtifact.initialize ("
116 + state.getID() + ").");
117 }
118 }
119
120
121 /**
122 * Get WQKms from factory.
123 * @return WQKms according to parameterization (can be null);
124 */
125 public WQKms getWQKms() {
126 logger.debug("StaticWQKmsArtifact.getWQKms");
127
128 int col = Integer.parseInt(getDataAsString("col_pos"));
129 int wst = Integer.parseInt(getDataAsString("wst_id"));
130
131 /** TODO do not run twice against db to do this. */
132 String wkmsName = WKmsFactory.getWKmsName(col, wst);
133
134 WQKms res = WQKmsFactory.getWQKms(col, wst);
135 res.setName(wkmsName);
136 return res;
137 }
138
139
140 /**
141 * Determines Facets initial disposition regarding activity (think of
142 * selection in Client ThemeList GUI). This will be checked one time
143 * when the facet enters a collections describe document.
144 *
145 * @param facetName name of the facet.
146 * @param index index of the facet.
147 *
148 * @return Always 0. Static Data will enter plots inactive.
149 */
150 @Override
151 public int getInitialFacetActivity(
152 String outputName,
153 String facetName,
154 int index)
155 {
156 return 0;
157 }
158
159
160 /** Return specific name. */
161 public String getName() {
162 return "staticwqkms";
163 }
164
165 // TODO implement deepCopy.
166 }
167 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org