Class SystemRoleFactorySupport

java.lang.Object
it.tidalwave.role.spi.SystemRoleFactorySupport
All Implemented Interfaces:
SystemRoleFactory

public abstract class SystemRoleFactorySupport extends Object implements SystemRoleFactory
A basic implementation of a SystemRoleFactory. This class must be specialized to:
  1. discover roles (see scan(java.util.Collection)
  2. associate roles to a datum (see findDatumTypesForRole(java.lang.Class)
  3. associate roles to contexts (see findContextTypeForRole(java.lang.Class)
  4. eventually retrieve beans to inject in created roles (see getBean(java.lang.Class)
Specializations might use annotations or configuration files to accomplish these tasks.
Author:
Fabrizio Giudici
  • Constructor Details

    • SystemRoleFactorySupport

      public SystemRoleFactorySupport()
  • Method Details

    • findRoles

      @Nonnull public <T> List<T> findRoles(@Nonnull Object datum, @Nonnull Class<? extends T> roleType)
      Retrieves the roles of the given class for the given owner object.
      Specified by:
      findRoles in interface SystemRoleFactory
      Type Parameters:
      T - the static type of the roles
      Parameters:
      datum - the owner object
      roleType - the dynamic type of the roles
      Returns:
      a list of roles
    • scan

      protected void scan(@Nonnull Collection<Class<?>> roleImplementationTypes)
      Scans all the given role implementation classes and build a map of roles by owner class.
      Parameters:
      roleImplementationTypes - the types of role implementations to scan
    • getBean

      @Nonnull protected <T> Optional<T> getBean(@Nonnull Class<T> beanType)
      Retrieves an extra bean.
      Type Parameters:
      T - the static type of the bean
      Parameters:
      beanType - the dynamic type of the bean
      Returns:
      the bean
    • findContextTypeForRole

      @Nonnull protected Optional<Class<?>> findContextTypeForRole(@Nonnull Class<?> roleImplementationType)
      Returns the type of the context associated to the given role implementation type.
      Parameters:
      roleImplementationType - the role type
      Returns:
      the context type
    • findDatumTypesForRole

      @Nonnull protected Class<?>[] findDatumTypesForRole(@Nonnull Class<?> roleImplementationType)
      Returns the valid datum types for the given role implementation type.
      Parameters:
      roleImplementationType - the role type
      Returns:
      the datum types
    • logRoles

      public void logRoles()