crazyboblee | 66b415a | 2006-08-25 02:01:19 +0000 | [diff] [blame] | 1 | /** |
| 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 | |
limpbizkit | 76c24b1 | 2008-12-25 04:32:41 +0000 | [diff] [blame] | 17 | package com.google.inject.internal; |
crazyboblee | 66b415a | 2006-08-25 02:01:19 +0000 | [diff] [blame] | 18 | |
limpbizkit | a98bc7a | 2008-08-29 16:52:44 +0000 | [diff] [blame] | 19 | import com.google.inject.spi.Dependency; |
kevinb9n | a99dca7 | 2007-02-11 04:48:57 +0000 | [diff] [blame] | 20 | import java.util.Map; |
crazyboblee | 66b415a | 2006-08-25 02:01:19 +0000 | [diff] [blame] | 21 | |
| 22 | /** |
| 23 | * Internal context. Used to coordinate injections and support circular |
| 24 | * dependencies. |
| 25 | * |
| 26 | * @author crazybob@google.com (Bob Lee) |
| 27 | */ |
limpbizkit | 5ae41eb | 2009-06-06 17:51:27 +0000 | [diff] [blame^] | 28 | final class InternalContext { |
crazyboblee | 66b415a | 2006-08-25 02:01:19 +0000 | [diff] [blame] | 29 | |
limpbizkit | e89c49e | 2009-05-06 01:02:14 +0000 | [diff] [blame] | 30 | private Map<Object, ConstructionContext<?>> constructionContexts = Maps.newHashMap(); |
limpbizkit | a98bc7a | 2008-08-29 16:52:44 +0000 | [diff] [blame] | 31 | private Dependency dependency; |
crazyboblee | 66b415a | 2006-08-25 02:01:19 +0000 | [diff] [blame] | 32 | |
crazyboblee | 66b415a | 2006-08-25 02:01:19 +0000 | [diff] [blame] | 33 | @SuppressWarnings("unchecked") |
limpbizkit | 8b23745 | 2008-04-22 06:47:36 +0000 | [diff] [blame] | 34 | public <T> ConstructionContext<T> getConstructionContext(Object key) { |
limpbizkit | e89c49e | 2009-05-06 01:02:14 +0000 | [diff] [blame] | 35 | ConstructionContext<T> constructionContext |
| 36 | = (ConstructionContext<T>) constructionContexts.get(key); |
| 37 | if (constructionContext == null) { |
| 38 | constructionContext = new ConstructionContext<T>(); |
crazyboblee | 66b415a | 2006-08-25 02:01:19 +0000 | [diff] [blame] | 39 | constructionContexts.put(key, constructionContext); |
kevinb9n | a99dca7 | 2007-02-11 04:48:57 +0000 | [diff] [blame] | 40 | } |
limpbizkit | e89c49e | 2009-05-06 01:02:14 +0000 | [diff] [blame] | 41 | return constructionContext; |
| 42 | } |
| 43 | |
limpbizkit | a98bc7a | 2008-08-29 16:52:44 +0000 | [diff] [blame] | 44 | public Dependency getDependency() { |
| 45 | return dependency; |
limpbizkit | b946ca2 | 2007-08-25 15:56:50 +0000 | [diff] [blame] | 46 | } |
| 47 | |
limpbizkit | a98bc7a | 2008-08-29 16:52:44 +0000 | [diff] [blame] | 48 | public void setDependency(Dependency dependency) { |
| 49 | this.dependency = dependency; |
limpbizkit | c808df0 | 2007-08-25 03:25:13 +0000 | [diff] [blame] | 50 | } |
crazyboblee | 66b415a | 2006-08-25 02:01:19 +0000 | [diff] [blame] | 51 | } |