Interface IocContext<S extends Scope>

Type Parameters:
S - The type for the scope class for this context.

public interface IocContext<S extends Scope>
Represents a context in witch components are managed. This interface is mean to be use (not for implementation), it brings all the method necessaries for find components and services in the scope that it manages.

An implementation of this interface can be obtained via the Ioc interface or by injecting Inject it in any component you want.

Author:
Gilberto Vento
  • Method Summary

    Modifier and Type Method Description
    <T extends Scope>
    IocContext<T>
    createChild​(T scope)
    Create a child IocContext of this context.
    boolean exists​(java.lang.reflect.Type service)
    This method finds if a service is provided by a least one component in the context.
    boolean existsComponent​(java.lang.Class<?> component)
    This method finds if the given class is a component of the context.
    <T> T find​(java.lang.Class<T> service)
    This method finds the highest priority component that provides the given service.
    <T> T[] findAll​(java.lang.Class<T> service)
    This method finds all the components that provides the given service.
    java.lang.Object findGeneric​(java.lang.reflect.Type service)
    This method finds the highest priority component that provides the given generic service.
    <T> T findNext​(java.lang.Class<T> service, int priority)
    This method finds the component that provides the given service with less priority than the priority parameter.
    java.lang.Object findNextGeneric​(java.lang.reflect.Type service, int priority)
    This method finds the component that provides the given generic service with less priority than the priority parameter.
    ClassRepository getClassRepository()
    Obtains the class repository associated with this context.
    IocContext<?> getParent()
    The parent of this context.
    S getScope()
    Gets the scope of the current context.
    java.lang.Class<S> getScopeClass()
    Gets the scope of the current context.
    void printPriorities​(java.lang.Class<?> service, java.io.PrintWriter writer)
    Prints all the implementations of the services with its priorities.
  • Method Details

    • getScope

      S getScope()
      Gets the scope of the current context.
      Returns:
      An string object representing the scope name used for this context.
    • getScopeClass

      java.lang.Class<S> getScopeClass()
      Gets the scope of the current context.
      Returns:
      An string object representing the scope name used for this context.
    • find

      <T> T find​(java.lang.Class<T> service)
      This method finds the highest priority component that provides the given service.

      Type Parameters:
      T - The generic type of the class of the service that this method should find.
      Parameters:
      service - The class that represents the service that this method must find.
      Returns:
      An object that extends or implement the class of the service provided, or null if no component provides this services in the context.
    • findNext

      <T> T findNext​(java.lang.Class<T> service, int priority)
      This method finds the component that provides the given service with less priority than the priority parameter.

      Type Parameters:
      T - The generic type of the class of the service that this method should find.
      Parameters:
      service - The class that represents the service that this method must find.
      priority - The given component must have a priority value greater than this parameter.
      Returns:
      An object that extends or implement the class of the service provided, or null if no component provides this services in the context.
    • findAll

      <T> T[] findAll​(java.lang.Class<T> service)
      This method finds all the components that provides the given service.

      Type Parameters:
      T - The generic type of the class of the service that this method should find.
      Parameters:
      service - The class that represents the service that this method must find.
      Returns:
      An array of objects who extends or implement the class of the service provided, or an empty array if no component provides this services in the context.
    • findGeneric

      java.lang.Object findGeneric​(java.lang.reflect.Type service)
      This method finds the highest priority component that provides the given generic service.

      Parameters:
      service - The Type that represents the service that this method must find.
      Returns:
      An object that extends or implement the service provided, or null if no component provides this services in the context.
    • findNextGeneric

      java.lang.Object findNextGeneric​(java.lang.reflect.Type service, int priority)
      This method finds the component that provides the given generic service with less priority than the priority parameter.

      Parameters:
      service - The Type that represents the service that this method must find.
      priority - The given component must have a priority value greater than this parameter.
      Returns:
      An object that extends or implement the service provided, or null if no component provides this services in the context.
    • exists

      boolean exists​(java.lang.reflect.Type service)
      This method finds if a service is provided by a least one component in the context.

      Parameters:
      service - The type of the service to look for.
      Returns:
      true If at least one component provides this service, false otherwise.
    • existsComponent

      boolean existsComponent​(java.lang.Class<?> component)
      This method finds if the given class is a component of the context.

      Parameters:
      component - The class of the component to look for.
      Returns:
      true If this class represents a component of the context, false otherwise.
    • getParent

      IocContext<?> getParent()
      The parent of this context.

      Returns:
      The IocContext instance representing the parent of this context, or null if this context has no parent.
    • createChild

      <T extends Scope> IocContext<T> createChild​(T scope)
      Create a child IocContext of this context.

      Type Parameters:
      T - The type of the scope.
      Parameters:
      scope - The scope of the new context.
      Returns:
      The new IocContext instance created as child of this context.
    • getClassRepository

      ClassRepository getClassRepository()
      Obtains the class repository associated with this context. that allows to find classes, fields and methods of the components in this context.

      Returns:
      A ClassRepository instance
    • printPriorities

      void printPriorities​(java.lang.Class<?> service, java.io.PrintWriter writer)
      Prints all the implementations of the services with its priorities.
      Parameters:
      service - The service to lookup.
      writer - The writer to print the result.