Class AbstractContainer

    • Constructor Detail

      • AbstractContainer

        protected AbstractContainer()
      • AbstractContainer

        protected AbstractContainer​(Interceptor successor)
    • Method Detail

      • start

        public void start()
        Start this component. Called initially at the begin of the lifecycle. It can be called again after a stop.
        Specified by:
        start in interface Startable
      • stop

        public void stop()
        Stop this component. Called near the end of the lifecycle. It can be called again after a further start. Implement Disposable if you need a single call at the definite end of the lifecycle.
        Specified by:
        stop in interface Startable
      • dispose

        public void dispose()
        Dispose this component. The component should deallocate all resources. The contract for this method defines a single call at the end of this component's life.
        Specified by:
        dispose in interface Disposable
      • getComponentInstance

        public <T> T getComponentInstance​(Object componentKey,
                                          Class<T> bindType,
                                          boolean autoRegistration)
        Retrieve a component instance registered with a specific key. If a component cannot be found in this container, the parent container (if one exists) will be searched.
        Specified by:
        getComponentInstance in interface Container
        Parameters:
        componentKey - the key that the component was registered with.
        bindType - the expected type of the instance if one can be found.
        autoRegistration - indicates whether the auto registration should be performed or not
        Returns:
        an instantiated component, or null if no component has been registered for the specified key.
      • getComponentInstanceOfType

        public <T> T getComponentInstanceOfType​(Class<T> componentType,
                                                boolean autoRegistration)
        Find a component instance matching the specified type.
        Specified by:
        getComponentInstanceOfType in interface Container
        Parameters:
        componentType - the type of the component.
        autoRegistration - indicates whether the auto registration should be performed or not
        Returns:
        the adapter matching the class.
      • getComponentAdapter

        public <T> ComponentAdapter<T> getComponentAdapter​(Object componentKey,
                                                           Class<T> bindType,
                                                           boolean autoRegistration)
        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 Container
        Parameters:
        componentKey - the key that the component was registered with.
        bindType - the expected raw type of the adapter if one can be found.
        autoRegistration - indicates whether the auto registration should be performed or not
        Returns:
        the component adapter associated with this key, or null if no component has been registered for the specified key.
      • getComponentAdapterOfType

        public <T> ComponentAdapter<T> getComponentAdapterOfType​(Class<T> componentType,
                                                                 boolean autoRegistration)
        Find a component adapter associated with the specified type. If a component adapter cannot be found in this container, the parent container (if one exists) will be searched.
        Specified by:
        getComponentAdapterOfType in interface Container
        Parameters:
        componentType - the type of the component.
        autoRegistration - indicates whether the auto registration should be performed or not
        Returns:
        the component adapter associated with this class, or null if no component has been registered for the specified key.
      • getComponentAdaptersOfType

        public <T> List<ComponentAdapter<T>> getComponentAdaptersOfType​(Class<T> componentType)
        Retrieve all component adapters inside this container that are associated with the specified type. The component adapters from the parent container are not returned.
        Specified by:
        getComponentAdaptersOfType in interface Container
        Parameters:
        componentType - the type of the components.
        Returns:
        a collection containing all the ComponentAdapters inside this container that are associated with the specified type. Changes to this collection will not be reflected in the container itself.
      • getComponentInstancesOfType

        public <T> List<T> getComponentInstancesOfType​(Class<T> componentType)
                                                throws ContainerException
        Returns a List of components of a certain componentType. The list is ordered by instantiation order, starting with the components instantiated first at the beginning.
        Specified by:
        getComponentInstancesOfType in interface Container
        Parameters:
        componentType - the searched type.
        Returns:
        a List of components.
        Throws:
        ContainerException
      • accept

        public void accept​(ContainerVisitor visitor)
        Accepts a visitor that should visit the child containers, component adapters and component instances.
        Specified by:
        accept in interface Container
        Parameters:
        visitor - the visitor
      • registerComponentImplementation

        public <T> ComponentAdapter<T> registerComponentImplementation​(Object componentKey,
                                                                       Class<T> componentImplementation)
                                                                throws ContainerException
        Register a component.
        Specified by:
        registerComponentImplementation in interface Container
        Parameters:
        componentKey - 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.
        componentImplementation - the component's implementation class. This must be a concrete class (ie, a class that can be instantiated).
        Returns:
        the ComponentAdapter that has been associated with this component. In the majority of cases, this return value can be safely ignored, as one of the getXXX() methods of the Container interface can be used to retrieve a reference to the component later on.
        Throws:
        ContainerException - if registration of the component fails.
      • registerComponentInstance

        public <T> ComponentAdapter<T> registerComponentInstance​(Object componentKey,
                                                                 T componentInstance)
                                                          throws ContainerException
        Register an arbitrary object as a component in the container. This is handy when other components in the same container have dependencies on this kind of object, but where letting the container manage and instantiate it is impossible.
        Beware that too much use of this method is an antipattern.
        Specified by:
        registerComponentInstance in interface Container
        Parameters:
        componentKey - 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 implementing container.
        componentInstance - an arbitrary object.
        Returns:
        the ComponentAdapter that has been associated with this component. In the majority of cases, this return value can be safely ignored, as one of the getXXX() methods of the Container interface can be used to retrieve a reference to the component later on.
        Throws:
        ContainerException - if registration fails.
      • unregisterComponent

        public ComponentAdapter<?> unregisterComponent​(Object componentKey)
        Unregister a component by key.
        Specified by:
        unregisterComponent in interface Container
        Parameters:
        componentKey - key of the component to unregister.
        Returns:
        the ComponentAdapter that was associated with this component.
      • createComponent

        public <T> T createComponent​(Class<T> clazz,
                                     InitParams params)
                              throws Exception
        Creates a component corresponding to the given Class with the given InitParams
        Specified by:
        createComponent in interface Container
        Parameters:
        clazz - the Class of the object to create
        params - the parameters to use to create the component
        Returns:
        an instance of the component
        Throws:
        Exception - if any issue occurs while creating the component.
      • initialize

        public void initialize()
        Initializes the container
        Specified by:
        initialize in interface Container