1 package org.picocontainer.alternatives; 2 3 import org.picocontainer.LifecycleManager; 4 import org.picocontainer.PicoVisitor; 5 import org.picocontainer.Startable; 6 import org.picocontainer.Disposable; 7 import org.picocontainer.PicoContainer; 8 import org.picocontainer.defaults.ComponentMonitor; 9 import org.picocontainer.defaults.LifecycleVisitor; 10 import org.picocontainer.defaults.NullComponentMonitor; 11 12 import java.lang.reflect.Method ; 13 14 18 public class RootVisitingLifecycleManager implements LifecycleManager { 19 20 private static final Method START; 21 private static final Method STOP; 22 private static final Method DISPOSE; 23 private PicoVisitor startVisitor; 24 private PicoVisitor stopVisitor; 25 private PicoVisitor disposeVisitor; 26 27 static { 28 try { 29 START = Startable.class.getMethod("start", null); 30 STOP = Startable.class.getMethod("stop", null); 31 DISPOSE = Disposable.class.getMethod("dispose", null); 32 } catch (NoSuchMethodException e) { 33 throw new InternalError (e.getMessage()); 35 } 37 } 38 39 49 public RootVisitingLifecycleManager(ComponentMonitor componentMonitor) { 50 this(new LifecycleVisitor(START, Startable.class, true, componentMonitor), 51 new LifecycleVisitor(STOP, Startable.class, false, componentMonitor), 52 new LifecycleVisitor(DISPOSE, Disposable.class, false, componentMonitor)); 53 } 54 55 62 public RootVisitingLifecycleManager(PicoVisitor startVisitor, PicoVisitor stopVisitor, PicoVisitor disposeVisitor) { 63 this.startVisitor = startVisitor; 64 this.stopVisitor = stopVisitor; 65 this.disposeVisitor = disposeVisitor; 66 } 67 68 71 public RootVisitingLifecycleManager() { 72 this(new NullComponentMonitor()); 73 } 74 75 public void start(PicoContainer node) { 76 startVisitor.traverse(node); 77 } 78 79 public void stop(PicoContainer node) { 80 stopVisitor.traverse(node); 81 } 82 83 public void dispose(PicoContainer node) { 84 disposeVisitor.traverse(node); 85 } 86 87 } 88 | Popular Tags |