Class ModuleBuilder

java.lang.Object
net.odoframework.container.ModuleBuilder
All Implemented Interfaces:
BiFunction<Container,​Properties,​Container>, Module
Direct Known Subclasses:
Application

public abstract class ModuleBuilder
extends Object
implements Module
The module builder is a utility class which provides convenience methods for registering BeanDefinition instances for the Module
  • Constructor Details

    • ModuleBuilder

      public ModuleBuilder()
  • Method Details

    • getStartupBeans

      public static Set<String> getStartupBeans()
      Set of startup beans registered by the ModuleBuilder
      Returns:
    • getDependencies

      public Set<Module> getDependencies()
      returns the set of the modules that are dependant for this Module
      Specified by:
      getDependencies in interface Module
      Returns:
      a set of the dependant modules
    • register

      protected ModuleBuilder register​(BeanDefinition<?> beanDefinition)
      Register an instance of a BeanDefinition to be loaded as part of the container
      Parameters:
      beanDefinition - the bean definition to inject
      Returns:
      self, allowing for fluent builders
    • provides

      public <T> BeanDefinition<T> provides​(String name)
      Creates an instance of a BeanDefinition class which has the name of the parameter
      Type Parameters:
      T - the return type of the BeanDefinition instance
      Parameters:
      name - the name to register in the container
      Returns:
      the newly created BeanDefinition instance
    • registerEventHandler

      public <K,​ T extends Consumer<K>> ModuleBuilder registerEventHandler​(Class<K> eventType, BeanDefinition<T> beanDefinition)
      Registered an Event handler
      Type Parameters:
      T -
      Parameters:
      eventType -
      beanDefinition -
      Returns:
    • provides

      public <T> BeanDefinition<T> provides​(Class<T> type)
      Creates an instance of a BeanDefinition class which has the name of the passed type
      Type Parameters:
      T - the return type of the BeanDefinition instance
      Parameters:
      type - the type to use as a name to register in the container
      Returns:
      the newly created BeanDefinition instance
    • getContainer

      public Container getContainer()
      returns the container associated with this Builder
      Returns:
    • apply

      public final Container apply​(Container container, Properties properties)
      Specified by:
      apply in interface BiFunction<Container,​Properties,​Container>
    • beforeContainerPopulated

      protected void beforeContainerPopulated​(Container container)
      Can be used to implement custom logic before the build() method is invoked
      Parameters:
      container - the container which will be populated with BeanDefinition instances
    • afterContainerPopulated

      protected void afterContainerPopulated​(Container container)
      Can be used to implement custom logic after the build() method is invoked
      Parameters:
      container - the container which will be populated with BeanDefinition instances
    • addStartupBean

      public <T extends Runnable> ModuleBuilder addStartupBean​(BeanDefinition<T> bean)
      This is used to register a bean which must be run when all the modules have been loaded
      Type Parameters:
      T - The returned type of the bean must implement Runnable
      Parameters:
      bean - the BeanDefinition instance to run during startup
      Returns:
      ModuleBuilder instance to allow for fluent builder
    • addStartupBean

      public <T extends Runnable> ModuleBuilder addStartupBean​(Class<T> type)
      This is used to register a bean which must be run when all the modules have been loaded
      Type Parameters:
      T - The returned type of the bean must implement Runnable
      Parameters:
      type - creates a BeanDefinition with the parameter as a name and adds it as a startup bean
      Returns:
      ModuleBuilder instance to allow for fluent builder
    • build

      public abstract void build()
      This method is implemented and called as a hook to add BeanDefinition instances to the module