Class AbstractLoader<T>

    • Method Detail

      • getLoadedResources

        @NonNull
        public Collection<TgetLoadedResources()
        Retrieve the set of loaded resources.
        Returns:
        the set of loaded resources
      • getCachedEntries

        @NonNull
        protected Map<URI,​TgetCachedEntries()
        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 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.
        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
                      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 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.
        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