1 8 9 15 package jfun.yan; 16 17 23 final class UsePropertyComponent<T> extends Component<T> { 24 private final Class component_type; 25 private final Object key; 26 private final Class <T> type; 27 public boolean isConcrete(){ 28 return false; 29 } 30 UsePropertyComponent(Class component_type, final Object key, final Class <T> type) { 31 this.component_type = component_type; 32 this.key = key; 33 this.type = type; 34 } 35 public Class getType() { 36 return type; 37 } 38 public T create(Dependency pp){ 39 return (T)findDependency(pp).getProperty(component_type, key, type); 40 } 41 public Class verify(Dependency pp){ 42 return findDependency(pp).verifyProperty(component_type, key, type); 43 } 44 45 public boolean equals(Object obj) { 46 if(obj instanceof UsePropertyComponent){ 47 final UsePropertyComponent other = (UsePropertyComponent)obj; 48 return component_type.equals(other.component_type) && type.equals(other.type) && key.equals(other.key); 49 } 50 else return false; 51 } 52 public int hashCode() { 53 return (key.hashCode()*31 + type.hashCode())*31+component_type.hashCode(); 54 } 55 public String toString() { 56 return "useProperty(" + component_type.getName()+"," + key + ","+jfun.util.Misc.getTypeName(type)+")"; 57 } 58 private Dependency findDependency(Dependency dep){ 59 final Dependency parent = dep.getParent(); 60 if(parent == null) 61 throw new YanException("useProperty can only be used for parameter or property"); 62 return parent; 63 } 64 public boolean isSingleton(){ 65 return false; 66 } 67 } 68 | Popular Tags |