blob: d79b5d6200b1dae9687554e68006e9f33a97ee4d [file] [log] [blame]
crazyboblee66b415a2006-08-25 02:01:19 +00001/**
2 * Copyright (C) 2006 Google Inc.
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
17package com.google.inject;
18
19import java.util.HashMap;
20import java.util.Map;
21
22/**
23 * Internal context. Used to coordinate injections and support circular
24 * dependencies.
25 *
26 * @author crazybob@google.com (Bob Lee)
27 */
28class InternalContext {
29
30 final ContainerImpl container;
31 final Map<Object, ConstructionContext<?>> constructionContexts =
32 new HashMap<Object, ConstructionContext<?>>();
crazyboblee66b415a2006-08-25 02:01:19 +000033 ExternalContext<?> externalContext;
34
crazyboblee63b592b2007-01-25 02:45:24 +000035 InternalContext(ContainerImpl container) {
crazyboblee66b415a2006-08-25 02:01:19 +000036 this.container = container;
37 }
38
39 public Container getContainer() {
40 return container;
41 }
42
43 ContainerImpl getContainerImpl() {
44 return container;
45 }
46
crazyboblee66b415a2006-08-25 02:01:19 +000047 @SuppressWarnings("unchecked")
48 <T> ConstructionContext<T> getConstructionContext(Object key) {
49 ConstructionContext<T> constructionContext =
50 (ConstructionContext<T>) constructionContexts.get(key);
51 if (constructionContext == null) {
52 constructionContext = new ConstructionContext<T>();
53 constructionContexts.put(key, constructionContext);
54 }
55 return constructionContext;
56 }
57
58 @SuppressWarnings("unchecked")
59 <T> ExternalContext<T> getExternalContext() {
60 return (ExternalContext<T>) externalContext;
61 }
62
63 void setExternalContext(ExternalContext<?> externalContext) {
64 this.externalContext = externalContext;
65 }
66}