Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/StaticWQKmsArtifact.java @ 3651:06a65baae494
merged flys-artifacts/2.9
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Fri, 28 Sep 2012 12:14:43 +0200 |
parents | afc7bfb4800b |
children | a2735a4bf75e |
comparison
equal
deleted
inserted
replaced
3549:6a8f83c538e3 | 3651:06a65baae494 |
---|---|
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 import de.intevation.artifactdatabase.state.FacetActivity; | |
12 | |
13 import de.intevation.artifacts.Artifact; | |
14 import de.intevation.artifacts.ArtifactFactory; | |
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 public static final String STATIC_STATE_NAME = | |
43 "state.additional_wqkms.static"; | |
44 | |
45 private static final String NAME = "staticwqkms"; | |
46 | |
47 static { | |
48 // TODO: Move to configuration. | |
49 FacetActivity.Registry.getInstance() | |
50 .register(NAME, FacetActivity.INACTIVE); | |
51 } | |
52 | |
53 /** | |
54 * Trivial Constructor. | |
55 */ | |
56 public StaticWQKmsArtifact() { | |
57 logger.debug("StaticWQKmsArtifact.StaticWQKmsArtifact"); | |
58 } | |
59 | |
60 | |
61 /** | |
62 * Gets called from factory, to set things up. | |
63 */ | |
64 @Override | |
65 public void setup( | |
66 String identifier, | |
67 ArtifactFactory factory, | |
68 Object context, | |
69 CallMeta callMeta, | |
70 Document data) | |
71 { | |
72 logger.debug("StaticWQKmsArtifact.setup"); | |
73 | |
74 // Store the 'ids' (from datacage). | |
75 if (logger.isDebugEnabled()) { | |
76 logger.debug("StaticWQKmsArtiact.setup" + XMLUtils.toString(data)); | |
77 } | |
78 | |
79 String code = getDatacageIDValue(data); | |
80 addStringData("ids", code); | |
81 if (code != null) { | |
82 String [] parts = code.split("-"); | |
83 | |
84 if (parts.length >= 4) { | |
85 int col = Integer.parseInt(parts[2]); | |
86 int wst = Integer.parseInt(parts[3]); | |
87 | |
88 addStringData("col_pos", parts[2]); | |
89 addStringData("wst_id", parts[3]); | |
90 } | |
91 } | |
92 | |
93 // Do this AFTER we have set the col_pos etc. | |
94 super.setup(identifier, factory, context, callMeta, data); | |
95 } | |
96 | |
97 | |
98 /** | |
99 * Called via setup. | |
100 * | |
101 * @param artifact The master-artifact. | |
102 */ | |
103 @Override | |
104 protected void initialize( | |
105 Artifact artifact, | |
106 Object context, | |
107 CallMeta meta) | |
108 { | |
109 logger.debug("StaticWQKmsArtifact.initialize"); | |
110 WINFOArtifact winfo = (WINFOArtifact) artifact; | |
111 // TODO: The river is of no interest, so far., also use importData | |
112 importData(winfo, "river"); | |
113 | |
114 List<Facet> fs = new ArrayList<Facet>(); | |
115 | |
116 DefaultState state = (DefaultState) getCurrentState(context); | |
117 state.computeInit(this, hash(), context, meta, fs); | |
118 if (!fs.isEmpty()) { | |
119 logger.debug("Facets to add in StaticWQKmsArtifact.initialize ."); | |
120 facets.put(getCurrentStateId(), fs); | |
121 } | |
122 else { | |
123 logger.debug("No facets to add in StaticWQKmsArtifact.initialize (" | |
124 + state.getID() + ")."); | |
125 } | |
126 } | |
127 | |
128 | |
129 /** | |
130 * Get WQKms from factory. | |
131 * @return WQKms according to parameterization (can be null); | |
132 */ | |
133 public WQKms getWQKms() { | |
134 logger.debug("StaticWQKmsArtifact.getWQKms"); | |
135 | |
136 int col = Integer.parseInt(getDataAsString("col_pos")); | |
137 int wst = Integer.parseInt(getDataAsString("wst_id")); | |
138 | |
139 /** TODO do not run twice against db to do this. */ | |
140 String wkmsName = WKmsFactory.getWKmsName(col, wst); | |
141 | |
142 WQKms res = WQKmsFactory.getWQKms(col, wst); | |
143 res.setName(wkmsName); | |
144 return res; | |
145 } | |
146 | |
147 /** Return specific name. */ | |
148 @Override | |
149 public String getName() { | |
150 return NAME; | |
151 } | |
152 | |
153 // TODO implement deepCopy. | |
154 } | |
155 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : |