Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/MapArtifact.java @ 3468:f37e7e8907cb
merged flys-artifacts/2.8.1
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Fri, 28 Sep 2012 12:14:39 +0200 |
parents | 453d2d0c4258 |
children | b1912514e0f5 |
comparison
equal
deleted
inserted
replaced
3387:5ffad8bde8ad | 3468:f37e7e8907cb |
---|---|
1 package de.intevation.flys.artifacts; | |
2 | |
3 import org.apache.log4j.Logger; | |
4 | |
5 import java.util.List; | |
6 | |
7 import org.w3c.dom.Document; | |
8 import org.w3c.dom.Element; | |
9 | |
10 import de.intevation.artifacts.ArtifactFactory; | |
11 import de.intevation.artifacts.CallMeta; | |
12 import de.intevation.artifacts.CallContext; | |
13 | |
14 import de.intevation.artifacts.common.utils.XMLUtils; | |
15 import de.intevation.artifacts.common.utils.XMLUtils.ElementCreator; | |
16 import de.intevation.artifacts.common.ArtifactNamespaceContext; | |
17 | |
18 import de.intevation.artifactdatabase.ProtocolUtils; | |
19 import de.intevation.artifactdatabase.state.Facet; | |
20 import de.intevation.artifactdatabase.state.State; | |
21 import de.intevation.artifactdatabase.state.StateEngine; | |
22 import de.intevation.artifactdatabase.state.Output; | |
23 | |
24 import de.intevation.flys.model.River; | |
25 import de.intevation.flys.utils.FLYSUtils; | |
26 | |
27 import de.intevation.flys.artifacts.RiverAxisArtifact.RiverAxisState; | |
28 import de.intevation.flys.artifacts.states.DefaultState; | |
29 import de.intevation.flys.artifacts.context.FLYSContext; | |
30 import de.intevation.flys.artifacts.model.map.WMSDBLayerFacet; | |
31 | |
32 | |
33 public class MapArtifact extends FLYSArtifact { | |
34 | |
35 private static final Logger logger = | |
36 Logger.getLogger(MapArtifact.class); | |
37 | |
38 @Override | |
39 public void setup( | |
40 String identifier, | |
41 ArtifactFactory factory, | |
42 Object context, | |
43 CallMeta callmeta, | |
44 Document data) | |
45 { | |
46 logger.debug("MapArtifact.setup"); | |
47 this.identifier = identifier; | |
48 name = "new_map"; | |
49 | |
50 FLYSContext flysContext = FLYSUtils.getFlysContext(context); | |
51 | |
52 List<State> states = getStates(context); | |
53 | |
54 setCurrentState(states.get(0)); | |
55 } | |
56 | |
57 | |
58 @Override | |
59 protected void appendBackgroundActivity( | |
60 ElementCreator cr, | |
61 Element root, | |
62 CallContext context | |
63 ) { | |
64 Element inBackground = cr.create("background-processing"); | |
65 root.appendChild(inBackground); | |
66 | |
67 cr.addAttr( | |
68 inBackground, | |
69 "value", | |
70 String.valueOf(context.isInBackground()), | |
71 true); | |
72 } | |
73 | |
74 | |
75 /** | |
76 * Append output mode nodes to a document. | |
77 */ | |
78 @Override | |
79 protected void appendOutputModes( | |
80 Document doc, | |
81 Element outs, | |
82 CallContext context, | |
83 String uuid) | |
84 { | |
85 List<String> stateIds = getPreviousStateIds(); | |
86 | |
87 XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator( | |
88 doc, | |
89 ArtifactNamespaceContext.NAMESPACE_URI, | |
90 ArtifactNamespaceContext.NAMESPACE_PREFIX); | |
91 | |
92 FLYSContext flysContext = FLYSUtils.getFlysContext(context); | |
93 StateEngine engine = (StateEngine) flysContext.get( | |
94 FLYSContext.STATE_ENGINE_KEY); | |
95 | |
96 for (String stateId: stateIds) { | |
97 logger.debug("Append output modes for state: " + stateId); | |
98 DefaultState state = (DefaultState) engine.getState(stateId); | |
99 | |
100 List<Output> list = state.getOutputs(); | |
101 if (list == null || list.size() == 0) { | |
102 logger.debug("-> No output modes for this state."); | |
103 continue; | |
104 } | |
105 | |
106 List<Facet> fs = facets.get(stateId); | |
107 | |
108 if (fs == null || fs.size() == 0) { | |
109 logger.debug("No facets for previous state found."); | |
110 continue; | |
111 } | |
112 | |
113 logger.debug("Found " + fs.size() + " facets in previous states."); | |
114 | |
115 List<Output> generated = generateOutputs(list, fs); | |
116 | |
117 ProtocolUtils.appendOutputModes(doc, outs, generated); | |
118 } | |
119 | |
120 try { | |
121 DefaultState cur = (DefaultState) getCurrentState(context); | |
122 if (cur.validate(this)) { | |
123 List<Output> list = cur.getOutputs(); | |
124 if (list != null && list.size() > 0) { | |
125 logger.debug( | |
126 "Append output modes for current state: " + cur.getID()); | |
127 | |
128 List<Facet> fs = facets.get(cur.getID()); | |
129 | |
130 if (fs != null && fs.size() > 0) { | |
131 List<Output> generated = generateOutputs(list, fs); | |
132 | |
133 logger.debug("Found " + fs.size() + " current facets."); | |
134 if (!generated.isEmpty()) { | |
135 ProtocolUtils.appendOutputModes( | |
136 doc, outs, generated); | |
137 } | |
138 } | |
139 else { | |
140 logger.debug("No facets found for the current state."); | |
141 } | |
142 } | |
143 } | |
144 } | |
145 catch (IllegalArgumentException iae) { | |
146 // state is not valid, so we do not append its outputs. | |
147 } | |
148 } | |
149 | |
150 public static class MapState extends RiverAxisState { | |
151 | |
152 @Override | |
153 public Object computeAdvance( | |
154 FLYSArtifact artifact, | |
155 String hash, | |
156 CallContext context, | |
157 List<Facet> facets, | |
158 Object old) | |
159 { | |
160 logger.debug("MapState.computeAdvance"); | |
161 | |
162 this.artifact = artifact; | |
163 | |
164 String type = getFacetType(); | |
165 | |
166 WMSDBLayerFacet facet = new WMSDBLayerFacet( | |
167 0, | |
168 type, | |
169 getTitle(context.getMeta()), | |
170 ComputeType.ADVANCE, | |
171 getID(), hash, | |
172 getUrl()); | |
173 | |
174 String name = type + "-" + artifact.identifier(); | |
175 | |
176 facet.addLayer(name); | |
177 facet.setExtent(getExtent()); | |
178 facet.setSrid(getSrid()); | |
179 facet.setData(getDataString()); | |
180 facet.setFilter(getFilter()); | |
181 facet.setGeometryType(getGeometryType()); | |
182 facet.setConnection(getConnection()); | |
183 facet.setConnectionType(getConnectionType()); | |
184 facet.setLabelItem(getLabelItem()); | |
185 | |
186 facets.add(facet); | |
187 | |
188 return null; | |
189 } | |
190 | |
191 @Override | |
192 public int getRiverId() { | |
193 River r = FLYSUtils.getRiver(artifact); | |
194 int riverId = r.getId(); | |
195 | |
196 return riverId; | |
197 } | |
198 } | |
199 } | |
200 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |