Class Context

java.lang.Object
org.refcodes.decoupling.Context
All Implemented Interfaces:
DependenciesAccessor, org.refcodes.mixin.Schemable

public class Context extends Object implements org.refcodes.mixin.Schemable, DependenciesAccessor
The Context describes the components and modules wired together by the Reactor.
  • Constructor Details

    • Context

      protected Context(Object[] aProfiles)
      Empty constructor to be used in conjunction with the initialize(Dependency[]) method!.
      Parameters:
      aProfiles - The profiles which have been applied when creating this Context.
    • Context

      public Context(Dependency<?>[] aDependencies, Object[] aProfiles)
      Creates the Context with the managed Dependency instances.
      Parameters:
      aDependencies - The Dependency declarations of which the Context consists.
      aProfiles - The profiles which have been applied when creating this Context.
  • Method Details

    • getProfiles

      public Object[] getProfiles()
      Retrieves the The profiles which have been applied when creating this Context.
      Returns:
      The according profiles.
    • getDependencies

      public Dependency<?>[] getDependencies()
      Retrieves the Dependency declarations contained in the Context.
      Specified by:
      getDependencies in interface DependenciesAccessor
      Returns:
      The Dependency declarations of which the Context consists.
    • getDependencyByInstance

      public Dependency<?> getDependencyByInstance(Object aInstance)
      Determines the Dependency element for the given instance created from the Dependency.
      Parameters:
      aInstance - The instance which's Dependency element creating this instance is to be retrieved.
      Returns:
      The according Dependency element or null if none Dependency element is responsible for crating the provided instance.
    • getDependencyByAlias

      public Dependency<?> getDependencyByAlias(String aAlias)
      Retrieves the Dependency declaration with the given alias managed by this Context, derived from the Dependency Dependency declaration from which the Reactor created this Context.
      Parameters:
      aAlias - The alias of Dependency declaration to retrieve.
      Returns:
      The according Dependency declaration managed by this Context.
    • getDependenciesByType

      public <T> Dependency<T>[] getDependenciesByType(Class<T> aType)
      Retrieves the Dependency declarations of the given type managed by this Context, derived from the Dependency declarations from which the Reactor created this Context.
      Type Parameters:
      T - the generic type
      Parameters:
      aType - The type of Dependency declarations to retrieve.
      Returns:
      The according Dependency declarations managed by this Context.
    • getDependenciesByTags

      public Dependency<?>[] getDependenciesByTags(Object... aTags)
      Retrieves the Dependency declarations of given tags managed by this Context, derived from the Dependency Dependency declarations from which the Reactor created this Context.
      Parameters:
      aTags - The tags of the Dependency declarations to retrieve.
      Returns:
      The according Dependency declarations managed by this Context.
    • getDependenciesByProfiles

      public Dependency<?>[] getDependenciesByProfiles(Object... aProfiles)
      Retrieves the Dependency declarations of given profiles managed by this Context, derived from the Dependency Dependency declarations from which the Reactor created this Context.
      Parameters:
      aProfiles - The profiles of the Dependency declarations to retrieve.
      Returns:
      The according Dependency declarations managed by this Context.
    • getInstances

      public Object[] getInstances()
      Retrieves the instances managed by this Context, derived from the Dependency declarations from which the Reactor created this Context.
      Returns:
      The instances managed by this Context.
    • getSingletonByAlias

      public Object getSingletonByAlias(String aAlias)
      Retrieves the instances created by a Dependency having InstanceMetrics with InstanceMetrics.isSingleton() being true (e.g. InstanceMode.SINGLETON_IS_MANDATORY or InstanceMode.SINGLETON_ON_DEMAND) and with the given alias managed by this Context, derived from the Dependency instances from which the Reactor created this Context.
      Parameters:
      aAlias - The alias of instances to retrieve.
      Returns:
      The according instances managed by this Context.
    • getSingletonByAlias

      public <T> T getSingletonByAlias(String aAlias, Class<T> aType)
      Retrieves the instances created by a Dependency having InstanceMetrics with InstanceMetrics.isSingleton() being true (e.g. InstanceMode.SINGLETON_IS_MANDATORY or InstanceMode.SINGLETON_ON_DEMAND) and with the given alias managed by this Context, derived from the Dependency instances from which the Reactor created this Context.
      Type Parameters:
      T - The type of the instance to be retrieved.
      Parameters:
      aAlias - The alias of instances to retrieve.
      aType - The type of the instance to retrieve.
      Returns:
      The according instances managed by this Context.
    • getInstancesByAlias

      public Object[] getInstancesByAlias(String aAlias)
      Retrieves the instances with the given alias managed by this Context, derived from the Dependency declarations from which the Reactor created this Context.
      Parameters:
      aAlias - The alias of instances to retrieve.
      Returns:
      The according instances managed by this Context.
    • getInstancesByType

      public <T> T[] getInstancesByType(Class<T> aType)
      Retrieves the instances of the given type managed by this Context, derived from the Dependency declarations from which the Reactor created this Context.
      Type Parameters:
      T - the generic type
      Parameters:
      aType - The type of instances to retrieve.
      Returns:
      The according instances managed by this Context.
    • getFirstByType

      public <T> T getFirstByType(Class<T> aType)
      Retrieves the first instance of the given type managed by this Context, derived from the Dependency declarations from which the Reactor created this Context.
      Type Parameters:
      T - the generic type
      Parameters:
      aType - The type of instance to retrieve.
      Returns:
      The according first instance managed by this Context or null if there is none.
    • getInstancesByTags

      public Object[] getInstancesByTags(Object... aTags)
      Retrieves the instances of given tags managed by this Context, derived from the Dependency declarations from which the Reactor created this Context.
      Parameters:
      aTags - The tags of the instances to retrieve.
      Returns:
      The according instances managed by this Context.
    • getInstancesByProfiles

      public Object[] getInstancesByProfiles(Object... aProfiles)
      Retrieves the instances of given profiles managed by this Context, derived from the Dependency declarations from which the Reactor created this Context.
      Parameters:
      aProfiles - The profiles of the instances to retrieve.
      Returns:
      The according instances managed by this Context.
    • toSchema

      public DependencySchema toSchema()
      Specified by:
      toSchema in interface org.refcodes.mixin.Schemable