comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/HYKArtifact.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 79044646f4eb
children c553d4fa3957
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.artifacts.Artifact;
11 import de.intevation.artifacts.ArtifactFactory;
12 import de.intevation.artifacts.CallMeta;
13
14 import de.intevation.artifacts.common.ArtifactNamespaceContext;
15 import de.intevation.artifacts.common.utils.XMLUtils;
16
17 import de.intevation.flys.artifacts.states.DefaultState;
18
19 import de.intevation.artifactdatabase.state.Facet;
20
21
22 /**
23 * Artifact to get hydr zones (HYKs).
24 */
25 public class HYKArtifact extends StaticFLYSArtifact {
26
27 /** Access ids of doc. */
28 public static final String XPATH_IDS = "/art:action/art:ids/@value";
29
30 /** Name of Artifact. */
31 public static final String HYK_ARTIFACT_NAME = "hyk";
32
33 /** Name of data item keeping the hyk id to load formations from. */
34 public static final String HYK_ID = "hyk_artifact.data.id";
35
36 /** Name of data item keeping the km of cs master. */
37 public static final String HYK_KM = "hyk_artifact.data.km";
38
39 /** Own logger. */
40 private static final Logger logger =
41 Logger.getLogger(HYKArtifact.class);
42
43
44 /** Return given name. */
45 @Override
46 public String getName() {
47 return HYK_ARTIFACT_NAME;
48 }
49
50
51 /** Store ids, do super.setup. */
52 @Override
53 public void setup(
54 String identifier,
55 ArtifactFactory factory,
56 Object context,
57 CallMeta callMeta,
58 Document data)
59 {
60 logger.info("HYKArtifact.setup");
61
62 String ids = XMLUtils.xpathString(
63 data, XPATH_IDS, ArtifactNamespaceContext.INSTANCE);
64
65 logger.info("HYKArtifact.setup: id is " + ids);
66
67 addStringData(HYK_ID, ids);
68
69 super.setup(identifier, factory, context, callMeta, data);
70 }
71
72
73 /** Set km as Data. */
74 public void setKm(double km) {
75 addStringData(HYK_KM, Double.toString(km));
76 }
77
78
79 /**
80 * Get a DataItem casted to double (0 if fails).
81 * TODO move to FlysArtifact.
82 */
83 public double getDataAsDouble(String dataName) {
84 String val = getDataAsString(dataName);
85 if (val == null) {
86 logger.warn("Data not available.");
87 return 0d;
88 }
89 try {
90 return Double.valueOf(val);
91 }
92 catch (NumberFormatException e) {
93 logger.warn("Could not get data " + dataName + " as double", e);
94 return 0;
95 }
96 }
97
98
99 /** Get km from state data. */
100 public double getKm() {
101 return getDataAsDouble(HYK_KM);
102 }
103
104
105 /** Get hyk-id from state data. */
106 public int getHykId() {
107 return getDataAsInteger(HYK_ID);
108 }
109
110
111 /** Do not copy data from daddyfact. */
112 @Override
113 protected void initialize(
114 Artifact artifact,
115 Object context,
116 CallMeta callMeta)
117 {
118 logger.debug("HYKArtifact.initialize");
119 WINFOArtifact winfo = (WINFOArtifact) artifact;
120 importData(winfo, "river");
121
122 List<Facet> fs = new ArrayList<Facet>();
123
124 DefaultState state = (DefaultState) getCurrentState(context);
125 state.computeInit(this, hash(), context, callMeta, fs);
126 if (!fs.isEmpty()) {
127 logger.debug("Facets to add in HYKArtifact.initialize .");
128 facets.put(getCurrentStateId(), fs);
129 }
130 else {
131 logger.debug("No facets to add in HYKArtifact.initialize ("
132 + state.getID() + ").");
133 }
134 }
135
136
137 /**
138 * Determines Facets initial disposition regarding activity (think of
139 * selection in Client ThemeList GUI). This will be checked one time
140 * when the facet enters a collections describe document.
141 *
142 * @param facetName name of the facet.
143 * @param index index of the facet.
144 *
145 * @return Always 0. Hyk Data will enter plots inactive.
146 */
147 @Override
148 public int getInitialFacetActivity(
149 String outputName,
150 String facetName,
151 int index)
152 {
153 return 0;
154 }
155 }
156 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org