1 8 14 package jfun.yan; 15 16 17 18 24 final class MbindComponent<From,To> extends Component<To> { 25 private final Creator<From> c1; 26 private final ComponentBinder<From,To> binder; 27 28 MbindComponent(final Creator<From> c1, final ComponentBinder<From,To> binder) { 29 this.c1 = c1; 30 this.binder = binder; 31 } 32 33 public Class <To> getType() { 34 return binder.bindType(c1.getType()); 35 } 36 public boolean isConcrete(){ 37 return false; 38 } 39 public To create(Dependency dep){ 40 final From v1 = c1.create(dep); 41 return run_binder(binder, v1).create(dep); 42 } 43 public Class <To> verify(Dependency dep){ 44 return binder.verify(c1.verify(dep)).verify(dep); 45 } 46 47 public boolean equals(Object obj) { 48 if(obj instanceof MbindComponent){ 49 final MbindComponent dc2 = (MbindComponent)obj; 50 return c1.equals(dc2.c1) && binder.equals(dc2.binder); 51 } 52 else return false; 53 } 54 public int hashCode() { 55 return c1.hashCode() * 31 + binder.hashCode(); 56 } 57 public String toString() { 58 return "(" + c1 + ") >>= (" + binder + ")"; 59 } 60 private Creator<To> run_binder(Binder<From,To> binder, From v){ 61 try{ 62 return binder.bind(v); 63 } 64 catch(Error e){ 65 throw e; 66 } 67 catch(YanException e){ 68 throw e; 69 } 70 catch(Throwable e){ 71 throw new jfun.yan.ComponentInstantiationException(e); 72 } 73 } 74 public boolean isSingleton(){ 75 return false; 76 } 77 } 78 | Popular Tags |