Class AbstractLoader<T>
- java.lang.Object
-
- gov.nist.secauto.metaschema.core.model.xml.AbstractLoader<T>
-
- Direct Known Subclasses:
ConstraintLoader
,ModuleLoader
public abstract class AbstractLoader<T> extends Object
-
-
Constructor Summary
Constructors Constructor Description AbstractLoader()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected Map<URI,T>
getCachedEntries()
Retrieve a mapping of resource URIs to the associated loaded resource.Collection<T>
getLoadedResources()
Retrieve the set of loaded resources.T
load(File file)
Load a resource from the specified file.T
load(URI resource)
Load a resource from the specified URI.T
load(URL url)
Loads a resource from the specified URL.T
load(Path path)
Load a resource from the specified path.protected T
loadInternal(URI resource, Deque<URI> visitedResources)
Loads a resource from the provided URI.protected abstract T
parseResource(URI resource, Deque<URI> visitedResources)
Parse the providedresource
.
-
-
-
Constructor Detail
-
AbstractLoader
public AbstractLoader()
-
-
Method Detail
-
getLoadedResources
@NonNull public Collection<T> getLoadedResources()
Retrieve the set of loaded resources.- 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
Load a resource from the specified URI.- 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
@NonNull public T load(@NonNull Path path) throws MetaschemaException, IOException
Load a resource from the specified path.- 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
@NonNull public T load(@NonNull File file) throws MetaschemaException, IOException
Load a resource from the specified file.- Parameters:
file
- 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
@NonNull public T load(@NonNull URL url) throws MetaschemaException, IOException
Loads a resource from the specified URL.- 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
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 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
-
-