1 9 package org.picocontainer.alternatives; 10 11 import org.picocontainer.ComponentAdapter; 12 import org.picocontainer.MutablePicoContainer; 13 import org.picocontainer.Parameter; 14 import org.picocontainer.PicoContainer; 15 import org.picocontainer.PicoRegistrationException; 16 import org.picocontainer.LifecycleManager; 17 import org.picocontainer.defaults.ComponentAdapterFactory; 18 import org.picocontainer.defaults.DefaultComponentAdapterFactory; 19 import org.picocontainer.defaults.DefaultPicoContainer; 20 import org.picocontainer.defaults.DefaultLifecycleManager; 21 22 import java.io.Serializable ; 23 24 33 public class ImplementationHidingPicoContainer extends AbstractDelegatingMutablePicoContainer implements Serializable { 34 35 private ComponentAdapterFactory caf; 36 private LifecycleManager lifecycleManager; 37 38 41 public ImplementationHidingPicoContainer(ComponentAdapterFactory caf, PicoContainer parent, LifecycleManager lifecycleManager) { 42 super(new DefaultPicoContainer(caf, parent, lifecycleManager)); 43 this.caf = caf; 44 this.lifecycleManager = lifecycleManager; 45 } 46 47 48 public ImplementationHidingPicoContainer(ComponentAdapterFactory caf, PicoContainer parent) { 49 this(caf, parent, new DefaultLifecycleManager()); 50 } 51 52 55 public ImplementationHidingPicoContainer(PicoContainer parent) { 56 this(new DefaultComponentAdapterFactory(), parent); 57 } 58 59 60 63 public ImplementationHidingPicoContainer() { 64 this(null); 65 } 66 67 public ComponentAdapter registerComponentImplementation(Object componentKey, Class componentImplementation) throws PicoRegistrationException { 68 if (componentKey instanceof Class ) { 69 Class clazz = (Class ) componentKey; 70 if (clazz.isInterface()) { 71 ComponentAdapter delegate = caf.createComponentAdapter(componentKey, componentImplementation, null); 72 return getDelegate().registerComponent(new ImplementationHidingComponentAdapter(delegate, true)); 73 } 74 } 75 return getDelegate().registerComponentImplementation(componentKey, componentImplementation); 76 } 77 78 public ComponentAdapter registerComponentImplementation(Object componentKey, Class componentImplementation, Parameter[] parameters) throws PicoRegistrationException { 79 if (componentKey instanceof Class ) { 80 Class clazz = (Class ) componentKey; 81 if (clazz.isInterface()) { 82 ComponentAdapter delegate = caf.createComponentAdapter(componentKey, componentImplementation, parameters); 83 ImplementationHidingComponentAdapter ihDelegate = new ImplementationHidingComponentAdapter(delegate, true); 84 return getDelegate().registerComponent(ihDelegate); 85 } 86 } 87 return getDelegate().registerComponentImplementation(componentKey, componentImplementation, parameters); 88 } 89 90 public MutablePicoContainer makeChildContainer() { 91 ImplementationHidingPicoContainer pc = new ImplementationHidingPicoContainer(caf, this, lifecycleManager); 92 getDelegate().addChildContainer(pc); 93 return pc; 94 } 95 96 } 97 | Popular Tags |