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
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionRetrieve a mapping of resource URIs to the associated loaded resource.Retrieve the set of loaded resources.Load a resource from the specified URI.Loads a resource from the specified URL.Load a resource from the specified path.protected TloadInternal(URI resource, Deque<URI> visitedResources) Loads a resource from the provided URI.protected abstract TparseResource(URI resource, Deque<URI> visitedResources) Parse the providedresource.
-
Constructor Details
-
AbstractLoader
public AbstractLoader()
-
-
Method Details
-
getLoadedResources
Description copied from interface:ILoaderRetrieve the set of loaded resources.- Specified by:
getLoadedResourcesin interfaceILoader<T>- Returns:
- the set of loaded resources
-
getCachedEntries
Retrieve a mapping of resource URIs to the associated loaded resource.- Returns:
- the mapping
-
load
Description copied from interface:ILoaderLoad a resource from the specified URI.- Specified by:
loadin interfaceILoader<T>- Parameters:
resource- the resource to load- Returns:
- the loaded instance for the specified resource
- Throws:
MetaschemaException- if an error occurred while processing the resourceIOException- if an error occurred parsing the resource
-
load
Load a resource from the specified path.- Specified by:
loadin interfaceILoader<T>- Parameters:
path- the resource to load- Returns:
- the loaded instance for the specified resource
- Throws:
MetaschemaException- if an error occurred while processing the resourceIOException- if an error occurred parsing the resource
-
load
Loads a resource from the specified URL.- Specified by:
loadin interfaceILoader<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 resourceIOException- 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
visitedResourcescan 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 loadvisitedResources- a LIFO queue representing previously visited resources in an import chain- Returns:
- the loaded resource
- Throws:
MetaschemaException- if an error occurred while processing the resourceMalformedURLException- if the provided URI is malformedIOException- if an error occurred parsing the resource
-
parseResource
protected abstract T parseResource(@NonNull URI resource, @NonNull Deque<URI> visitedResources) throws IOException Parse the providedresource.- Parameters:
resource- the resource to parsevisitedResources- a stack representing previously parsed resources imported by the providedresource- Returns:
- the parsed resource
- Throws:
IOException- if an error occurred while parsing the resource
-