Class DefaultModuleParserFactory

java.lang.Object
dev.jcputney.elearning.parser.impl.factory.DefaultModuleParserFactory
All Implemented Interfaces:
ModuleParserFactory

public final class DefaultModuleParserFactory extends Object implements ModuleParserFactory
Default implementation of the ModuleParserFactory interface.

This class creates appropriate parsers for different types of eLearning modules based on the detected module type. It uses a ModuleTypeDetector to determine the module type and then creates the corresponding parser.

  • Constructor Details

    • DefaultModuleParserFactory

      public DefaultModuleParserFactory(FileAccess fileAccess, ModuleTypeDetector moduleTypeDetector, ParserOptions options)
      Constructs a new DefaultModuleParserFactory with the specified FileAccess, ModuleTypeDetector, and ParserOptions.
      Parameters:
      fileAccess - the FileAccess implementation to use for accessing module files
      moduleTypeDetector - the ModuleTypeDetector implementation to use for detecting module types
      options - the parser options to control validation and calculation behavior
      Throws:
      IllegalArgumentException - if fileAccess or moduleTypeDetector is null
    • DefaultModuleParserFactory

      public DefaultModuleParserFactory(FileAccess fileAccess, ModuleTypeDetector moduleTypeDetector)
      Constructs a new DefaultModuleParserFactory with the specified FileAccess and ModuleTypeDetector implementations, using default parser options.
      Parameters:
      fileAccess - the FileAccess implementation to use for accessing module files
      moduleTypeDetector - the ModuleTypeDetector implementation to use for detecting module types
      Throws:
      IllegalArgumentException - if fileAccess or moduleTypeDetector is null
    • DefaultModuleParserFactory

      public DefaultModuleParserFactory(FileAccess fileAccess, ParserOptions options)
      Constructs a new DefaultModuleParserFactory with the specified FileAccess implementation, a default ModuleTypeDetector, and custom parser options.
      Parameters:
      fileAccess - the FileAccess implementation to use for accessing module files
      options - the parser options to control validation and calculation behavior
      Throws:
      IllegalArgumentException - if fileAccess is null
    • DefaultModuleParserFactory

      public DefaultModuleParserFactory(FileAccess fileAccess)
      Constructs a new DefaultModuleParserFactory with the specified FileAccess implementation, a default ModuleTypeDetector, and default parser options.
      Parameters:
      fileAccess - the FileAccess implementation to use for accessing module files
      Throws:
      IllegalArgumentException - if fileAccess is null
  • Method Details

    • registerParser

      public void registerParser(ModuleType moduleType, Function<FileAccess,ModuleParser<?>> parserFactory)
      Registers a parser factory function for the specified module type.
      Parameters:
      moduleType - the module type to register the parser for
      parserFactory - the factory function that creates a parser for the specified module type
      Throws:
      IllegalArgumentException - if moduleType or parserFactory is null
    • unregisterParser

      public boolean unregisterParser(ModuleType moduleType)
      Unregisters the parser factory function for the specified module type.
      Parameters:
      moduleType - the module type to unregister the parser for
      Returns:
      true if a parser was unregistered, false if no parser was registered for the specified module type
      Throws:
      IllegalArgumentException - if moduleType is null
    • getParser

      public ModuleParser<?> getParser() throws ModuleDetectionException
      Returns an appropriate parser for the module type detected at the given path.
      Specified by:
      getParser in interface ModuleParserFactory
      Returns:
      A ModuleParser instance for the detected module type.
      Throws:
      ModuleDetectionException - if the module type cannot be determined.
    • parseModule

      public ModuleMetadata<?> parseModule() throws ModuleException
      Parses the module at the specified path and returns a ModuleMetadata object containing the extracted metadata.
      Specified by:
      parseModule in interface ModuleParserFactory
      Returns:
      A ModuleMetadata object containing the extracted metadata.
      Throws:
      ModuleDetectionException - if the module type cannot be determined.
      ModuleParsingException - if an error occurs during parsing.
      ModuleDetectionException - if the module type cannot be determined.
      ModuleParsingException - if an error occurs during parsing.
      ModuleException