01: /*
02: * Copyright 2007 Tim Peierls
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
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: * Returns a provider that finds the instance registry corresponding
33: * to the current context and returns the object registered with
34: * the given key, creating it if it doesn't exist in the registry.
35: */
36: <T> Provider<T> scope(final Key<T> key, final Provider<T> creator);
37:
38: /**
39: * The context identifier used to look up an instance registry.
40: * The value returned is a function of the current context.
41: */
42: C get();
43:
44: /**
45: * The type of object used as a context identifier.
46: */
47: Class<C> type();
48:
49: /**
50: * The keys bound in this scope.
51: */
52: List<Key<?>> getKeysInScope();
53:
54: /**
55: * The context identifiers of all open contexts that this
56: * scope knows about.
57: */
58: Collection<C> getOpenContexts();
59:
60: /**
61: * Closes the given context.
62: */
63: void close(C context, ContextCloseHandler<?>... closeHandlers);
64:
65: /**
66: * Closes all open contexts.
67: */
68: void closeAll(ContextCloseHandler<?>... closeHandlers);
69: }
|