# HG changeset patch # User Felix Wolfsteller # Date 1322641495 0 # Node ID 33d7a6da1a0534593b5e9fab5a6d0d5d91876b5d # Parent 9c8d91708d28fb77b674b31000211436a80fd73e Extended CallContext to also act as a blackboard/service broker. artifacts/trunk@3331 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 9c8d91708d28 -r 33d7a6da1a05 artifact-database/src/main/java/de/intevation/artifactdatabase/AbstractCallContext.java --- a/artifact-database/src/main/java/de/intevation/artifactdatabase/AbstractCallContext.java Wed Nov 30 08:20:15 2011 +0000 +++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/AbstractCallContext.java Wed Nov 30 08:24:55 2011 +0000 @@ -7,11 +7,14 @@ */ package de.intevation.artifactdatabase; +import java.util.ArrayList; +import java.util.List; import java.util.HashMap; import de.intevation.artifacts.ArtifactDatabase; import de.intevation.artifacts.CallContext; import de.intevation.artifacts.CallMeta; +import de.intevation.artifacts.DataProvider; /** @@ -42,6 +45,11 @@ */ protected HashMap customValues; + /** + * Map to act like a clipboard when nesting calls like a proxy artifact. + */ + protected HashMap> dataProviders; + /** * The default constructor of this abstract CallContext. @@ -101,5 +109,36 @@ } return customValues.put(key, value); } + + /** + * Get list of DataProviders that registered for given key. + * @return list (empty list if none found, never null). + */ + public List getDataProvider(Object key) { + return dataProviders != null + ? dataProviders.get(key) + : null;//java.util.Collections.emptyList(); + } + + /** + * Let a DataProvider register itself with given key. + * Multiple DataProvider can register under the same key. + */ + public Object registerDataProvider(Object key, DataProvider value) { + List providers = null; + if (dataProviders == null) { + dataProviders = new HashMap(); + providers = new ArrayList(); + providers.add(value); + return dataProviders.put(key, providers); + } + providers = dataProviders.get(key); + + if (providers == null) { + providers = new ArrayList(); + } + providers.add(value); + return dataProviders.put(key, providers); + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r 9c8d91708d28 -r 33d7a6da1a05 artifacts/src/main/java/de/intevation/artifacts/CallContext.java --- a/artifacts/src/main/java/de/intevation/artifacts/CallContext.java Wed Nov 30 08:20:15 2011 +0000 +++ b/artifacts/src/main/java/de/intevation/artifacts/CallContext.java Wed Nov 30 08:24:55 2011 +0000 @@ -8,6 +8,7 @@ package de.intevation.artifacts; +import java.util.List; import java.util.LinkedList; import org.w3c.dom.Document; @@ -128,5 +129,17 @@ * @return The time to live of the current artifact. */ Long getTimeToLive(); + + /** + * Get a list of DataProvider that get provide 'key' type of data to + * other facets. + */ + public List getDataProvider(Object key); + + /** + * Register a DataProvider that can provide 'key' type of data to + * other facets. + */ + public Object registerDataProvider(Object key, DataProvider provider); } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :