1 16 17 package com.google.inject; 18 19 import java.util.HashMap ; 20 import java.util.Map ; 21 22 28 class InternalContext { 29 30 final InjectorImpl injector; 31 Map <Object , ConstructionContext<?>> constructionContexts; 32 ExternalContext<?> externalContext; 33 34 InternalContext(InjectorImpl injector) { 35 this.injector = injector; 36 } 37 38 InjectorImpl getInjectorImpl() { 39 return injector; 40 } 41 42 @SuppressWarnings ("unchecked") 43 <T> ConstructionContext<T> getConstructionContext(Object key) { 44 if (constructionContexts == null) { 45 constructionContexts = new HashMap <Object , ConstructionContext<?>>(); 46 ConstructionContext<T> constructionContext = new ConstructionContext<T>(); 47 constructionContexts.put(key, constructionContext); 48 return constructionContext; 49 } 50 else { 51 ConstructionContext<T> constructionContext 52 = (ConstructionContext<T>) constructionContexts.get(key); 53 if (constructionContext == null) { 54 constructionContext = new ConstructionContext<T>(); 55 constructionContexts.put(key, constructionContext); 56 } 57 return constructionContext; 58 } 59 } 60 61 @SuppressWarnings ("unchecked") 62 <T> ExternalContext<T> getExternalContext() { 63 return (ExternalContext<T>) externalContext; 64 } 65 66 Class <?> getExpectedType() { 67 return externalContext.getKey().getRawType(); 68 } 69 70 void setExternalContext(ExternalContext<?> externalContext) { 71 this.externalContext = externalContext; 72 } 73 } 74 | Popular Tags |