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:
20: /**
21: * Manages instances for a context. This class is only useful for
22: * defining new implementations of {@link AbstractContextScope}.
23: * @author Tim Peierls [tim at peierls dot net]
24: */
25: public interface ContextRegistry<C, R> {
26: /**
27: * Returns the registry object associated with the given context.
28: */
29: R registryFor(C context);
30:
31: /**
32: * Looks up an InstanceProvider for a key (either directly or using
33: * the precalculated key.toString() value) in a registry object,
34: * returning null if not found.
35: */
36: <T> InstanceProvider<T> get(R registry, Key<T> key, String keyString);
37:
38: /**
39: * Looks up an InstanceProvider for a key (either directly or using
40: * the precalculated key.toString() value) in a registry object,
41: * returning null if not found, otherwise returning the existing value.
42: */
43: <T> InstanceProvider<T> putIfAbsent(R registry, Key<T> key,
44: String keyString, InstanceProvider<T> creator);
45:
46: /**
47: * Removes the registry entry for the given key (either directly or using
48: * the precalculated key.toString() value) from a registry object if
49: * the registered value is identical to {@code creator}.
50: * @return whether the value was removed
51: */
52: <T> boolean remove(R registry, Key<T> key, String keyString,
53: InstanceProvider<T> creator);
54: }
|