Mercurial > dive4elements > framework
changeset 353:33d7a6da1a05
Extended CallContext to also act as a blackboard/service broker.
artifacts/trunk@3331 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Wed, 30 Nov 2011 08:24:55 +0000 |
parents | 9c8d91708d28 |
children | c83519249fea |
files | artifact-database/src/main/java/de/intevation/artifactdatabase/AbstractCallContext.java artifacts/src/main/java/de/intevation/artifacts/CallContext.java |
diffstat | 2 files changed, 52 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- 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<Object, List<DataProvider>> 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<DataProvider> 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<DataProvider> providers = null; + if (dataProviders == null) { + dataProviders = new HashMap(); + providers = new ArrayList<DataProvider>(); + providers.add(value); + return dataProviders.put(key, providers); + } + providers = dataProviders.get(key); + + if (providers == null) { + providers = new ArrayList<DataProvider>(); + } + providers.add(value); + return dataProviders.put(key, providers); + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- 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<DataProvider> 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 :