1 4 package jfun.yan; 5 6 import jfun.util.Misc; 7 8 final class UseTypeComponent<T> extends Component<T> { 9 private final Class <T> type; 10 UseTypeComponent(Class <T> type) { 11 this.type = type; 12 } 13 14 public boolean equals(Object obj) { 15 if(obj instanceof UseTypeComponent){ 16 final UseTypeComponent other = (UseTypeComponent)obj; 17 return type.equals(other.type); 18 } 19 else return false; 20 } 21 22 public int hashCode() { 23 return type.hashCode(); 24 } 25 26 public Class verify(Dependency dependency){ 27 return findComponent(dependency).verify(dependency); 28 } 29 30 public T create(Dependency dependency){ 31 return findComponent(dependency).create(dependency); 32 } 33 private Component<T> findComponent(Dependency dependency){ 34 final ComponentMap cmap = dependency.getComponentMap(); 35 final Component<T> cc = 36 cmap.getComponentOfType(type); 37 if(cc==null)throw new UnresolvedComponentException(type); 38 return cc; 39 } 40 public boolean isSingleton(){ 41 return false; 42 } 43 44 public boolean isConcrete(){ 45 return false; 46 } 47 48 public Class getType(){ 49 return null; 50 } 51 52 public String toString(){ 53 return "useType <" + Misc.getTypeName(type)+">"; 54 } 55 } | Popular Tags |