1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.directwebremoting.guice;
17
18 import com.google.inject.Key;
19
20 import java.util.Collection;
21
22 /**
23 * Manages instances for a context. This class is only useful for
24 * defining new implementations of {@link AbstractContextScope}.
25 * @author Tim Peierls [tim at peierls dot net]
26 */
27 public interface ContextRegistry<C, R>
28 {
29 /**
30 * Returns the registry object associated with the given context.
31 */
32 R registryFor(C context);
33
34
35 /**
36 * Looks up an InstanceProvider for a key (either directly or using
37 * the precalculated key.toString() value) in a registry object,
38 * returning null if not found.
39 */
40 <T> InstanceProvider<T> get(R registry, Key<T> key, String keyString);
41
42
43 /**
44 * Looks up an InstanceProvider for a key (either directly or using
45 * the precalculated key.toString() value) in a registry object,
46 * returning null if not found, otherwise returning the existing value.
47 */
48 <T> InstanceProvider<T> putIfAbsent(R registry, Key<T> key, String keyString,
49 InstanceProvider<T> creator);
50
51
52 /**
53 * Removes the registry entry for the given key (either directly or using
54 * the precalculated key.toString() value) from a registry object if
55 * the registered value is identical to {@code creator}.
56 * @return whether the value was removed
57 */
58 <T> boolean remove(R registry, Key<T> key, String keyString,
59 InstanceProvider<T> creator);
60 }