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