View Javadoc

1   /*
2    * Copyright 2007 Tim Peierls
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *         http://www.apache.org/licenses/LICENSE-2.0
9    *
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      /**
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  }