Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/ReferenceCurveFacet.java @ 3318:dbe2f85bf160
merged flys-artifacts/2.8
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Fri, 28 Sep 2012 12:14:35 +0200 |
parents | 5642a83420f2 |
children |
comparison
equal
deleted
inserted
replaced
2987:98c7a46ec5ae | 3318:dbe2f85bf160 |
---|---|
1 package de.intevation.flys.artifacts.model; | |
2 | |
3 import java.util.ArrayList; | |
4 import java.util.List; | |
5 import java.util.Collections; | |
6 | |
7 import de.intevation.artifactdatabase.state.Facet; | |
8 | |
9 import de.intevation.artifacts.Artifact; | |
10 import de.intevation.artifacts.CallContext; | |
11 | |
12 import de.intevation.flys.artifacts.FLYSArtifact; | |
13 import de.intevation.flys.artifacts.WINFOArtifact; | |
14 | |
15 import de.intevation.flys.artifacts.states.DefaultState.ComputeType; | |
16 | |
17 import org.apache.log4j.Logger; | |
18 | |
19 | |
20 /** Facet for W-over-Ws. */ | |
21 public class ReferenceCurveFacet | |
22 extends DataFacet | |
23 { | |
24 private static Logger log = Logger.getLogger(ReferenceCurveFacet.class); | |
25 | |
26 public static final String CONTEXT_KEY = "reference.curve.axis.scale"; | |
27 | |
28 /** Blackboard data provider key for reference curves start km. */ | |
29 public static final String BB_REFERENCECURVE_STARTKM = | |
30 "reference_curve.startkm"; | |
31 | |
32 /** Blackboard data provider key for reference curves end kms. */ | |
33 public static final String BB_REFERENCECURVE_ENDKMS = | |
34 "reference_curve.endkms"; | |
35 | |
36 | |
37 public ReferenceCurveFacet() { | |
38 } | |
39 | |
40 | |
41 public ReferenceCurveFacet(int index, String name, String description) { | |
42 super(index, name, description, ComputeType.ADVANCE, null, null); | |
43 } | |
44 | |
45 | |
46 public ReferenceCurveFacet( | |
47 int index, | |
48 String name, | |
49 String description, | |
50 ComputeType type, | |
51 String stateID, | |
52 String hash | |
53 ) { | |
54 super(index, name, description, type, hash, stateID); | |
55 } | |
56 | |
57 | |
58 public Object getData(Artifact artifact, CallContext context) { | |
59 | |
60 if (log.isDebugEnabled()) { | |
61 log.debug("Get data for reference curve at index: " + index + | |
62 " /stateId: " + stateId); | |
63 } | |
64 | |
65 return getWWQQ(artifact, context); | |
66 } | |
67 | |
68 | |
69 /** | |
70 * Can provide parameters of reference curve | |
71 * @param key will respond on BB_REFERENCECURVE START/ENDKMS | |
72 * @param param ignored | |
73 * @param context ignored | |
74 * @return whatever parameters for reference curve | |
75 */ | |
76 @Override | |
77 public Object provideBlackboardData(Artifact artifact, | |
78 Object key, | |
79 Object param, | |
80 CallContext context | |
81 ) { | |
82 WINFOArtifact winfo = (WINFOArtifact) artifact; | |
83 if (key.equals(BB_REFERENCECURVE_STARTKM)) { | |
84 return winfo.getReferenceStartKm(); | |
85 } | |
86 else if (key.equals(BB_REFERENCECURVE_ENDKMS)) { | |
87 return winfo.getReferenceEndKms(); | |
88 } | |
89 else { | |
90 return null; | |
91 } | |
92 } | |
93 | |
94 | |
95 protected WWQQ getWWQQ(Artifact artifact, CallContext context) { | |
96 FLYSArtifact winfo = (FLYSArtifact)artifact; | |
97 | |
98 CalculationResult res = (CalculationResult) | |
99 winfo.compute(context, hash, stateId, type, false); | |
100 | |
101 return ((WWQQ [])res.getData())[index]; | |
102 } | |
103 | |
104 | |
105 @Override | |
106 public void set(Facet other) { | |
107 super.set(other); | |
108 ReferenceCurveFacet o = (ReferenceCurveFacet)other; | |
109 type = o.type; | |
110 hash = o.hash; | |
111 stateId = o.stateId; | |
112 } | |
113 | |
114 | |
115 /** Copy deeply. */ | |
116 @Override | |
117 public Facet deepCopy() { | |
118 ReferenceCurveFacet copy = new ReferenceCurveFacet(); | |
119 copy.set(this); | |
120 return copy; | |
121 } | |
122 | |
123 | |
124 @Override | |
125 public List getStaticDataProviderKeys(Artifact art) { | |
126 List list = new ArrayList(); | |
127 list.add(BB_REFERENCECURVE_STARTKM); | |
128 list.add(BB_REFERENCECURVE_ENDKMS); | |
129 return list; | |
130 } | |
131 | |
132 | |
133 @Override | |
134 public List getDataProviderKeys(Artifact art, CallContext context) { | |
135 | |
136 // compute / get data | |
137 Object obj = context.getContextValue(CONTEXT_KEY); | |
138 | |
139 if (!(obj instanceof WWAxisTypes)) { | |
140 obj = new WWAxisTypes(getWWQQ(art, context)); | |
141 context.putContextValue(CONTEXT_KEY, obj); | |
142 } | |
143 else { | |
144 ((WWAxisTypes)obj).classify(getWWQQ(art, context)); | |
145 } | |
146 | |
147 return getStaticDataProviderKeys(art);//Collections.emptyList(); | |
148 } | |
149 } | |
150 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |