Mercurial > dive4elements > river
annotate flys-artifacts/src/main/java/de/intevation/flys/artifacts/CrossSectionArtifact.java @ 1999:02ce03329ef5
Some optimizations during out() operation of FLYSArtifactCollection.
flys-artifacts/trunk@3437 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Fri, 16 Dec 2011 11:47:57 +0000 |
parents | 07b176b14205 |
children | c03aeb0cf46b |
rev | line source |
---|---|
1964
85e442933e6d
New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
1 package de.intevation.flys.artifacts; |
85e442933e6d
New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
2 |
85e442933e6d
New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
3 import java.util.ArrayList; |
85e442933e6d
New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
4 import java.util.List; |
85e442933e6d
New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
5 |
85e442933e6d
New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
6 import org.apache.log4j.Logger; |
85e442933e6d
New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
7 |
85e442933e6d
New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
8 import org.w3c.dom.Document; |
85e442933e6d
New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
9 |
85e442933e6d
New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
10 import de.intevation.artifacts.Artifact; |
85e442933e6d
New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
11 import de.intevation.artifacts.ArtifactFactory; |
85e442933e6d
New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
12 import de.intevation.artifacts.CallMeta; |
85e442933e6d
New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
13 |
85e442933e6d
New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
14 import de.intevation.flys.artifacts.model.CrossSectionFacet; |
85e442933e6d
New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
15 |
1967
27bb2e24f7f8
Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1964
diff
changeset
|
16 import de.intevation.flys.model.CrossSection; |
27bb2e24f7f8
Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1964
diff
changeset
|
17 import de.intevation.flys.model.CrossSectionLine; |
27bb2e24f7f8
Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1964
diff
changeset
|
18 import de.intevation.flys.artifacts.model.CrossSectionFactory; |
1964
85e442933e6d
New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
19 import de.intevation.artifacts.common.ArtifactNamespaceContext; |
85e442933e6d
New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
20 import de.intevation.artifacts.common.utils.XMLUtils; |
85e442933e6d
New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
21 |
85e442933e6d
New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
22 import de.intevation.flys.artifacts.states.StaticState; |
85e442933e6d
New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
23 |
85e442933e6d
New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
24 import de.intevation.artifactdatabase.state.Facet; |
85e442933e6d
New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
25 import de.intevation.artifactdatabase.state.State; |
85e442933e6d
New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
26 |
85e442933e6d
New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
27 |
1985
07b176b14205
Cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1982
diff
changeset
|
28 /** |
07b176b14205
Cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1982
diff
changeset
|
29 * Artifact describing a cross-section. |
07b176b14205
Cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1982
diff
changeset
|
30 */ |
1964
85e442933e6d
New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
31 public class CrossSectionArtifact extends StaticFLYSArtifact { |
85e442933e6d
New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
32 |
85e442933e6d
New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
33 /** Access ids of doc. */ |
85e442933e6d
New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
34 public static final String XPATH_IDS = "/art:action/art:ids/@value"; |
85e442933e6d
New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
35 |
85e442933e6d
New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
36 /** Name of Artifact. */ |
85e442933e6d
New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
37 public static final String CS_ARTIFACT_NAME = "cross_section"; |
85e442933e6d
New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
38 |
85e442933e6d
New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
39 /** Name of state. */ |
85e442933e6d
New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
40 public static final String STATIC_STATE_NAME = "state.cross_section"; |
85e442933e6d
New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
41 |
1967
27bb2e24f7f8
Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1964
diff
changeset
|
42 /** Name of data item keeping the position. */ |
27bb2e24f7f8
Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1964
diff
changeset
|
43 public static final String DATA_KM = "cross_section.km"; |
27bb2e24f7f8
Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1964
diff
changeset
|
44 |
27bb2e24f7f8
Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1964
diff
changeset
|
45 /** Name of data item keeping the database id of this c.s.. */ |
27bb2e24f7f8
Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1964
diff
changeset
|
46 public static final String DATA_DBID = "cross_section.dbid"; |
27bb2e24f7f8
Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1964
diff
changeset
|
47 |
27bb2e24f7f8
Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1964
diff
changeset
|
48 /** Name of data item keeping the database id of this c.s.. */ |
27bb2e24f7f8
Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1964
diff
changeset
|
49 public static final String DATA_IS_MASTER = "cross_section.master?"; |
27bb2e24f7f8
Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1964
diff
changeset
|
50 |
1964
85e442933e6d
New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
51 /** Own logger. */ |
85e442933e6d
New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
52 private static final Logger logger = |
85e442933e6d
New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
53 Logger.getLogger(CrossSectionArtifact.class); |
85e442933e6d
New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
54 |
85e442933e6d
New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
55 |
85e442933e6d
New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
56 /** Return given name. */ |
85e442933e6d
New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
57 @Override |
85e442933e6d
New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
58 public String getName() { |
85e442933e6d
New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
59 return CS_ARTIFACT_NAME; |
85e442933e6d
New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
60 } |
85e442933e6d
New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
61 |
85e442933e6d
New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
62 |
1985
07b176b14205
Cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1982
diff
changeset
|
63 /** Store ids, create a CrossSectionFacet. */ |
1964
85e442933e6d
New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
64 @Override |
85e442933e6d
New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
65 public void setup( |
85e442933e6d
New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
66 String identifier, |
85e442933e6d
New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
67 ArtifactFactory factory, |
85e442933e6d
New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
68 Object context, |
85e442933e6d
New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
69 CallMeta callMeta, |
85e442933e6d
New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
70 Document data) |
85e442933e6d
New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
71 { |
85e442933e6d
New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
72 logger.info("CrossSectionArtifact.setup"); |
85e442933e6d
New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
73 |
85e442933e6d
New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
74 super.setup(identifier, factory, context, callMeta, data); |
85e442933e6d
New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
75 |
85e442933e6d
New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
76 String ids = XMLUtils.xpathString( |
85e442933e6d
New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
77 data, XPATH_IDS, ArtifactNamespaceContext.INSTANCE); |
85e442933e6d
New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
78 |
85e442933e6d
New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
79 if (ids != null && ids.length() > 0) { |
1967
27bb2e24f7f8
Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1964
diff
changeset
|
80 addStringData(DATA_DBID, ids); |
27bb2e24f7f8
Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1964
diff
changeset
|
81 logger.debug("CrossSectionArtifacts db-id: " + ids); |
1964
85e442933e6d
New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
82 } |
85e442933e6d
New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
83 else { |
85e442933e6d
New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
84 throw new IllegalArgumentException("No attribute 'ids' found!"); |
85e442933e6d
New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
85 } |
85e442933e6d
New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
86 |
1967
27bb2e24f7f8
Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1964
diff
changeset
|
87 // Assume we start at km 0. |
27bb2e24f7f8
Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1964
diff
changeset
|
88 addStringData(DATA_KM, "0"); |
27bb2e24f7f8
Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1964
diff
changeset
|
89 addStringData(DATA_IS_MASTER, "0"); |
27bb2e24f7f8
Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1964
diff
changeset
|
90 |
1964
85e442933e6d
New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
91 List<Facet> fs = new ArrayList<Facet>(); |
1971
741d2067cfe1
Given CrossSections a name, let crosssection facets survive.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1967
diff
changeset
|
92 CrossSection cs = CrossSectionFactory.getCrossSection(Integer.valueOf(ids)); |
741d2067cfe1
Given CrossSections a name, let crosssection facets survive.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1967
diff
changeset
|
93 fs.add(new CrossSectionFacet(0, cs.getDescription())); |
1964
85e442933e6d
New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
94 |
85e442933e6d
New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
95 StaticState state = (StaticState) getCurrentState(context); |
85e442933e6d
New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
96 |
85e442933e6d
New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
97 if (!fs.isEmpty()) { |
85e442933e6d
New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
98 facets.put(getCurrentStateId(), fs); |
85e442933e6d
New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
99 } |
85e442933e6d
New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
100 } |
85e442933e6d
New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
101 |
85e442933e6d
New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
102 |
85e442933e6d
New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
103 /** Do not copy data from daddyfact. */ |
85e442933e6d
New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
104 @Override |
85e442933e6d
New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
105 protected void initialize( |
85e442933e6d
New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
106 Artifact artifact, |
85e442933e6d
New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
107 Object context, |
85e442933e6d
New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
108 CallMeta callMeta) |
85e442933e6d
New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
109 { |
85e442933e6d
New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
110 // do nothing |
85e442933e6d
New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
111 } |
85e442933e6d
New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
112 |
85e442933e6d
New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
113 |
85e442933e6d
New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
114 /** |
85e442933e6d
New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
115 * Create and return a new StaticState with charting output. |
85e442933e6d
New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
116 */ |
85e442933e6d
New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
117 @Override |
85e442933e6d
New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
118 public State getCurrentState(Object cc) { |
1971
741d2067cfe1
Given CrossSections a name, let crosssection facets survive.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1967
diff
changeset
|
119 final List<Facet> fs = facets.get(getCurrentStateId()); |
1964
85e442933e6d
New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
120 |
1971
741d2067cfe1
Given CrossSections a name, let crosssection facets survive.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1967
diff
changeset
|
121 StaticState state = new StaticState(STATIC_STATE_NAME) { |
1982
8afd6a9bb244
Cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1973
diff
changeset
|
122 @Override |
1971
741d2067cfe1
Given CrossSections a name, let crosssection facets survive.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1967
diff
changeset
|
123 public Object staticCompute(List<Facet> facets) { |
741d2067cfe1
Given CrossSections a name, let crosssection facets survive.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1967
diff
changeset
|
124 if (facets != null) { |
741d2067cfe1
Given CrossSections a name, let crosssection facets survive.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1967
diff
changeset
|
125 facets.addAll(fs); |
741d2067cfe1
Given CrossSections a name, let crosssection facets survive.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1967
diff
changeset
|
126 } |
741d2067cfe1
Given CrossSections a name, let crosssection facets survive.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1967
diff
changeset
|
127 return null; |
741d2067cfe1
Given CrossSections a name, let crosssection facets survive.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1967
diff
changeset
|
128 } |
741d2067cfe1
Given CrossSections a name, let crosssection facets survive.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1967
diff
changeset
|
129 }; |
1964
85e442933e6d
New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
130 |
1967
27bb2e24f7f8
Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1964
diff
changeset
|
131 state.addDefaultChartOutput("cross_section", fs); |
1964
85e442933e6d
New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
132 |
85e442933e6d
New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
133 return state; |
85e442933e6d
New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
134 } |
85e442933e6d
New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
135 |
85e442933e6d
New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
136 |
85e442933e6d
New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
137 /** |
85e442933e6d
New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
138 * Get a list containing the one and only State. |
85e442933e6d
New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
139 * @param context ignored. |
85e442933e6d
New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
140 * @return list with one and only state. |
85e442933e6d
New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
141 */ |
85e442933e6d
New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
142 @Override |
85e442933e6d
New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
143 protected List<State> getStates(Object context) { |
85e442933e6d
New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
144 ArrayList<State> states = new ArrayList<State>(); |
85e442933e6d
New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
145 states.add(getCurrentState(context)); |
85e442933e6d
New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
146 |
85e442933e6d
New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
147 return states; |
85e442933e6d
New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
148 } |
1967
27bb2e24f7f8
Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1964
diff
changeset
|
149 |
27bb2e24f7f8
Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1964
diff
changeset
|
150 // TODO all data access needs proper caching. |
27bb2e24f7f8
Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1964
diff
changeset
|
151 |
27bb2e24f7f8
Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1964
diff
changeset
|
152 /** |
27bb2e24f7f8
Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1964
diff
changeset
|
153 * Get a DataItem casted to int (0 if fails). |
27bb2e24f7f8
Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1964
diff
changeset
|
154 */ |
27bb2e24f7f8
Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1964
diff
changeset
|
155 public int getDataAsIntNull(String dataName) { |
27bb2e24f7f8
Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1964
diff
changeset
|
156 String val = getDataAsString(dataName); |
27bb2e24f7f8
Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1964
diff
changeset
|
157 try { |
27bb2e24f7f8
Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1964
diff
changeset
|
158 return Integer.valueOf(val); |
27bb2e24f7f8
Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1964
diff
changeset
|
159 } |
27bb2e24f7f8
Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1964
diff
changeset
|
160 catch (NumberFormatException e) { |
27bb2e24f7f8
Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1964
diff
changeset
|
161 logger.warn("Could not get data " + dataName + " as int", e); |
27bb2e24f7f8
Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1964
diff
changeset
|
162 return 0; |
27bb2e24f7f8
Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1964
diff
changeset
|
163 } |
27bb2e24f7f8
Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1964
diff
changeset
|
164 } |
27bb2e24f7f8
Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1964
diff
changeset
|
165 |
27bb2e24f7f8
Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1964
diff
changeset
|
166 |
27bb2e24f7f8
Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1964
diff
changeset
|
167 /** Returns database-id of cross-section (from data). */ |
27bb2e24f7f8
Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1964
diff
changeset
|
168 protected int getDBID() { |
27bb2e24f7f8
Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1964
diff
changeset
|
169 return getDataAsIntNull(DATA_DBID); |
27bb2e24f7f8
Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1964
diff
changeset
|
170 } |
27bb2e24f7f8
Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1964
diff
changeset
|
171 |
27bb2e24f7f8
Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1964
diff
changeset
|
172 |
27bb2e24f7f8
Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1964
diff
changeset
|
173 /** |
27bb2e24f7f8
Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1964
diff
changeset
|
174 * Return position (km) from data, 0 if not found. |
27bb2e24f7f8
Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1964
diff
changeset
|
175 */ |
27bb2e24f7f8
Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1964
diff
changeset
|
176 protected double getKm() { |
27bb2e24f7f8
Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1964
diff
changeset
|
177 String val = getDataAsString(DATA_KM); |
27bb2e24f7f8
Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1964
diff
changeset
|
178 try { |
27bb2e24f7f8
Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1964
diff
changeset
|
179 return Double.valueOf(val); |
27bb2e24f7f8
Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1964
diff
changeset
|
180 } |
27bb2e24f7f8
Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1964
diff
changeset
|
181 catch (NumberFormatException e) { |
27bb2e24f7f8
Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1964
diff
changeset
|
182 logger.warn("Could not get data " + DATA_KM + " as double", e); |
27bb2e24f7f8
Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1964
diff
changeset
|
183 return 0; |
27bb2e24f7f8
Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1964
diff
changeset
|
184 } |
27bb2e24f7f8
Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1964
diff
changeset
|
185 } |
27bb2e24f7f8
Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1964
diff
changeset
|
186 |
27bb2e24f7f8
Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1964
diff
changeset
|
187 |
27bb2e24f7f8
Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1964
diff
changeset
|
188 /** Returns true if artifact is set to be a "master" (other facets will |
27bb2e24f7f8
Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1964
diff
changeset
|
189 * refer to this). */ |
27bb2e24f7f8
Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1964
diff
changeset
|
190 public boolean isMaster() { |
27bb2e24f7f8
Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1964
diff
changeset
|
191 return !getDataAsString(DATA_IS_MASTER).equals("0"); |
27bb2e24f7f8
Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1964
diff
changeset
|
192 } |
27bb2e24f7f8
Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1964
diff
changeset
|
193 |
27bb2e24f7f8
Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1964
diff
changeset
|
194 |
27bb2e24f7f8
Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1964
diff
changeset
|
195 /** |
27bb2e24f7f8
Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1964
diff
changeset
|
196 * Get points of Profile of cross section at given kilometer. |
27bb2e24f7f8
Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1964
diff
changeset
|
197 * |
27bb2e24f7f8
Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1964
diff
changeset
|
198 * @return an array holding coordinates of points of profile ( |
27bb2e24f7f8
Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1964
diff
changeset
|
199 * in the form {{x1, x2} {y1, y2}} ). |
27bb2e24f7f8
Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1964
diff
changeset
|
200 */ |
27bb2e24f7f8
Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1964
diff
changeset
|
201 public double [][] getCrossSectionData() { |
27bb2e24f7f8
Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1964
diff
changeset
|
202 logger.info("getCrossSectionData() for cross_section.km " |
27bb2e24f7f8
Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1964
diff
changeset
|
203 + getDataAsString(DATA_KM)); |
27bb2e24f7f8
Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1964
diff
changeset
|
204 CrossSectionLine line = searchCrossSectionLine(); |
27bb2e24f7f8
Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1964
diff
changeset
|
205 |
27bb2e24f7f8
Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1964
diff
changeset
|
206 return line != null |
27bb2e24f7f8
Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1964
diff
changeset
|
207 ? line.fetchCrossSectionProfile() |
27bb2e24f7f8
Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1964
diff
changeset
|
208 : null; |
27bb2e24f7f8
Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1964
diff
changeset
|
209 } |
27bb2e24f7f8
Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1964
diff
changeset
|
210 |
27bb2e24f7f8
Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1964
diff
changeset
|
211 |
27bb2e24f7f8
Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1964
diff
changeset
|
212 /** |
27bb2e24f7f8
Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1964
diff
changeset
|
213 * Get CrossSectionLine spatially closest to what is specified in the data |
27bb2e24f7f8
Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1964
diff
changeset
|
214 * "cross_section.km". |
27bb2e24f7f8
Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1964
diff
changeset
|
215 * |
27bb2e24f7f8
Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1964
diff
changeset
|
216 * @return CrossSectionLine closest to "cross_section.km". |
27bb2e24f7f8
Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1964
diff
changeset
|
217 */ |
27bb2e24f7f8
Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1964
diff
changeset
|
218 public CrossSectionLine searchCrossSectionLine() { |
27bb2e24f7f8
Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1964
diff
changeset
|
219 double wishKM = getKm(); |
27bb2e24f7f8
Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1964
diff
changeset
|
220 |
27bb2e24f7f8
Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1964
diff
changeset
|
221 CrossSection crossSection = CrossSectionFactory.getCrossSection(getDBID()); |
27bb2e24f7f8
Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1964
diff
changeset
|
222 logger.debug("dbid " + getDBID() + " : " + crossSection); |
27bb2e24f7f8
Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1964
diff
changeset
|
223 List<CrossSectionLine> crossSectionLines = |
27bb2e24f7f8
Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1964
diff
changeset
|
224 crossSection.getLines(); |
27bb2e24f7f8
Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1964
diff
changeset
|
225 |
27bb2e24f7f8
Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1964
diff
changeset
|
226 // Get the cross section closest to requested km. |
27bb2e24f7f8
Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1964
diff
changeset
|
227 // Naive, linear approach. |
27bb2e24f7f8
Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1964
diff
changeset
|
228 CrossSectionLine oldLine = crossSectionLines.get(0); |
27bb2e24f7f8
Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1964
diff
changeset
|
229 double oldDiff = Math.abs(wishKM - oldLine.getKm().doubleValue()); |
27bb2e24f7f8
Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1964
diff
changeset
|
230 for (CrossSectionLine line: crossSectionLines) { |
27bb2e24f7f8
Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1964
diff
changeset
|
231 double diff = Math.abs(wishKM - line.getKm().doubleValue()); |
27bb2e24f7f8
Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1964
diff
changeset
|
232 if (diff > oldDiff) { |
27bb2e24f7f8
Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1964
diff
changeset
|
233 break; |
27bb2e24f7f8
Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1964
diff
changeset
|
234 } |
27bb2e24f7f8
Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1964
diff
changeset
|
235 oldDiff = diff; |
27bb2e24f7f8
Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1964
diff
changeset
|
236 oldLine = line; |
27bb2e24f7f8
Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1964
diff
changeset
|
237 } |
27bb2e24f7f8
Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1964
diff
changeset
|
238 return oldLine; |
27bb2e24f7f8
Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1964
diff
changeset
|
239 } |
1964
85e442933e6d
New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
240 } |
85e442933e6d
New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
241 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |