comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/StaticWQKmsArtifact.java @ 3818:dc18457b1cef

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

http://dive4elements.wald.intevation.org