Class AbstractModuleLoaderStrategy

java.lang.Object
dev.metaschema.databind.AbstractModuleLoaderStrategy
All Implemented Interfaces:
IBindingContext.IModuleLoaderStrategy, ModuleLoadingPostProcessor
Direct Known Subclasses:
SimpleModuleLoaderStrategy

public abstract class AbstractModuleLoaderStrategy extends Object implements IBindingContext.IModuleLoaderStrategy
Provides basic module loading capabilities.
Since:
2.0.0
  • Constructor Details

    • AbstractModuleLoaderStrategy

      public AbstractModuleLoaderStrategy()
  • Method Details

    • loadModule

      public IBoundModule loadModule(@NonNull Class<? extends IBoundModule> clazz, @NonNull IBindingContext bindingContext)
      Description copied from interface: IBindingContext.IModuleLoaderStrategy
      Load the bound Metaschema module represented by the provided class.

      This is the primary entry point for loading an already bound module. This method must ensure that the loaded module is post-processed and registered.

      Implementations are allowed to return a cached instance if the module has already been loaded by this method.

      Specified by:
      loadModule in interface IBindingContext.IModuleLoaderStrategy
      Parameters:
      clazz - the Module class
      bindingContext - the Metaschema binding context used to load bound resources
      Returns:
      the module
    • registerModule

      public IBoundModule registerModule(IModule module, IBindingContext bindingContext) throws MetaschemaException
      Description copied from interface: IBindingContext.IModuleLoaderStrategy
      Registers the provided Metaschema module.

      If this module has not been post-processed, this method is expected to drive post-processing first.

      If the provided instance is not an instance of IBoundModule, then annotated Java classes for this module will be generated, compiled, and loaded based on the provided Module.

      Specified by:
      registerModule in interface IBindingContext.IModuleLoaderStrategy
      Parameters:
      module - the Module module to generate classes for
      bindingContext - the Metaschema binding context used to load bound resources
      Returns:
      the registered module, which may be a different instance than what was provided if dynamic compilation was performed
      Throws:
      MetaschemaException - if an error occurred while dynamically binding the provided module
    • handleUnboundModule

      @NonNull protected abstract Class<? extends IBoundModule> handleUnboundModule(@NonNull IModule key) throws MetaschemaException
      Handle a module that is not already bound to a Java class.

      This method is called when a module is encountered that does not implement IBoundModule. Implementations must determine the appropriate bound module class to use for the given module.

      Parameters:
      key - the unbound module to handle
      Returns:
      the class of the bound module to use
      Throws:
      MetaschemaException - if an error occurs while determining the bound module class
    • lookupInstance

      @NonNull protected IBoundModule lookupInstance(@NonNull Class<? extends IBoundModule> moduleClass, @NonNull IBindingContext bindingContext)
      Get the Module instance for a given class annotated by the MetaschemaModule annotation, instantiating it if needed.

      Will also load any imported Metaschemas.

      Parameters:
      moduleClass - the Module class
      bindingContext - the Metaschema binding context used to lookup binding information
      Returns:
      the new Module instance
    • registerBindingMatcher

      @NonNull protected IBindingContext.IBindingMatcher registerBindingMatcher(@NonNull IBoundDefinitionModelAssembly definition)
      Register a binding matcher for a root assembly definition.

      The binding matcher is used to match document root elements to their corresponding assembly definitions during deserialization.

      Parameters:
      definition - the root assembly definition to register a matcher for
      Returns:
      the registered binding matcher
      Throws:
      IllegalArgumentException - if the provided definition is not a root assembly
    • getBindingMatchers

      public final List<IBindingContext.IBindingMatcher> getBindingMatchers()
      Description copied from interface: IBindingContext.IModuleLoaderStrategy
      Get the matchers used to identify the bound class associated with the definition's root name.
      Specified by:
      getBindingMatchers in interface IBindingContext.IModuleLoaderStrategy
      Returns:
      the matchers
    • getBoundDefinitionForClass

      public IBoundDefinitionModelComplex getBoundDefinitionForClass(@NonNull Class<? extends IBoundObject> clazz, @NonNull IBindingContext bindingContext)
      Description copied from interface: IBindingContext.IModuleLoaderStrategy
      Get the IBoundDefinitionModel instance associated with the provided Java class.

      Typically the class will have a MetaschemaAssembly or MetaschemaField annotation.

      Specified by:
      getBoundDefinitionForClass in interface IBindingContext.IModuleLoaderStrategy
      Parameters:
      clazz - the class binding to load
      bindingContext - the Metaschema binding context used to load bound resources
      Returns:
      the associated class binding instance