comparison artifact-database/src/main/java/de/intevation/artifactdatabase/AbstractCallContext.java @ 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 a8a06bbe306c
children 1d11a0531242
comparison
equal deleted inserted replaced
352:9c8d91708d28 353:33d7a6da1a05
5 * Read the file LGPL.txt coming with the software for details 5 * Read the file LGPL.txt coming with the software for details
6 * or visit http://www.gnu.org/licenses/ if it does not exist. 6 * or visit http://www.gnu.org/licenses/ if it does not exist.
7 */ 7 */
8 package de.intevation.artifactdatabase; 8 package de.intevation.artifactdatabase;
9 9
10 import java.util.ArrayList;
11 import java.util.List;
10 import java.util.HashMap; 12 import java.util.HashMap;
11 13
12 import de.intevation.artifacts.ArtifactDatabase; 14 import de.intevation.artifacts.ArtifactDatabase;
13 import de.intevation.artifacts.CallContext; 15 import de.intevation.artifacts.CallContext;
14 import de.intevation.artifacts.CallMeta; 16 import de.intevation.artifacts.CallMeta;
17 import de.intevation.artifacts.DataProvider;
15 18
16 19
17 /** 20 /**
18 * Abstract class that implements some basic methods of a CallContext. 21 * Abstract class that implements some basic methods of a CallContext.
19 * 22 *
39 42
40 /** 43 /**
41 * Map to act like a clipboard when nesting calls like a proxy artifact. 44 * Map to act like a clipboard when nesting calls like a proxy artifact.
42 */ 45 */
43 protected HashMap customValues; 46 protected HashMap customValues;
47
48 /**
49 * Map to act like a clipboard when nesting calls like a proxy artifact.
50 */
51 protected HashMap<Object, List<DataProvider>> dataProviders;
44 52
45 53
46 /** 54 /**
47 * The default constructor of this abstract CallContext. 55 * The default constructor of this abstract CallContext.
48 * 56 *
99 if (customValues == null) { 107 if (customValues == null) {
100 customValues = new HashMap(); 108 customValues = new HashMap();
101 } 109 }
102 return customValues.put(key, value); 110 return customValues.put(key, value);
103 } 111 }
112
113 /**
114 * Get list of DataProviders that registered for given key.
115 * @return list (empty list if none found, never null).
116 */
117 public List<DataProvider> getDataProvider(Object key) {
118 return dataProviders != null
119 ? dataProviders.get(key)
120 : null;//java.util.Collections.emptyList();
121 }
122
123 /**
124 * Let a DataProvider register itself with given key.
125 * Multiple DataProvider can register under the same key.
126 */
127 public Object registerDataProvider(Object key, DataProvider value) {
128 List<DataProvider> providers = null;
129 if (dataProviders == null) {
130 dataProviders = new HashMap();
131 providers = new ArrayList<DataProvider>();
132 providers.add(value);
133 return dataProviders.put(key, providers);
134 }
135 providers = dataProviders.get(key);
136
137 if (providers == null) {
138 providers = new ArrayList<DataProvider>();
139 }
140 providers.add(value);
141 return dataProviders.put(key, providers);
142 }
104 } 143 }
105 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : 144 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org