1 8 14 package jfun.yan; 15 16 22 final class SingletonComponent 23 extends DelegatingComponent{ 24 private transient Object v = null; 25 private transient boolean cached = false; 26 public synchronized Object create(Dependency a) { 27 if(cached) return v; 28 this.v = super.create(a); 29 this.cached = true; 30 return v; 31 } 32 public synchronized Class verify(Dependency ac) { 33 if(!cached){ 34 return super.verify(ac); 35 } 36 else{ 37 return getCachedType(); 38 } 39 } 40 public synchronized Class getType(){ 41 if(v!=null) 42 return v.getClass(); 43 else{ 44 return super.getType(); 45 } 46 } 47 public synchronized boolean isConcrete(){ 48 return cached; 49 } 50 private Class getCachedType(){ 51 return v==null?void.class:v.getClass(); 52 } 53 SingletonComponent(final Component cc) { 54 super(cc); 55 } 56 public Component singleton(){return this;} 57 public boolean isSingleton(){ 58 return true; 59 } 60 } 61 | Popular Tags |