1 package jfun.yan; 2 3 import java.util.Arrays ; 4 5 import jfun.util.Misc; 6 import jfun.util.StringUtils; 7 import jfun.yan.element.ElementChecker; 8 import jfun.yan.element.ElementStore; 9 10 18 public abstract class StoreBinder<T,L> implements ComponentBinder<L,L>, ElementChecker { 19 private final Creator<T>[] steps; 20 21 25 public StoreBinder(Creator<T>[] steps) { 26 this.steps = steps; 27 } 28 29 public boolean equals(Object obj) { 30 if(obj instanceof StoreBinder){ 31 final StoreBinder other = (StoreBinder)obj; 32 return Arrays.equals(steps, other.steps); 33 } 34 return false; 35 } 36 37 public int hashCode() { 38 return Misc.getArrayHashcode(steps); 39 } 40 41 public String toString() { 42 return StringUtils.listArray("[", ",", "]", steps); 43 } 44 45 public Verifiable verify(final Class type) { 46 return new Verifiable(){ 47 public Class verify(Dependency dep) throws IrresolveableArgumentException, ParameterTypeMismatchException, AmbiguousComponentResolutionException, YanException { 48 for(int i=0; i<steps.length;i++){ 49 checkElement(i, steps[i].verify(dep)); 50 } 51 return type; 52 } 53 }; 54 } 55 56 public Class bindType(Class type) { 57 return type; 58 } 59 60 public Creator<L> bind(L v) throws Throwable { 61 return new CollectionComponent<T,L>(steps, toStore(v), this); 62 } 63 71 public abstract ElementStore<T> toStore(L v); 72 78 public void checkElement(int i, Class type){} 79 80 public Creator<T>[] getProducers() { 81 return steps; 82 } 83 84 } 85 | Popular Tags |