blob: 40b61329037955650fb7c8632356a96b0636fe8a [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
limpbizkit76c24b12008-12-25 04:32:41 +000017package com.google.inject.internal;
crazyboblee66b415a2006-08-25 02:01:19 +000018
limpbizkita98bc7a2008-08-29 16:52:44 +000019import com.google.inject.spi.Dependency;
kevinb9na99dca72007-02-11 04:48:57 +000020import java.util.Map;
crazyboblee66b415a2006-08-25 02:01:19 +000021
22/**
23 * Internal context. Used to coordinate injections and support circular
24 * dependencies.
25 *
26 * @author crazybob@google.com (Bob Lee)
27 */
limpbizkit5ae41eb2009-06-06 17:51:27 +000028final class InternalContext {
crazyboblee66b415a2006-08-25 02:01:19 +000029
limpbizkite89c49e2009-05-06 01:02:14 +000030 private Map<Object, ConstructionContext<?>> constructionContexts = Maps.newHashMap();
limpbizkita98bc7a2008-08-29 16:52:44 +000031 private Dependency dependency;
crazyboblee66b415a2006-08-25 02:01:19 +000032
crazyboblee66b415a2006-08-25 02:01:19 +000033 @SuppressWarnings("unchecked")
limpbizkit8b237452008-04-22 06:47:36 +000034 public <T> ConstructionContext<T> getConstructionContext(Object key) {
limpbizkite89c49e2009-05-06 01:02:14 +000035 ConstructionContext<T> constructionContext
36 = (ConstructionContext<T>) constructionContexts.get(key);
37 if (constructionContext == null) {
38 constructionContext = new ConstructionContext<T>();
crazyboblee66b415a2006-08-25 02:01:19 +000039 constructionContexts.put(key, constructionContext);
kevinb9na99dca72007-02-11 04:48:57 +000040 }
limpbizkite89c49e2009-05-06 01:02:14 +000041 return constructionContext;
42 }
43
limpbizkita98bc7a2008-08-29 16:52:44 +000044 public Dependency getDependency() {
45 return dependency;
limpbizkitb946ca22007-08-25 15:56:50 +000046 }
47
limpbizkita98bc7a2008-08-29 16:52:44 +000048 public void setDependency(Dependency dependency) {
49 this.dependency = dependency;
limpbizkitc808df02007-08-25 03:25:13 +000050 }
crazyboblee66b415a2006-08-25 02:01:19 +000051}