Class AbstractBehavior<T>

    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void accept​(PicoVisitor visitor)
      Accepts a visitor for this ComponentAdapter.
      void changeMonitor​(ComponentMonitor monitor)
      Delegates change of monitor if the delegate supports a component monitor strategy.
      boolean componentHasLifecycle()
      Invokes delegate hasLifecycle method if the delegate is a Behavior Test if a component honors a lifecycle.
      ComponentMonitor currentMonitor()
      Returns delegate's current monitor if the delegate supports a component monitor strategy.
      void dispose​(java.lang.Object component)
      Invokes delegate dispose method if the delegate is a LifecycleStrategy Invoke the "dispose" method on the component instance if this is disposable.
      void dispose​(PicoContainer container)
      Invokes delegate dispose method if the delegate is a Behavior Invoke the "dispose" method on the component.
      <U extends ComponentAdapter>
      U
      findAdapterOfType​(java.lang.Class<U> adapterType)
      Locates a component adapter of type componentAdapterType in the ComponentAdapter chain.
      java.lang.Class<? extends T> getComponentImplementation()
      Retrieve the class of the component.
      T getComponentInstance​(PicoContainer container)
      Retrieve the component instance.
      T getComponentInstance​(PicoContainer container, java.lang.reflect.Type into)
      Retrieve the component instance.
      java.lang.Object getComponentKey()
      Retrieve the key associated with the component.
      ComponentAdapter<T> getDelegate()
      Component adapters may be nested in a chain, and this method is used to grab the next ComponentAdapter in the chain.
      boolean hasLifecycle​(java.lang.Class<?> type)
      Invokes delegate hasLifecycle(Class) method if the delegate is a LifecycleStrategy Test if a component instance has a lifecycle.
      boolean isLazy​(ComponentAdapter<?> adapter)
      Is a component eager (not lazy) in that it should start when start() or equivalent is called, or lazy (it will only start on first getComponent() ).
      boolean isStarted()  
      void start​(java.lang.Object component)
      Invokes delegate start method if the delegate is a LifecycleStrategy Invoke the "start" method on the component instance if this is startable.
      void start​(PicoContainer container)
      Invokes delegate start method if the delegate is a Behavior Invoke the "start" method on the component.
      void stop​(java.lang.Object component)
      Invokes delegate stop method if the delegate is a LifecycleStrategy Invoke the "stop" method on the component instance if this is stoppable.
      void stop​(PicoContainer container)
      Invokes delegate stop method if the delegate is a Behavior Invoke the "stop" method on the component.
      java.lang.String toString()  
      void verify​(PicoContainer container)
      Verify that all dependencies for this adapter can be satisfied.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

    • Method Detail

      • getComponentKey

        public java.lang.Object getComponentKey()
        Description copied from interface: ComponentAdapter
        Retrieve the key associated with the component.
        Specified by:
        getComponentKey in interface ComponentAdapter<T>
        Returns:
        the component's key. Should either be a class type (normally an interface) or an identifier that is unique (within the scope of the current PicoContainer).
      • getComponentImplementation

        public java.lang.Class<? extends T> getComponentImplementation()
        Description copied from interface: ComponentAdapter
        Retrieve the class of the component.
        Specified by:
        getComponentImplementation in interface ComponentAdapter<T>
        Returns:
        the component's implementation class. Should normally be a concrete class (ie, a class that can be instantiated).
      • getComponentInstance

        public T getComponentInstance​(PicoContainer container)
                               throws PicoCompositionException
        Description copied from interface: ComponentAdapter
        Retrieve the component instance. This method will usually create a new instance each time it is called, but that is not required. For example, Cached will always return the same instance.
        Specified by:
        getComponentInstance in interface ComponentAdapter<T>
        Parameters:
        container - the PicoContainer, that is used to resolve any possible dependencies of the instance.
        Returns:
        the component instance.
        Throws:
        PicoCompositionException - if the component has dependencies which could not be resolved, or instantiation of the component lead to an ambigous situation within the container.
      • getComponentInstance

        public T getComponentInstance​(PicoContainer container,
                                      java.lang.reflect.Type into)
                               throws PicoCompositionException
        Description copied from interface: ComponentAdapter
        Retrieve the component instance. This method will usually create a new instance each time it is called, but that is not required. For example, Cached will always return the same instance.
        Specified by:
        getComponentInstance in interface ComponentAdapter<T>
        Parameters:
        container - the PicoContainer, that is used to resolve any possible dependencies of the instance.
        into - the class that is about to be injected into. Use ComponentAdapter.NOTHING.class if this is not important to you.
        Returns:
        the component instance.
        Throws:
        PicoCompositionException - if the component has dependencies which could not be resolved, or instantiation of the component lead to an ambiguous situation within the container.
      • verify

        public void verify​(PicoContainer container)
                    throws PicoCompositionException
        Description copied from interface: ComponentAdapter
        Verify that all dependencies for this adapter can be satisfied. Normally, the adapter should verify this by checking that the associated PicoContainer contains all the needed dependencies.
        Specified by:
        verify in interface ComponentAdapter<T>
        Parameters:
        container - the PicoContainer, that is used to resolve any possible dependencies of the instance.
        Throws:
        PicoCompositionException - if one or more dependencies cannot be resolved.
      • getDelegate

        public final ComponentAdapter<T> getDelegate()
        Description copied from interface: ComponentAdapter
        Component adapters may be nested in a chain, and this method is used to grab the next ComponentAdapter in the chain.
        Specified by:
        getDelegate in interface ComponentAdapter<T>
        Returns:
        the next component adapter in line or null if there is no delegate ComponentAdapter.
      • findAdapterOfType

        public final <U extends ComponentAdapter> U findAdapterOfType​(java.lang.Class<U> adapterType)
        Description copied from interface: ComponentAdapter
        Locates a component adapter of type componentAdapterType in the ComponentAdapter chain. Will return null if there is no adapter of the given type.
        Specified by:
        findAdapterOfType in interface ComponentAdapter<T>
        Type Parameters:
        U - the type of ComponentAdapter being located.
        Parameters:
        adapterType - the class of the adapter type being located. Never null.
        Returns:
        the appropriate component adapter of type U. May return null if the component adapter type is not returned.
      • accept

        public void accept​(PicoVisitor visitor)
        Description copied from interface: ComponentAdapter
        Accepts a visitor for this ComponentAdapter. The method is normally called by visiting a PicoContainer, that cascades the visitor also down to all its ComponentAdapter instances.
        Specified by:
        accept in interface ComponentAdapter<T>
        Parameters:
        visitor - the visitor.
      • changeMonitor

        public void changeMonitor​(ComponentMonitor monitor)
        Delegates change of monitor if the delegate supports a component monitor strategy. Changes the component monitor used
        Specified by:
        changeMonitor in interface ComponentMonitorStrategy
        Parameters:
        monitor - the new ComponentMonitor to use
      • start

        public void start​(PicoContainer container)
        Invokes delegate start method if the delegate is a Behavior Invoke the "start" method on the component.
        Specified by:
        start in interface ComponentLifecycle<T>
        Parameters:
        container - the container to "start" the component
      • stop

        public void stop​(PicoContainer container)
        Invokes delegate stop method if the delegate is a Behavior Invoke the "stop" method on the component.
        Specified by:
        stop in interface ComponentLifecycle<T>
        Parameters:
        container - the container to "stop" the component
      • dispose

        public void dispose​(PicoContainer container)
        Invokes delegate dispose method if the delegate is a Behavior Invoke the "dispose" method on the component.
        Specified by:
        dispose in interface ComponentLifecycle<T>
        Parameters:
        container - the container to "dispose" the component
      • componentHasLifecycle

        public boolean componentHasLifecycle()
        Invokes delegate hasLifecycle method if the delegate is a Behavior Test if a component honors a lifecycle.
        Specified by:
        componentHasLifecycle in interface ComponentLifecycle<T>
        Returns:
        true if the component has a lifecycle
      • start

        public void start​(java.lang.Object component)
        Invokes delegate start method if the delegate is a LifecycleStrategy Invoke the "start" method on the component instance if this is startable. It is up to the implementation of the strategy what "start" and "startable" means.
        Specified by:
        start in interface LifecycleStrategy
        Parameters:
        component - the instance of the component to start
      • stop

        public void stop​(java.lang.Object component)
        Invokes delegate stop method if the delegate is a LifecycleStrategy Invoke the "stop" method on the component instance if this is stoppable. It is up to the implementation of the strategy what "stop" and "stoppable" means.
        Specified by:
        stop in interface LifecycleStrategy
        Parameters:
        component - the instance of the component to stop
      • dispose

        public void dispose​(java.lang.Object component)
        Invokes delegate dispose method if the delegate is a LifecycleStrategy Invoke the "dispose" method on the component instance if this is disposable. It is up to the implementation of the strategy what "dispose" and "disposable" means.
        Specified by:
        dispose in interface LifecycleStrategy
        Parameters:
        component - the instance of the component to dispose
      • hasLifecycle

        public boolean hasLifecycle​(java.lang.Class<?> type)
        Invokes delegate hasLifecycle(Class) method if the delegate is a LifecycleStrategy Test if a component instance has a lifecycle.
        Specified by:
        hasLifecycle in interface LifecycleStrategy
        Parameters:
        type - the component's type
        Returns:
        true if the component has a lifecycle
      • isLazy

        public boolean isLazy​(ComponentAdapter<?> adapter)
        Description copied from interface: LifecycleStrategy
        Is a component eager (not lazy) in that it should start when start() or equivalent is called, or lazy (it will only start on first getComponent() ). The default is the first of those two.
        Specified by:
        isLazy in interface LifecycleStrategy
        Returns:
        true if lazy, false if not lazy
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object