Class DefaultBoundLoader

java.lang.Object
dev.metaschema.core.model.AbstractResourceResolver
dev.metaschema.databind.io.DefaultBoundLoader
All Implemented Interfaces:
dev.metaschema.core.configuration.IConfiguration<DeserializationFeature<?>>, dev.metaschema.core.configuration.IMutableConfiguration<DeserializationFeature<?>>, dev.metaschema.core.metapath.IDocumentLoader, dev.metaschema.core.model.IResourceResolver, IBoundLoader

public class DefaultBoundLoader extends dev.metaschema.core.model.AbstractResourceResolver implements IBoundLoader
A default implementation of an IBoundLoader.
  • Field Details

  • Constructor Details

    • DefaultBoundLoader

      public DefaultBoundLoader(@NonNull IBindingContext bindingContext)
      Construct a new loader instance, using the provided IBindingContext.
      Parameters:
      bindingContext - the Module binding context to use to load Java types
  • Method Details

    • isFeatureEnabled

      public boolean isFeatureEnabled(DeserializationFeature<?> feature)
      Specified by:
      isFeatureEnabled in interface dev.metaschema.core.configuration.IConfiguration<DeserializationFeature<?>>
    • getFeatureValues

      Specified by:
      getFeatureValues in interface dev.metaschema.core.configuration.IConfiguration<DeserializationFeature<?>>
    • applyConfiguration

      public IBoundLoader applyConfiguration(@NonNull dev.metaschema.core.configuration.IConfiguration<DeserializationFeature<?>> other)
      Specified by:
      applyConfiguration in interface IBoundLoader
      Specified by:
      applyConfiguration in interface dev.metaschema.core.configuration.IMutableConfiguration<DeserializationFeature<?>>
    • set

      public IBoundLoader set(DeserializationFeature<?> feature, Object value)
      Specified by:
      set in interface IBoundLoader
      Specified by:
      set in interface dev.metaschema.core.configuration.IMutableConfiguration<DeserializationFeature<?>>
    • getBindingContext

      Description copied from interface: IBoundLoader
      Get the configured Module binding context to use to load Java types.
      Specified by:
      getBindingContext in interface IBoundLoader
      Returns:
      the binding context
    • detectFormat

      public Format detectFormat(@NonNull URI uri) throws IOException
      Description copied from interface: IBoundLoader
      Determine the format of the resource identified by the provided uri.
      Specified by:
      detectFormat in interface IBoundLoader
      Parameters:
      uri - the resource
      Returns:
      the format information for the provided resource
      Throws:
      IOException - if an error occurred while reading the resource
    • detectFormat

      Description copied from interface: IBoundLoader
      Determine the format of the provided resource.

      This method will consume data from the provided InputStream. If the caller of this method intends to read data from the stream after determining the format, the caller should pass in a stream that can be reset.

      This method will not close the provided InputStream, since it does not own the stream.

      Specified by:
      detectFormat in interface IBoundLoader
      Parameters:
      is - an input stream for the resource
      resource - the URI of the resource
      Returns:
      the format information for the provided resource
      Throws:
      IOException - if an error occurred while reading the resource
    • detectModel

      @Owning public @Owning ModelDetector.Result detectModel(@NotOwning InputStream is, URI resource, Format format) throws IOException
      Description copied from interface: IBoundLoader
      Determine the model of the provided resource.

      This method will consume data from any InputStream provided by the InputSource. If the caller of this method intends to read data from the stream after determining the format, the caller should pass in a stream that can be reset.

      This method will not close any InputStream provided by the InputSource, since it does not own the stream.

      The caller owns the returned result and is responsible for closing it.

      Specified by:
      detectModel in interface IBoundLoader
      Parameters:
      is - an input stream for the resource
      resource - the URI of the resource
      format - the format of the provided resource
      Returns:
      the model of the provided resource
      Throws:
      IOException - if an error occurred while reading the resource
    • load

      public <CLASS extends dev.metaschema.core.model.IBoundObject> CLASS load(@NonNull URI uri) throws IOException
      Description copied from interface: IBoundLoader
      Load data from the resource identified by the provided uri into a bound object.

      This method will auto-detect the format of the provided resource.

      Specified by:
      load in interface IBoundLoader
      Type Parameters:
      CLASS - the type of the bound object to return
      Parameters:
      uri - the resource
      Returns:
      a bound object containing the loaded data
      Throws:
      IOException - if an error occurred while reading the resource
      See Also:
    • load

      @NonNull public <CLASS extends dev.metaschema.core.model.IBoundObject> CLASS load(@NotOwning @NonNull InputStream is, @NonNull URI resource) throws IOException
      Description copied from interface: IBoundLoader
      Load data from the provided resource into a bound object.

      This method should auto-detect the format of the provided resource.

      This method will not close the provided InputStream, since it does not own the stream.

      Specified by:
      load in interface IBoundLoader
      Type Parameters:
      CLASS - the type of the bound object to return
      Parameters:
      is - the resource stream
      resource - the URI of the resource
      Returns:
      a bound object containing the loaded data
      Throws:
      IOException - if an error occurred while reading the resource
      See Also:
    • load

      public <CLASS extends dev.metaschema.core.model.IBoundObject> CLASS load(Class<CLASS> clazz, URI uri) throws IOException
      Description copied from interface: IBoundLoader
      Load data from the specified resource into a bound object with the type of the specified Java class.
      Specified by:
      load in interface IBoundLoader
      Type Parameters:
      CLASS - the Java type to load data into
      Parameters:
      clazz - the class for the java type
      uri - the resource to load
      Returns:
      the loaded instance data
      Throws:
      IOException - if an error occurred while loading the data in the specified file
    • load

      public <CLASS extends dev.metaschema.core.model.IBoundObject> CLASS load(Class<CLASS> clazz, InputStream is, URI documentUri) throws IOException
      Description copied from interface: IBoundLoader
      Load data from the specified resource into a bound object with the type of the specified Java class.

      This method will not close the provided InputStream, since it does not own the stream.

      Implementations of this method will do format detection. This process might leave the provided InputStream at a position beyond the last parsed location. If you want to avoid this possibility, use and implementation of IDeserializer.deserialize(InputStream, URI) instead, such as what is provided by DefaultBindingContext.newDeserializer(Format, Class).

      Specified by:
      load in interface IBoundLoader
      Type Parameters:
      CLASS - the Java type to load data into
      Parameters:
      clazz - the class for the java type
      is - the resource stream
      documentUri - the URI of the resource
      Returns:
      the loaded data
      Throws:
      IOException - if an error occurred while loading the data from the specified resource
    • load

      @NonNull public <CLASS extends dev.metaschema.core.model.IBoundObject> CLASS load(@NonNull Class<CLASS> clazz, @NonNull Format format, @NonNull InputStream is, @NonNull URI documentUri) throws IOException
      Description copied from interface: IBoundLoader
      Load data from the specified resource into a bound object with the type of the specified Java class.

      This method will not close the provided InputStream, since it does not own the stream.

      Specified by:
      load in interface IBoundLoader
      Type Parameters:
      CLASS - the Java type to load data into
      Parameters:
      clazz - the class for the java type
      format - the format to parse
      is - the resource stream
      documentUri - the URI of the resource
      Returns:
      the loaded data
      Throws:
      IOException - if an error occurred while loading the data from the specified resource
    • loadAsNodeItem

      public dev.metaschema.core.metapath.item.node.IDocumentNodeItem loadAsNodeItem(URI uri) throws IOException
      Specified by:
      loadAsNodeItem in interface dev.metaschema.core.metapath.IDocumentLoader
      Throws:
      IOException
    • loadAsNodeItem

      public dev.metaschema.core.metapath.item.node.IDocumentNodeItem loadAsNodeItem(Format format, URI uri) throws IOException
      Description copied from interface: IBoundLoader
      Load data expressed using the provided format and return that data as a Metapath node item.

      The specific Module model is auto-detected by analyzing the source. The class reported is implementation specific.

      Specified by:
      loadAsNodeItem in interface IBoundLoader
      Parameters:
      format - the expected format of the data to parse
      uri - the resource
      Returns:
      the Metapath node item for the parsed data
      Throws:
      IOException - if an error occurred while loading the data from the specified resource
    • loadAsNodeItem

      public dev.metaschema.core.metapath.item.node.IDocumentNodeItem loadAsNodeItem(Format format, InputStream is, URI resource) throws IOException
      Description copied from interface: IBoundLoader
      Load data expressed using the provided format and return that data as a Metapath node item.

      The specific Module model is auto-detected by analyzing the source. The class reported is implementation specific.

      Specified by:
      loadAsNodeItem in interface IBoundLoader
      Parameters:
      format - the expected format of the data to parse
      is - the resource stream
      resource - the URI of the resource
      Returns:
      the Metapath node item for the parsed data
      Throws:
      IOException - if an error occurred while loading the data from the specified resource