KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > directwebremoting > guice > ContextRegistry


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
20 import java.util.Collection JavaDoc;
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 JavaDoc 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 JavaDoc 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 JavaDoc keyString,
59                        InstanceProvider<T> creator);
60 }
61
Popular Tags