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 import com.google.inject.Provider;
20 import com.google.inject.Scope;
21
22 import java.util.Collection;
23 import java.util.List;
24
25 /**
26 * A scope that looks up providers in a current context, using itself as a
27 * provider for the context.
28 * @author Tim Peierls [tim at peierls dot net]
29 */
30 public interface ContextScope<C> extends Scope, Provider<C>
31 {
32 /**
33 * Returns a provider that finds the instance registry corresponding
34 * to the current context and returns the object registered with
35 * the given key, creating it if it doesn't exist in the registry.
36 */
37 <T> Provider<T> scope(final Key<T> key, final Provider<T> creator);
38
39 /**
40 * The context identifier used to look up an instance registry.
41 * The value returned is a function of the current context.
42 */
43 C get();
44
45 /**
46 * The type of object used as a context identifier.
47 */
48 Class<C> type();
49
50 /**
51 * The keys bound in this scope.
52 */
53 List<Key<?>> getKeysInScope();
54
55 /**
56 * The context identifiers of all open contexts that this
57 * scope knows about.
58 */
59 Collection<C> getOpenContexts();
60
61 /**
62 * Closes the given context.
63 */
64 void close(C context, ContextCloseHandler<?>... closeHandlers);
65
66 /**
67 * Closes all open contexts.
68 */
69 void closeAll(ContextCloseHandler<?>... closeHandlers);
70 }