Class AbstractLoader<T>

java.lang.Object
dev.metaschema.core.model.AbstractLoader<T>
Type Parameters:
T - the Java type of the resource being loaded
All Implemented Interfaces:
ILoader<T>
Direct Known Subclasses:
AbstractModuleLoader, BindingConstraintLoader

public abstract class AbstractLoader<T> extends Object implements ILoader<T>
Base implementation of ILoader providing resource loading with caching and cycle detection.

This loader maintains a cache of loaded resources keyed by URI to avoid redundant parsing. It tracks visited resources during import chains to detect and prevent circular dependencies.

  • Constructor Details

    • AbstractLoader

      public AbstractLoader()
  • Method Details

    • getLoadedResources

      @NonNull public Collection<T> getLoadedResources()
      Description copied from interface: ILoader
      Retrieve the set of loaded resources.
      Specified by:
      getLoadedResources in interface ILoader<T>
      Returns:
      the set of loaded resources
    • getCachedEntries

      @NonNull protected Map<URI,T> getCachedEntries()
      Retrieve a mapping of resource URIs to the associated loaded resource.
      Returns:
      the mapping
    • load

      @NonNull public T load(@NonNull URI resource) throws MetaschemaException, IOException
      Description copied from interface: ILoader
      Load a resource from the specified URI.
      Specified by:
      load in interface ILoader<T>
      Parameters:
      resource - the resource to load
      Returns:
      the loaded instance for the specified resource
      Throws:
      MetaschemaException - if an error occurred while processing the resource
      IOException - if an error occurred parsing the resource
    • load

      @NonNull public T load(@NonNull Path path) throws MetaschemaException, IOException
      Load a resource from the specified path.
      Specified by:
      load in interface ILoader<T>
      Parameters:
      path - the resource to load
      Returns:
      the loaded instance for the specified resource
      Throws:
      MetaschemaException - if an error occurred while processing the resource
      IOException - if an error occurred parsing the resource
    • load

      @NonNull public T load(@NonNull URL url) throws MetaschemaException, IOException
      Loads a resource from the specified URL.
      Specified by:
      load in interface ILoader<T>
      Parameters:
      url - the URL to load the resource from
      Returns:
      the loaded instance for the specified resource
      Throws:
      MetaschemaException - if an error occurred while processing the resource
      IOException - if an error occurred parsing the resource
    • loadInternal

      @NonNull protected T loadInternal(@NonNull URI resource, @NonNull Deque<URI> visitedResources) throws MetaschemaException, MalformedURLException, IOException
      Loads a resource from the provided URI.

      If the resource imports other resources, the provided visitedResources can be used to track circular imports. This is useful when this method recurses into included resources.

      Previously loaded resources are provided by the cache. This method will add the resource to the cache after all imported resources have been loaded.

      Parameters:
      resource - the resource to load
      visitedResources - a LIFO queue representing previously visited resources in an import chain
      Returns:
      the loaded resource
      Throws:
      MetaschemaException - if an error occurred while processing the resource
      MalformedURLException - if the provided URI is malformed
      IOException - if an error occurred parsing the resource
    • parseResource

      protected abstract T parseResource(@NonNull URI resource, @NonNull Deque<URI> visitedResources) throws IOException
      Parse the provided resource.
      Parameters:
      resource - the resource to parse
      visitedResources - a stack representing previously parsed resources imported by the provided resource
      Returns:
      the parsed resource
      Throws:
      IOException - if an error occurred while parsing the resource