1 7 package org.ejtools.beans.beancontext; 8 9 import java.beans.beancontext.BeanContext ; 10 import java.beans.beancontext.BeanContextChild ; 11 import java.beans.beancontext.BeanContextServiceRevokedListener ; 12 import java.beans.beancontext.BeanContextServices ; 13 import java.beans.beancontext.BeanContextServicesSupport ; 14 import java.util.Iterator ; 15 import java.util.TooManyListenersException ; 16 17 import org.ejtools.util.state.Storable; 18 import org.ejtools.util.state.StoreVisitor; 19 20 27 public abstract class CustomBeanContextServicesSupport extends BeanContextServicesSupport implements Storable 28 { 29 34 public void accept(StoreVisitor visitor) 35 { 36 visitor.persist(this); 37 } 38 39 40 41 public void clear() 42 { 43 Iterator iterator; 44 45 iterator = this.iterator(); 47 while (iterator.hasNext()) 48 { 49 Object o = iterator.next(); 50 if (o instanceof BeanContext ) 51 { 52 ((BeanContext ) o).clear(); 53 } 54 } 55 56 iterator = this.iterator(); 58 while (iterator.hasNext()) 59 { 60 iterator.next(); 61 iterator.remove(); 62 } 63 } 64 65 66 78 public Object getService(BeanContextChild child, Object requestor, Class serviceClass, Object serviceSelector, BeanContextServiceRevokedListener bcsrl) 79 throws TooManyListenersException 80 { 81 Object service = super.getService(child, requestor, serviceClass, serviceSelector, bcsrl); 82 83 if (service == null) 85 { 86 BeanContextServices bcs = null; 87 88 try 89 { 90 bcs = (BeanContextServices ) this.getBeanContext(); 91 } 92 catch (ClassCastException cce) 93 { 94 return null; 95 } 96 97 return bcs.getService(this, requestor, serviceClass, serviceSelector, bcsrl); 98 } 99 100 return service; 101 } 102 } 103 | Popular Tags |