1 4 package jfun.yan; 5 6 import jfun.yan.util.ReflectionUtil; 7 8 final class LazyComponent2Component<T> extends Component<T> { 9 private final LazyComponent<T> lcc; 10 11 private final Object key; 12 13 private Class type; 14 15 public boolean equals(Object obj) { 16 if(obj instanceof LazyComponent2Component){ 17 final LazyComponent2Component other = (LazyComponent2Component)obj; 18 return lcc.equals(other.lcc); 19 } 20 else return false; 21 } 22 23 public int hashCode() { 24 return lcc.hashCode(); 25 } 26 27 LazyComponent2Component(LazyComponent<T> lcc, Object key) { 28 this.lcc = lcc; 29 this.key = key; 30 } 31 32 public T create(Dependency dependency){ 33 final T r = Components.ensureComponent(eval(), key) 34 .create(dependency); 35 return r; 36 } 37 38 public boolean isConcrete(){ 39 return false; 40 } 41 42 public synchronized Class getType(){ 43 if(type==null){ 44 this.type = lcc.getType(); 45 } 46 return this.type; 47 53 } 54 55 public Class verify(Dependency dependency){ 56 final Class t = Components.ensureComponent(eval(), key) 57 .verify(dependency); 58 if(t!=null) 59 cacheType(t); 60 return t; 61 } 62 63 private synchronized void cacheType(Class <T> type){ 64 if(this.type==null || !ReflectionUtil.isAssignableFrom(type, this.type)){ 65 this.type = type; 66 } 67 } 68 69 public boolean isSingleton(){ 70 return false; 71 } 72 73 private Component<T> eval(){ 74 return lcc.eval(); 75 } 76 77 public String toString(){ 78 return lcc.toString(); 79 } 80 } | Popular Tags |