1 package jfun.yan; 2 3 final class UseKeyComponent extends Component { 4 private final Object key; 5 6 UseKeyComponent(Object key) { 7 this.key = key; 8 } 9 public Class verify(Dependency dependency){ 10 final ComponentMap cmap = dependency.getComponentMap(); 11 final Component cc = 12 cmap.getComponent(key); 13 if(cc==null)throw new UnresolvedComponentException(key); 14 return cc.verify(dependency); 15 } 16 public Object create(Dependency dependency){ 17 final ComponentMap cmap = dependency.getComponentMap(); 18 final Component cc = 19 cmap.getComponent(key); 20 if(cc==null)throw new UnresolvedComponentException(key); 21 return cc.create(dependency); 22 } 23 public boolean isSingleton(){ 24 return false; 25 } 26 public boolean isConcrete(){ 27 return false; 28 } 29 public Class getType(){ 30 return null; 31 } 32 public String toString(){ 33 return "useKey <"+key+">"; 34 } 35 public boolean equals(Object obj) { 36 if(obj instanceof UseKeyComponent){ 37 final UseKeyComponent other = (UseKeyComponent)obj; 38 return key.equals(other.key); 39 } 40 else return false; 41 } 42 public int hashCode() { 43 return key.hashCode(); 44 } 45 46 } | Popular Tags |