1 8 14 package jfun.yan; 15 16 import jfun.yan.function.Signature; 17 18 19 31 public class SimpleDependency implements Dependency { 32 private final Object ckey; 33 private final ComponentMap cmap; 34 35 40 public SimpleDependency(final Object ckey, final ComponentMap cmap) { 41 this.ckey = ckey; 42 this.cmap = cmap; 43 } 44 private Component obtainCreator(int k, Class type){ 45 final Component cc = cmap.getComponentOfType(type); 46 if(cc == null){ 47 throw new IrresolveableArgumentException(ckey, k, type); 48 } 49 return cc; 50 } 51 private Component obtainCreator(Object k, Class type){ 52 final Component cc = cmap.getComponentOfType(type); 53 if(cc == null){ 54 throw new IrresolveablePropertyException(ckey, k, type); 55 } 56 return cc; 57 } 58 public ComponentMap getComponentMap(){return cmap;} 59 public Object getArgument(final Signature src, int i, final Class type){ 60 return obtainCreator(i, type).create( 61 getDependencyForType(type)); 62 } 63 public Class verifyArgument(final Signature src, int i, Class type){ 64 final Component cc = obtainCreator(i, type); 65 final Class r = cc.verify(this); 66 Utils.checkType(src, ckey, i, type, r); 67 return r; 68 } 69 public Object getProperty(final Class component_type, Object lkey, final Class type){ 70 return obtainCreator(lkey, type).create(getDependencyForType(type)); 71 } 72 public Class verifyProperty(final Class component_type, Object lkey, Class type){ 73 final Component cc = obtainCreator(lkey, type); 74 final Class r = cc.verify(this); 75 Utils.checkType(component_type, ckey, lkey, type, r); 76 return r; 77 } 78 79 public Object getComponentKey(){ 80 return ckey; 81 } 82 public Dependency getParent(){return null;} 83 private Dependency getDependencyForType(Class type){ 84 return cmap.getDependencyOfType(type, cmap); 85 } 86 public Dependency getOriginal(){ 87 return this; 88 } 89 public Dependency seal(){ 90 return new ManualDependency(cmap, ckey); 91 } 92 } 93 | Popular Tags |