annotate flys-artifacts/src/main/java/de/intevation/flys/artifacts/GaugeDischargeCurveArtifact.java @ 4154:92021091b03d

Avoid another possible NullPointerException in GaugeTree
author Björn Ricks <bjoern.ricks@intevation.de>
date Tue, 16 Oct 2012 14:42:51 +0200
parents 46c1210be26b
children bbae306fcb4f 1755a1bfe5ce
rev   line source
3936
4e1b3b4ef132 Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
1 package de.intevation.flys.artifacts;
4e1b3b4ef132 Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
2
4e1b3b4ef132 Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
3 import java.util.ArrayList;
4e1b3b4ef132 Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
4 import java.util.List;
4e1b3b4ef132 Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
5
4e1b3b4ef132 Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
6 import org.apache.log4j.Logger;
4e1b3b4ef132 Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
7
4e1b3b4ef132 Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
8 import org.w3c.dom.Document;
4e1b3b4ef132 Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
9
4e1b3b4ef132 Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
10 import de.intevation.artifactdatabase.state.DefaultOutput;
4e1b3b4ef132 Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
11 import de.intevation.artifactdatabase.state.Facet;
4034
46c1210be26b Set translated data descriptions
Björn Ricks <bjoern.ricks@intevation.de>
parents: 4032
diff changeset
12 import de.intevation.artifactdatabase.data.DefaultStateData;
3936
4e1b3b4ef132 Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
13
4e1b3b4ef132 Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
14 import de.intevation.artifacts.ArtifactFactory;
4e1b3b4ef132 Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
15 import de.intevation.artifacts.CallMeta;
4e1b3b4ef132 Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
16
4e1b3b4ef132 Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
17 import de.intevation.artifacts.common.ArtifactNamespaceContext;
4e1b3b4ef132 Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
18 import de.intevation.artifacts.common.utils.XMLUtils;
4e1b3b4ef132 Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
19
4032
a5e1ca620f15 Add description and set correct name for GaugeDischargeCurveFacet
Björn Ricks <bjoern.ricks@intevation.de>
parents: 4028
diff changeset
20 import de.intevation.flys.artifacts.model.GaugeDischargeCurveFacet;
a5e1ca620f15 Add description and set correct name for GaugeDischargeCurveFacet
Björn Ricks <bjoern.ricks@intevation.de>
parents: 4028
diff changeset
21 import de.intevation.flys.artifacts.resources.Resources;
3936
4e1b3b4ef132 Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
22 import de.intevation.flys.artifacts.states.StaticState;
4032
a5e1ca620f15 Add description and set correct name for GaugeDischargeCurveFacet
Björn Ricks <bjoern.ricks@intevation.de>
parents: 4028
diff changeset
23
a5e1ca620f15 Add description and set correct name for GaugeDischargeCurveFacet
Björn Ricks <bjoern.ricks@intevation.de>
parents: 4028
diff changeset
24 import de.intevation.flys.model.Gauge;
a5e1ca620f15 Add description and set correct name for GaugeDischargeCurveFacet
Björn Ricks <bjoern.ricks@intevation.de>
parents: 4028
diff changeset
25 import de.intevation.flys.utils.FLYSUtils;
3936
4e1b3b4ef132 Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
26
4e1b3b4ef132 Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
27
4e1b3b4ef132 Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
28 /**
4e1b3b4ef132 Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
29 * Artifact to calculate a discharge curve from a gauge overview info
4e1b3b4ef132 Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
30 *
4e1b3b4ef132 Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
31 * @author <a href="mailto:bjoern.ricks@intevation.de">Björn Ricks</a>
4e1b3b4ef132 Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
32 */
4e1b3b4ef132 Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
33 public class GaugeDischargeCurveArtifact
4e1b3b4ef132 Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
34 extends AbstractStaticStateArtifact
4e1b3b4ef132 Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
35 {
4e1b3b4ef132 Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
36
4e1b3b4ef132 Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
37 private static final Logger logger =
4e1b3b4ef132 Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
38 Logger.getLogger(GaugeDischargeCurveArtifact.class);
4e1b3b4ef132 Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
39
4027
21cac9482958 Fix xpath for attributes
Björn Ricks <bjoern.ricks@intevation.de>
parents: 3991
diff changeset
40 public static final String XPATH_RIVER = "/art:action/art:river/@art:name";
21cac9482958 Fix xpath for attributes
Björn Ricks <bjoern.ricks@intevation.de>
parents: 3991
diff changeset
41 public static final String XPATH_GAUGE = "/art:action/art:gauge/@art:reference";
3936
4e1b3b4ef132 Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
42 public static final String NAME = "gaugedischargecurve";
4e1b3b4ef132 Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
43 public static final String STATIC_STATE_NAME = "state.gaugedischargecurve.static";
4e1b3b4ef132 Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
44
4e1b3b4ef132 Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
45 /**
4e1b3b4ef132 Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
46 * Setup initializes the data by extracting the river and gauge from
4e1b3b4ef132 Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
47 * the XML Document.
4e1b3b4ef132 Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
48 */
4e1b3b4ef132 Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
49 @Override
4e1b3b4ef132 Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
50 public void setup(
4e1b3b4ef132 Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
51 String identifier,
4e1b3b4ef132 Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
52 ArtifactFactory factory,
4e1b3b4ef132 Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
53 Object context,
4e1b3b4ef132 Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
54 CallMeta callmeta,
4e1b3b4ef132 Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
55 Document data)
4e1b3b4ef132 Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
56 {
4e1b3b4ef132 Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
57 logger.debug("GaugeDischargeCurveArtifact.setup");
4e1b3b4ef132 Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
58
4e1b3b4ef132 Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
59 if (logger.isDebugEnabled()) {
4028
b993d328f8b0 Improve debug output
Björn Ricks <bjoern.ricks@intevation.de>
parents: 4027
diff changeset
60 logger.debug("GaugeDischargeCurveArtifact.setup" + XMLUtils.toString(data));
3936
4e1b3b4ef132 Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
61 }
4e1b3b4ef132 Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
62 String gaugeref = XMLUtils.xpathString(data, XPATH_GAUGE,
4e1b3b4ef132 Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
63 ArtifactNamespaceContext.INSTANCE);
4e1b3b4ef132 Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
64 String rivername = XMLUtils.xpathString(data, XPATH_RIVER,
4e1b3b4ef132 Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
65 ArtifactNamespaceContext.INSTANCE);
4e1b3b4ef132 Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
66
4034
46c1210be26b Set translated data descriptions
Björn Ricks <bjoern.ricks@intevation.de>
parents: 4032
diff changeset
67 addData("river", new DefaultStateData("river",
46c1210be26b Set translated data descriptions
Björn Ricks <bjoern.ricks@intevation.de>
parents: 4032
diff changeset
68 Resources.getMsg(callmeta,
46c1210be26b Set translated data descriptions
Björn Ricks <bjoern.ricks@intevation.de>
parents: 4032
diff changeset
69 "facet.gauge_discharge_curve.river",
46c1210be26b Set translated data descriptions
Björn Ricks <bjoern.ricks@intevation.de>
parents: 4032
diff changeset
70 "Name of the river"),
46c1210be26b Set translated data descriptions
Björn Ricks <bjoern.ricks@intevation.de>
parents: 4032
diff changeset
71 "String", rivername));
46c1210be26b Set translated data descriptions
Björn Ricks <bjoern.ricks@intevation.de>
parents: 4032
diff changeset
72 addData("reference_gauge", new DefaultStateData("reference_gauge",
46c1210be26b Set translated data descriptions
Björn Ricks <bjoern.ricks@intevation.de>
parents: 4032
diff changeset
73 Resources.getMsg(callmeta,
46c1210be26b Set translated data descriptions
Björn Ricks <bjoern.ricks@intevation.de>
parents: 4032
diff changeset
74 "facet.gauge_discharge_curve.reference_gauge",
46c1210be26b Set translated data descriptions
Björn Ricks <bjoern.ricks@intevation.de>
parents: 4032
diff changeset
75 "Gauge official number"),
46c1210be26b Set translated data descriptions
Björn Ricks <bjoern.ricks@intevation.de>
parents: 4032
diff changeset
76 "Double", gaugeref));
3936
4e1b3b4ef132 Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
77
4032
a5e1ca620f15 Add description and set correct name for GaugeDischargeCurveFacet
Björn Ricks <bjoern.ricks@intevation.de>
parents: 4028
diff changeset
78 Gauge gauge = FLYSUtils.getReferenceGauge(this);
4034
46c1210be26b Set translated data descriptions
Björn Ricks <bjoern.ricks@intevation.de>
parents: 4032
diff changeset
79 String gaugename = "";
46c1210be26b Set translated data descriptions
Björn Ricks <bjoern.ricks@intevation.de>
parents: 4032
diff changeset
80 if (gauge != null) {
46c1210be26b Set translated data descriptions
Björn Ricks <bjoern.ricks@intevation.de>
parents: 4032
diff changeset
81 gaugename = gauge.getName();
46c1210be26b Set translated data descriptions
Björn Ricks <bjoern.ricks@intevation.de>
parents: 4032
diff changeset
82 }
4032
a5e1ca620f15 Add description and set correct name for GaugeDischargeCurveFacet
Björn Ricks <bjoern.ricks@intevation.de>
parents: 4028
diff changeset
83
a5e1ca620f15 Add description and set correct name for GaugeDischargeCurveFacet
Björn Ricks <bjoern.ricks@intevation.de>
parents: 4028
diff changeset
84 String description = Resources.format(callmeta,
a5e1ca620f15 Add description and set correct name for GaugeDischargeCurveFacet
Björn Ricks <bjoern.ricks@intevation.de>
parents: 4028
diff changeset
85 "facet.gauge_discharge_curve.description",
a5e1ca620f15 Add description and set correct name for GaugeDischargeCurveFacet
Björn Ricks <bjoern.ricks@intevation.de>
parents: 4028
diff changeset
86 "Discharge curve on gauge",
a5e1ca620f15 Add description and set correct name for GaugeDischargeCurveFacet
Björn Ricks <bjoern.ricks@intevation.de>
parents: 4028
diff changeset
87 rivername,
4034
46c1210be26b Set translated data descriptions
Björn Ricks <bjoern.ricks@intevation.de>
parents: 4032
diff changeset
88 gaugename);
4032
a5e1ca620f15 Add description and set correct name for GaugeDischargeCurveFacet
Björn Ricks <bjoern.ricks@intevation.de>
parents: 4028
diff changeset
89
a5e1ca620f15 Add description and set correct name for GaugeDischargeCurveFacet
Björn Ricks <bjoern.ricks@intevation.de>
parents: 4028
diff changeset
90 Facet gfacet = new GaugeDischargeCurveFacet(description);
3936
4e1b3b4ef132 Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
91
4e1b3b4ef132 Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
92 List<Facet> fs = new ArrayList<Facet>(1);
4e1b3b4ef132 Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
93 fs.add(gfacet);
4e1b3b4ef132 Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
94
4e1b3b4ef132 Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
95 addFacets(STATIC_STATE_NAME, fs);
4e1b3b4ef132 Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
96
4e1b3b4ef132 Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
97 super.setup(identifier, factory, context, callmeta, data);
4e1b3b4ef132 Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
98 }
4e1b3b4ef132 Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
99
4e1b3b4ef132 Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
100 @Override
4e1b3b4ef132 Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
101 public String getName() {
4e1b3b4ef132 Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
102 return NAME;
4e1b3b4ef132 Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
103 }
4e1b3b4ef132 Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
104
4e1b3b4ef132 Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
105 @Override
4e1b3b4ef132 Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
106 protected void initStaticState() {
4e1b3b4ef132 Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
107 StaticState state = new StaticState(STATIC_STATE_NAME);
4e1b3b4ef132 Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
108 List<Facet> fs = facets.get(STATIC_STATE_NAME);
4e1b3b4ef132 Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
109 DefaultOutput output = new DefaultOutput(
4e1b3b4ef132 Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
110 "discharge_curve",
4e1b3b4ef132 Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
111 "output.discharge_curve", "image/png",
4e1b3b4ef132 Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
112 fs,
4e1b3b4ef132 Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
113 "chart");
4e1b3b4ef132 Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
114
4e1b3b4ef132 Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
115 state.addOutput(output);
4e1b3b4ef132 Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
116 setStaticState(state);
4e1b3b4ef132 Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
117 }
4e1b3b4ef132 Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
118 }

http://dive4elements.wald.intevation.org