Class ExoContainer

java.lang.Object
org.exoplatform.container.AbstractContainer
org.exoplatform.container.ExoContainer
All Implemented Interfaces:
Serializable, Container, Disposable, Startable
Direct Known Subclasses:
PortalContainer, RootContainer, StandaloneContainer

public class ExoContainer extends AbstractContainer
Created by The eXo Platform SAS
The Exo Container is an object responsible for loading services/components. The eXoContainer class is inherited by all the containers, including RootContainer, PortalContainer, and StandaloneContainer. It itself inherits from a Container which allows eXo to apply the Inversion of Control (also known as IoC) principles.
See Also:
  • Field Details

  • Constructor Details

    • ExoContainer

      public ExoContainer()
    • ExoContainer

      public ExoContainer(ExoContainer parent)
  • Method Details

    • getProfilesFromProperty

      public static Set<String> getProfilesFromProperty()
      Returns an unmodifiable set of profiles defined by the value returned by invoking PropertyManager.getProperty(String) with the PropertyManager.RUNTIME_PROFILES property.
      Returns:
      the set of profiles
    • getProfiles

      public static Set<String> getProfiles()
      Returns:
      current container profiles, else return default profiles retrieved by getProfilesFromProperty()
    • hasProfileInProperty

      public static boolean hasProfileInProperty(String profileName)
      Indicates whether or not a given profile exists
      Parameters:
      profileName - the name of the profile to check
      Returns:
      true if the profile exists, false otherwise.
    • hasProfile

      public static boolean hasProfile(String profileName)
      Indicates whether the current container has a given profile.
      Parameters:
      profileName - profile to check
      Returns:
      true if current ExoContainer retrieved from ExoContainerContext was started with the given profile, false otherwise.
    • getContext

      public ExoContainerContext getContext()
    • initContainerInternal

      protected void initContainerInternal()
    • dispose

      public void dispose()
      Description copied from class: AbstractContainer
      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
      Overrides:
      dispose in class AbstractContainer
    • start

      public void start(boolean init)
      Starts the container
      Parameters:
      init - indicates if the container must be initialized first
    • initialize

      public void initialize()
      Description copied from class: AbstractContainer
      Initializes the container
      Specified by:
      initialize in interface Container
      Overrides:
      initialize in class AbstractContainer
    • start

      public void start()
      Description copied from class: AbstractContainer
      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
      Overrides:
      start in class AbstractContainer
    • stop

      public void stop()
      Description copied from class: AbstractContainer
      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
      Overrides:
      stop in class AbstractContainer
    • addComponentLifecylePlugin

      public void addComponentLifecylePlugin(ComponentLifecyclePlugin plugin)
    • addContainerLifecylePlugin

      public void addContainerLifecylePlugin(ContainerLifecyclePlugin plugin)
    • getConfiguration

      protected Configuration getConfiguration()
      Gets the ConfigurationManager from the given ExoContainer if it exists, then returns the nested Configuration otherwise it returns null
    • getExternalComponentPluginsUnused

      protected Collection<ExternalComponentPlugins> getExternalComponentPluginsUnused()
      Gives all the ExternalComponentPlugins that have not been used, null if there are all used.
    • unregisterAllComponents

      protected void unregisterAllComponents()
      Unregister all components from container to avoid keeping instances in memory.
    • registerComponentImplementation

      public <T> ComponentAdapter<T> registerComponentImplementation(Class<T> componentImplementation) throws ContainerException
      Register a component using the componentImplementation as key. Calling this method is equivalent to calling registerComponentImplementation(componentImplementation, componentImplementation).
      Parameters:
      componentImplementation - the concrete component class.
      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.
    • registerComponentInstance

      public <T> ComponentAdapter<T> registerComponentInstance(T componentInstance) throws ContainerException
      Register an arbitrary object. The class of the object will be used as a key. Calling this method is equivalent to calling * registerComponentImplementation(componentImplementation, componentImplementation).
      Parameters:
      componentInstance - the instance of the component to register
      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.
    • createComponent

      public <T> T createComponent(Class<T> clazz) throws Exception
      Creates a component corresponding to the given Class with no parameters This is equivalent to call AbstractContainer.createComponent(Class, InitParams) with null as InitParams
      Parameters:
      clazz - the Class of the object to create
      Returns:
      an instance of the component
      Throws:
      Exception - if any issue occurs while creating the component.
    • getComponentAdapter

      public ComponentAdapter<?> getComponentAdapter(Object componentKey)
      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.
      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.
    • getComponentInstance

      public Object getComponentInstance(Object componentKey)
      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.
      Parameters:
      componentKey - the key that the component was registered with.
      Returns:
      an instantiated component, or null if no component has been registered for the specified key.
    • getRegisteredComponentNames

      public Set<String> getRegisteredComponentNames() throws ContainerException
      Throws:
      ContainerException
    • getParent

      public ExoContainer getParent()
      Gives the parent container of this container.
      Returns:
      a ExoContainer instance, or null if this container does not have a parent.
    • canBeStarted

      public boolean canBeStarted()
      Indicates whether or not the container can be started
      Returns:
      true if it can be started, false otherwise.
    • canBeStopped

      public boolean canBeStopped()
      Indicates whether or not the container can be stopped
      Returns:
      true if it can be stopped, false otherwise.
    • canBeDisposed

      public boolean canBeDisposed()
      Indicates whether or not the container can be disposed
      Returns:
      true if it can be disposed, false otherwise.
    • canBeInitialized

      protected boolean canBeInitialized()
      Indicates whether or not the container can be initialized
      Returns:
      true if it can be initialized, false otherwise.
    • getContextManager

      public ContextManager getContextManager()
      Gives the ContextManager that has been registered
      Returns:
      the ContextManager related to this container, null otherwise.
    • isContextManagerLoaded

      public boolean isContextManagerLoaded()
      Indicates whether or not the ContextManager has already been loaded
      Returns:
      true if the ContextManager has been loaded, false otherwise.
    • getComponentInstanceOfType

      public <T> T getComponentInstanceOfType(Class<T> componentType)
      This method is equivalent to getComponentInstanceOfType(Class, boolean) with true for the parameter autoRegistration
    • getComponentInstanceOfType

      public <T> T getComponentInstanceOfType(Class<T> componentType, boolean autoRegistration)
      Find a component instance matching the specified type. If none can be found it will try to auto register the component according to the content of the annotation DefinitionByType if the parameter autoRegistration has been set to true.
      Specified by:
      getComponentInstanceOfType in interface Container
      Overrides:
      getComponentInstanceOfType in class AbstractContainer
      Parameters:
      componentType - the type of the component.
      autoRegistration - indicates whether the auto registration should be performed or not
      Returns:
      the adapter matching the class.
    • getComponentAdapterOfType

      public <T> ComponentAdapter<T> getComponentAdapterOfType(Class<T> componentType)
      This method is equivalent to getComponentAdapterOfType(Class, boolean) with true for the parameter autoRegistration
      Parameters:
      componentType - the type of the component.
      Returns:
      the component adapter associated with this class, 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. If none can be found it will try to auto register the component according to the content of the annotation DefinitionByType if the parameter autoRegistration has been set to true.
      Specified by:
      getComponentAdapterOfType in interface Container
      Overrides:
      getComponentAdapterOfType in class AbstractContainer
      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.
    • getComponentInstance

      public <T> T getComponentInstance(Object componentKey, Class<T> bindType)
      This method is equivalent to getComponentInstance(Object, Class, boolean) with true for the parameter autoRegistration
      Parameters:
      componentKey - the key that the component was registered with.
      bindType - the expected type of the instance if one can be found.
      Returns:
      an instantiated component, or null if no component has been registered for the specified key.
    • 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. If none can be found and the parameter autoRegistration has been set to true, it will try to auto register the component according to the content of:
      Specified by:
      getComponentInstance in interface Container
      Overrides:
      getComponentInstance in class AbstractContainer
      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.
    • getComponentAdapter

      public <T> ComponentAdapter<T> getComponentAdapter(Object componentKey, Class<T> bindType)
      This method is equivalent to getComponentAdapter(Object, Class, boolean) with true for the parameter autoRegistration
      Parameters:
      componentKey - the key that the component was registered with.
      bindType - the expected raw type of the adapter if one can be found.
      Returns:
      the component adapter associated with this key, or null if no component has been registered for the specified key.
    • 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. If none can be found and the parameter autoRegistration has been set to true, it will try to auto register the component according to the content of:
      Specified by:
      getComponentAdapter in interface Container
      Overrides:
      getComponentAdapter in class AbstractContainer
      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.