01: /**
02: * Copyright (C) 2006 Google Inc.
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: */package com.google.inject;
16:
17: import java.lang.reflect.Member;
18: import java.util.LinkedHashMap;
19:
20: /**
21: * An immutable snapshot of the current context which is safe to expose to
22: * client code.
23: *
24: * @author crazybob@google.com (Bob Lee)
25: */
26: class ExternalContext<T> implements Context {
27:
28: final Member member;
29: final Key<T> key;
30: final InjectorImpl injector;
31: final int parameterIndex;
32:
33: public ExternalContext(Member member, int paramterIndex,
34: Key<T> key, InjectorImpl injector) {
35: this .member = member;
36: this .key = key;
37: this .injector = injector;
38: this .parameterIndex = paramterIndex;
39: }
40:
41: public Key<?> getKey() {
42: return this .key;
43: }
44:
45: public Injector getInjector() {
46: return injector;
47: }
48:
49: public Member getMember() {
50: return member;
51: }
52:
53: public int getParameterIndex() {
54: return parameterIndex;
55: }
56:
57: public String toString() {
58: return "Context" + new LinkedHashMap<String, Object>() {
59: {
60: put("member", member);
61: put("key", getKey());
62: put("injector", injector);
63: }
64: }.toString();
65: }
66:
67: static <T> ExternalContext<T> newInstance(Member member,
68: Key<T> key, InjectorImpl injector) {
69: return new ExternalContext<T>(member, -1, key, injector);
70: }
71:
72: static <T> ExternalContext<T> newInstance(Member member,
73: int parameterIndex, Key<T> key, InjectorImpl injector) {
74: return new ExternalContext<T>(member, parameterIndex, key,
75: injector);
76: }
77: }
|