Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/CrossSectionFacet.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 | 31168ac9c7e7 |
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 | |
6 import org.apache.log4j.Logger; | |
7 | |
8 import de.intevation.artifacts.Artifact; | |
9 import de.intevation.artifacts.CallContext; | |
10 | |
11 import de.intevation.artifactdatabase.state.Facet; | |
12 | |
13 import de.intevation.flys.artifacts.CrossSectionArtifact; | |
14 | |
15 import de.intevation.flys.artifacts.states.DefaultState.ComputeType; | |
16 | |
17 | |
18 /** | |
19 * Trival Facet for Cross Sections (profiles). | |
20 */ | |
21 public class CrossSectionFacet | |
22 extends BlackboardDataFacet | |
23 implements FacetTypes { | |
24 | |
25 public static String BLACKBOARD_CS_MASTER_DATA | |
26 = "crosssection.masterprofile.data"; | |
27 | |
28 public static String BLACKBOARD_CS_PREV_KM | |
29 = "crosssection.masterprofile.km.prev"; | |
30 | |
31 public static String BLACKBOARD_CS_NEXT_KM | |
32 = "crosssection.masterprofile.km.next"; | |
33 | |
34 | |
35 private static Logger logger = Logger.getLogger(CrossSectionFacet.class); | |
36 | |
37 protected ComputeType type; | |
38 | |
39 | |
40 /** Trivial constructor, set (maybe localized) description. */ | |
41 public CrossSectionFacet(int idx, String description) { | |
42 super(idx, CROSS_SECTION, description); | |
43 type = ComputeType.ADVANCE; | |
44 } | |
45 | |
46 | |
47 /** Tell world we know about crosssection masters data and its index. */ | |
48 public List getStaticDataProviderKeys(Artifact art) { | |
49 CrossSectionArtifact artifact = (CrossSectionArtifact) art; | |
50 List keys = new ArrayList(); | |
51 if (artifact.isMaster()) { | |
52 keys.add(BLACKBOARD_CS_MASTER_DATA); | |
53 keys.add(BLACKBOARD_CS_PREV_KM); | |
54 keys.add(BLACKBOARD_CS_NEXT_KM); | |
55 } | |
56 keys.add(artifact.identifier() + getIndex()); | |
57 keys.addAll(super.getStaticDataProviderKeys(art)); | |
58 return keys; | |
59 } | |
60 | |
61 | |
62 /** | |
63 * Can provide the master cross section lines or its index. | |
64 * @param artifact crosssection-artifact | |
65 * @param key will respond on BLACKBOARD_CS_MASTER_DATA | |
66 * @param param ignored | |
67 * @param context ignored | |
68 * @return data from artifact (cross section master track). | |
69 */ | |
70 public Object provideBlackboardData(Artifact artifact, | |
71 Object key, | |
72 Object param, | |
73 CallContext context | |
74 ) { | |
75 CrossSectionArtifact crossSection = (CrossSectionArtifact) artifact; | |
76 | |
77 if (key.equals(BLACKBOARD_CS_MASTER_DATA)) { | |
78 return crossSection.searchCrossSectionLine(); | |
79 } | |
80 else if (key.equals(artifact.identifier() + getIndex())) { | |
81 return getData(artifact, context); | |
82 } | |
83 else if (key.equals(BLACKBOARD_CS_NEXT_KM)) { | |
84 return crossSection.getNextKm(); | |
85 } | |
86 else if (key.equals(BLACKBOARD_CS_PREV_KM)) { | |
87 return crossSection.getPrevKm(); | |
88 } | |
89 else { | |
90 Object obj = super.provideBlackboardData(artifact, key, param, | |
91 context); | |
92 if (obj == null) { | |
93 logger.warn("Cannot provide data for key: " + key); | |
94 } | |
95 return obj; | |
96 } | |
97 } | |
98 | |
99 | |
100 /** | |
101 * Gets Cross Section (profile). | |
102 * @param art artifact to get data from. | |
103 * @param context ignored | |
104 */ | |
105 public Object getData(Artifact art, CallContext context) { | |
106 logger.debug("Get data for cross section"); | |
107 | |
108 CrossSectionArtifact artifact = (CrossSectionArtifact)art; | |
109 | |
110 return artifact.getCrossSectionData(); | |
111 } | |
112 | |
113 | |
114 /** Do a deep copy. */ | |
115 @Override | |
116 public Facet deepCopy() { | |
117 CrossSectionFacet copy = new CrossSectionFacet(this.index, this.description); | |
118 copy.set(this); | |
119 return copy; | |
120 } | |
121 } | |
122 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |