1 10 11 package org.picocontainer.defaults; 12 13 import java.io.Serializable ; 14 import java.lang.reflect.Constructor ; 15 import java.lang.reflect.Method ; 16 17 import org.picocontainer.ComponentMonitor; 18 import org.picocontainer.monitors.DefaultComponentMonitor; 19 20 35 public class DelegatingComponentMonitor implements ComponentMonitor, ComponentMonitorStrategy, Serializable { 36 37 private ComponentMonitor delegate; 38 39 43 public DelegatingComponentMonitor(ComponentMonitor delegate) { 44 checkMonitor(delegate); 45 this.delegate = delegate; 46 } 47 48 52 public DelegatingComponentMonitor() { 53 this(DefaultComponentMonitor.getInstance()); 54 } 55 56 public void instantiating(Constructor constructor) { 57 delegate.instantiating(constructor); 58 } 59 60 public void instantiated(Constructor constructor, long duration) { 61 delegate.instantiated(constructor, duration); 62 } 63 64 public void instantiated(Constructor constructor, Object instantiated, Object [] injected, long duration) { 65 delegate.instantiated(constructor, instantiated, injected, duration); 66 } 67 68 public void instantiationFailed(Constructor constructor, Exception e) { 69 delegate.instantiationFailed(constructor, e); 70 } 71 72 public void invoking(Method method, Object instance) { 73 delegate.invoking(method, instance); 74 } 75 76 public void invoked(Method method, Object instance, long duration) { 77 delegate.invoked(method, instance, duration); 78 } 79 80 public void invocationFailed(Method method, Object instance, Exception e) { 81 delegate.invocationFailed(method, instance, e); 82 } 83 84 public void lifecycleInvocationFailed(Method method, Object instance, RuntimeException cause) { 85 delegate.lifecycleInvocationFailed(method,instance, cause); 86 } 87 88 94 public void changeMonitor(ComponentMonitor monitor) { 95 checkMonitor(monitor); 96 if ( delegate instanceof ComponentMonitorStrategy ){ 97 ((ComponentMonitorStrategy)delegate).changeMonitor(monitor); 98 } else { 99 delegate = monitor; 100 } 101 } 102 103 public ComponentMonitor currentMonitor() { 104 if ( delegate instanceof ComponentMonitorStrategy ){ 105 return ((ComponentMonitorStrategy)delegate).currentMonitor(); 106 } else { 107 return delegate; 108 } 109 } 110 111 private void checkMonitor(ComponentMonitor monitor) { 112 if ( monitor == null ){ 113 throw new NullPointerException ("monitor"); 114 } 115 } 116 117 } 118 | Popular Tags |