Class DefaultClassLoadingPicoContainer

    • Field Detail

      • namedChildContainers

        protected final java.util.Map<java.lang.String,​PicoContainer> namedChildContainers
    • Constructor Detail

      • DefaultClassLoadingPicoContainer

        public DefaultClassLoadingPicoContainer​(java.lang.ClassLoader classLoader,
                                                ComponentFactory componentFactory,
                                                PicoContainer parent)
      • DefaultClassLoadingPicoContainer

        public DefaultClassLoadingPicoContainer​(java.lang.ClassLoader classLoader,
                                                MutablePicoContainer delegate)
      • DefaultClassLoadingPicoContainer

        public DefaultClassLoadingPicoContainer​(java.lang.ClassLoader classLoader,
                                                PicoContainer parent,
                                                ComponentMonitor componentMonitor)
      • DefaultClassLoadingPicoContainer

        public DefaultClassLoadingPicoContainer​(ComponentFactory componentFactory)
      • DefaultClassLoadingPicoContainer

        public DefaultClassLoadingPicoContainer​(PicoContainer parent)
      • DefaultClassLoadingPicoContainer

        public DefaultClassLoadingPicoContainer​(MutablePicoContainer delegate)
      • DefaultClassLoadingPicoContainer

        public DefaultClassLoadingPicoContainer​(java.lang.ClassLoader classLoader)
      • DefaultClassLoadingPicoContainer

        public DefaultClassLoadingPicoContainer()
    • Method Detail

      • changeMonitor

        public void changeMonitor​(ComponentMonitor monitor)
        Propagates the monitor change down the delegate chain if a delegate that implements ComponentMonitorStrategy exists. Because of the ComponentMonitorStrategy API, not all delegates can have their API changed. If a delegate implementing ComponentMonitorStrategy cannot be found, an exception is thrown.
        Specified by:
        changeMonitor in interface ComponentMonitorStrategy
        Parameters:
        monitor - the monitor to swap.
        Throws:
        java.lang.IllegalStateException - if no delegate can be found that implements ComponentMonitorStrategy.
      • getComponent

        public final java.lang.Object getComponent​(java.lang.Object componentKeyOrType)
                                            throws PicoException
        Description copied from interface: PicoContainer
        Retrieve a component instance registered with a specific key or type. If a component cannot be found in this container, the parent container (if one exists) will be searched.
        Specified by:
        getComponent in interface PicoContainer
        Overrides:
        getComponent in class AbstractDelegatingPicoContainer
        Parameters:
        componentKeyOrType - the key or Type that the component was registered with.
        Returns:
        an instantiated component, or null if no component has been registered for the specified key.
        Throws:
        PicoException
      • makeChildContainer

        public final MutablePicoContainer makeChildContainer()
        Description copied from interface: MutablePicoContainer
        Make a child container, using both the same implementation of MutablePicoContainer as the parent and identical behaviors as well. It will have a reference to this as parent. This will list the resulting MPC as a child. Lifecycle events will be cascaded from parent to child as a consequence of this.

        Note that for long-lived parent containers, you need to unregister child containers made with this call before disposing or you will leak memory. (Experience speaking here! )

        Incorrect Example:

           MutablePicoContainer parent = new PicoBuilder().withCaching().withLifecycle().build();
           MutablePicoContainer child = parent.makeChildContainer();
           child = null; //Child still retains in memory because parent still holds reference.
         

        Correct Example:

           MutablePicoContainer parent = new PicoBuilder().withCaching().withLifecycle().build();
           MutablePicoContainer child = parent.makeChildContainer();
           parent.removeChildContainer(child); //Remove the bi-directional references.
           child = null; 
         
        Specified by:
        makeChildContainer in interface MutablePicoContainer
        Overrides:
        makeChildContainer in class AbstractDelegatingMutablePicoContainer
        Returns:
        the new child container.
      • makeChildContainer

        public ClassLoadingPicoContainer makeChildContainer​(java.lang.String name)
        Makes a child container with the same basic characteristics of this object (ComponentFactory, PicoContainer type, Behavior, etc)
        Specified by:
        makeChildContainer in interface ClassLoadingPicoContainer
        Parameters:
        name - the name of the child container
        Returns:
        The child MutablePicoContainer
      • getNamedContainers

        protected final java.util.Map<java.lang.String,​PicoContainer> getNamedContainers()
      • addComponent

        public MutablePicoContainer addComponent​(java.lang.Object key,
                                                 java.lang.Object componentImplementationOrInstance,
                                                 Parameter... parameters)
        Description copied from interface: MutablePicoContainer
        Register a component and creates specific instructions on which constructor to use, along with which components and/or constants to provide as constructor arguments. These "directives" are provided through an array of Parameter objects. Parameter[0] correspondes to the first constructor argument, Parameter[N] corresponds to the N+1th constructor argument.

        Tips for Parameter usage

        • Partial Autowiring: If you have two constructor args to match and you only wish to specify one of the constructors and let PicoContainer wire the other one, you can use as parameters: new ComponentParameter(), new ComponentParameter("someService") The default constructor for the component parameter indicates auto-wiring should take place for that parameter.
        • Force No-Arg constructor usage: If you wish to force a component to be constructed with the no-arg constructor, use a zero length Parameter array. Ex: new Parameter[0]
          Specified by:
          addComponent in interface MutablePicoContainer
          Overrides:
          addComponent in class AbstractDelegatingMutablePicoContainer
          Parameters:
          key - a key that identifies the component. Must be unique within the container. The type of the key object has no semantic significance unless explicitly specified in the documentation of the implementing container.
          componentImplementationOrInstance - the component's implementation class. This must be a concrete class (ie, a class that can be instantiated). Or an intance of the compoent.
          parameters - the parameters that gives the container hints about what arguments to pass to the constructor when it is instantiated. Container implementations may ignore one or more of these hints.
          Returns:
          the same instance of MutablePicoContainer
          See Also:
          Parameter, ConstantParameter, ComponentParameter
        • getComponentAdapter

          public ComponentAdapter<?> getComponentAdapter​(java.lang.Object componentKey)
          Description copied from interface: PicoContainer
          Find a component adapter associated with the specified key. If a component adapter cannot be found in this container, the parent container (if one exists) will be searched.
          Specified by:
          getComponentAdapter in interface PicoContainer
          Overrides:
          getComponentAdapter in class AbstractDelegatingPicoContainer
          Parameters:
          componentKey - the key that the component was registered with.
          Returns:
          the component adapter associated with this key, or null if no component has been registered for the specified key.