comparison flys-artifacts/src/main/java/de/intevation/flys/collections/FLYSArtifactCollection.java @ 1946:a584a26d5fde

Introduce pre-rendering inter-facet communication phase ('blackboard pass'). flys-artifacts/trunk@3336 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Wed, 30 Nov 2011 10:18:38 +0000
parents 0585bf8af41b
children 8c0e9d13d1fc
comparison
equal deleted inserted replaced
1945:f2c14e09a8f1 1946:a584a26d5fde
28 import de.intevation.artifacts.common.utils.XMLUtils; 28 import de.intevation.artifacts.common.utils.XMLUtils;
29 29
30 import de.intevation.artifactdatabase.Backend; 30 import de.intevation.artifactdatabase.Backend;
31 import de.intevation.artifactdatabase.Backend.PersistentArtifact; 31 import de.intevation.artifactdatabase.Backend.PersistentArtifact;
32 import de.intevation.artifactdatabase.DefaultArtifactCollection; 32 import de.intevation.artifactdatabase.DefaultArtifactCollection;
33 import de.intevation.artifactdatabase.state.ArtifactAndFacet;
34 import de.intevation.artifactdatabase.state.Blackboard;
35 import de.intevation.artifactdatabase.state.Facet;
33 import de.intevation.artifactdatabase.state.StateEngine; 36 import de.intevation.artifactdatabase.state.StateEngine;
34 37
35 import de.intevation.flys.artifacts.context.FLYSContext; 38 import de.intevation.flys.artifacts.context.FLYSContext;
36 import de.intevation.flys.artifacts.FLYSArtifact; 39 import de.intevation.flys.artifacts.FLYSArtifact;
37 import de.intevation.flys.artifacts.model.ManagedFacet; 40 import de.intevation.flys.artifacts.model.ManagedFacet;
44 47
45 /** 48 /**
46 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> 49 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
47 */ 50 */
48 public class FLYSArtifactCollection extends DefaultArtifactCollection { 51 public class FLYSArtifactCollection extends DefaultArtifactCollection {
49
50 /** The logger used in this class. */ 52 /** The logger used in this class. */
51 private static Logger log = Logger.getLogger(FLYSArtifactCollection.class); 53 private static Logger log = Logger.getLogger(FLYSArtifactCollection.class);
52 54
53 /** Constant XPath that points to the outputmodes of an artifact. */ 55 /** Constant XPath that points to the outputmodes of an artifact. */
54 public static final String XPATH_ARTIFACT_OUTPUTMODES = 56 public static final String XPATH_ARTIFACT_OUTPUTMODES =
267 ThemeList themeList = new ThemeList(attributes); 269 ThemeList themeList = new ThemeList(attributes);
268 270
269 int size = themeList.size(); 271 int size = themeList.size();
270 log.debug("Output will contain " + size + " elements."); 272 log.debug("Output will contain " + size + " elements.");
271 273
274 List<ArtifactAndFacet> dataProviders =
275 doBlackboardPass(themeList, context);
276
272 try { 277 try {
273 for (int i = 0; i < size; i++) { 278 for (int i = 0; i < size; i++) {
274 ManagedFacet theme = themeList.get(i); 279 ManagedFacet theme = themeList.get(i);
275 280
276 if (theme == null) { 281 if (theme == null) {
277 log.debug("Theme is empty - no output is generated."); 282 log.debug("Theme is empty - no output is generated.");
278 continue; 283 continue;
279 } 284 }
280 285
281 String art = theme.getArtifact(); 286 String art = theme.getArtifact();
287 String facetName = theme.getName();
282 288
283 if (log.isDebugEnabled()) { 289 if (log.isDebugEnabled()) {
284 log.debug("Do output for..."); 290 log.debug("Do output for...");
285 log.debug("... artifact: " + art); 291 log.debug("... artifact: " + art);
286 log.debug("... facet: " + theme.getName()); 292 log.debug("... facet: " + facetName);
287 } 293 }
288
289 String facetName = theme.getName();
290 294
291 if (outName.equals("export") && !facetName.equals(facet)) { 295 if (outName.equals("export") && !facetName.equals(facet)) {
292 continue; 296 continue;
293 } 297 }
294 298
295 Artifact artifact = getArtifact(art, context);
296
297 generator.doOut( 299 generator.doOut(
298 artifact, 300 dataProviders.get(i),
299 theme,
300 getFacetThemeFromAttribute( 301 getFacetThemeFromAttribute(
301 art, 302 art,
302 outName, 303 outName,
303 facetName, 304 facetName,
304 theme.getDescription(), 305 theme.getDescription(),
313 314
314 generator.generate(); 315 generator.generate();
315 } 316 }
316 317
317 318
319 /**
320 * Show blackboard (context) to each facet and create a list of
321 * ArtifactAndFacets on the fly (with the same ordering as the passed
322 * ThemeList).
323 * @param themeList ThemeList to create a ArtifactAndFacetList along.
324 * @param contect The "Blackboard".
325 */
326 protected List<ArtifactAndFacet> doBlackboardPass(
327 ThemeList themeList, CallContext context
328 ) {
329 ArrayList<ArtifactAndFacet> dataProviders =
330 new ArrayList<ArtifactAndFacet>();
331 int size = themeList.size();
332
333 try {
334 // Collect all ArtifactAndFacets for blackboard pass.
335 for (int i = 0; i < size; i++) {
336 ManagedFacet theme = themeList.get(i);
337 String uuid = theme.getArtifact();
338 Artifact artifact = getArtifact(uuid, context);
339 FLYSArtifact flys = (FLYSArtifact) artifact;
340 ArtifactAndFacet artifactAndFacet = new ArtifactAndFacet(artifact,
341 flys.getNativeFacet(theme));
342
343 // Show blackboard to facet.
344 artifactAndFacet.register(context);
345
346 // Add to themes.
347 dataProviders.add(i, artifactAndFacet);
348 }
349 }
350 catch (ArtifactDatabaseException ade) {
351 log.error("ArtifactDatabaseException!", ade);
352 }
353
354 return dataProviders;
355 }
356
318 /** 357 /**
319 * @return masterartifact or null if exception/not found. 358 * @return masterartifact or null if exception/not found.
320 */ 359 */
321 protected FLYSArtifact getMasterArtifact(CallContext context) 360 protected FLYSArtifact getMasterArtifact(CallContext context)
322 { 361 {

http://dive4elements.wald.intevation.org