Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/QSectorArtifact.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 | 6442f317a0c7 |
children | a66df8e8d3df |
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 | |
12 import de.intevation.artifacts.Artifact; | |
13 import de.intevation.artifacts.ArtifactFactory; | |
14 import de.intevation.artifacts.CallMeta; | |
15 import de.intevation.artifacts.CallContext; | |
16 | |
17 import de.intevation.flys.artifacts.model.FacetTypes; | |
18 import de.intevation.flys.artifacts.model.GaugeFinder; | |
19 import de.intevation.flys.artifacts.model.GaugeFinderFactory; | |
20 import de.intevation.flys.artifacts.model.GaugeRange; | |
21 import de.intevation.flys.artifacts.model.NamedDouble; | |
22 | |
23 import de.intevation.flys.artifacts.services.FixingsKMChartService; | |
24 | |
25 import de.intevation.flys.artifacts.states.DefaultState; | |
26 | |
27 import de.intevation.flys.artifacts.resources.Resources; | |
28 | |
29 | |
30 /** | |
31 * Artifact to produce sector markers. | |
32 */ | |
33 public class QSectorArtifact | |
34 extends StaticFLYSArtifact | |
35 implements FacetTypes | |
36 { | |
37 /** The logger for this class. */ | |
38 private static Logger logger = Logger.getLogger(QSectorArtifact.class); | |
39 | |
40 /** The name of the artifact. */ | |
41 public static final String ARTIFACT_NAME = "qsector"; | |
42 | |
43 | |
44 /** | |
45 * Trivial Constructor. | |
46 */ | |
47 public QSectorArtifact() { | |
48 logger.debug("QSectorArtifact.QSectorArtifact()"); | |
49 } | |
50 | |
51 | |
52 /** | |
53 * Gets called from factory, to set things up. | |
54 */ | |
55 @Override | |
56 public void setup( | |
57 String identifier, | |
58 ArtifactFactory factory, | |
59 Object context, | |
60 CallMeta callMeta, | |
61 Document data) | |
62 { | |
63 logger.debug("QSectorArtifact.setup"); | |
64 super.setup(identifier, factory, context, callMeta, data); | |
65 initialize(null, context, callMeta); | |
66 } | |
67 | |
68 | |
69 /** Return the name of this artifact. */ | |
70 public String getName() { | |
71 return ARTIFACT_NAME; | |
72 } | |
73 | |
74 | |
75 /** Get list of NamedDouble s (QSectors). */ | |
76 public Object getQSectors(double km, CallContext context) { | |
77 | |
78 String river = getDataAsString("river"); | |
79 List<NamedDouble> qsectors = new ArrayList<NamedDouble>(); | |
80 | |
81 GaugeFinderFactory ggf = GaugeFinderFactory.getInstance(); | |
82 GaugeFinder gf = ggf.getGaugeFinder(river); | |
83 | |
84 if (gf == null) { | |
85 logger.warn("No gauge finder found for river '" + river + "'"); | |
86 return null; | |
87 } | |
88 | |
89 GaugeRange gr = gf.find(km); | |
90 if (gr == null) { | |
91 logger.debug("No gauge range found for km " | |
92 + km + " on river " + river + "."); | |
93 return null; | |
94 } | |
95 | |
96 if (logger.isDebugEnabled()) { | |
97 logger.debug(gr); | |
98 } | |
99 | |
100 for (int i = 0; i < FixingsKMChartService.I18N_Q_SECTOR_BOARDERS.length; ++i) { | |
101 String key = FixingsKMChartService.I18N_Q_SECTOR_BOARDERS[i]; | |
102 String def = FixingsKMChartService.DEFAULT_Q_SECTOR_BORDERS[i]; | |
103 String label = Resources.getMsg(context.getMeta(), key, def); | |
104 | |
105 qsectors.add(new NamedDouble(label, gr.getSectorBorder(i))); | |
106 } | |
107 | |
108 return qsectors; | |
109 } | |
110 | |
111 | |
112 /** Setup state and facet. */ | |
113 @Override | |
114 protected void initialize(Artifact artifact, Object context, CallMeta meta) { | |
115 logger.debug("QSectorArtifact.initialize"); | |
116 List<Facet> fs = new ArrayList<Facet>(); | |
117 | |
118 FLYSArtifact flys = (FLYSArtifact) artifact; | |
119 importData(flys, "river"); | |
120 | |
121 DefaultState state = (DefaultState) getCurrentState(context); | |
122 state.computeInit(this, hash(), context, meta, fs); | |
123 if (!fs.isEmpty()) { | |
124 logger.debug("Facets to add in QSectorArtifact.initialize ."); | |
125 facets.put(getCurrentStateId(), fs); | |
126 } | |
127 else { | |
128 logger.debug("No facets to add in QSectorArtifact.initialize (" | |
129 + state.getID() + ")."); | |
130 } | |
131 } | |
132 } | |
133 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |