Class DefaultBoundLoader

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

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

    • LOOK_AHEAD_BYTES

      public static final int LOOK_AHEAD_BYTES
      The number of bytes to read ahead when determining the source format.
      See Also:
  • 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)
      Description copied from interface: IConfiguration
      Determines if a specific feature is enabled.
      Specified by:
      isFeatureEnabled in interface IConfiguration<DeserializationFeature<?>>
      Parameters:
      feature - the feature to check for
      Returns:
      true if the feature is enabled, or false otherwise
      See Also:
    • getFeatureValues

      public Map<DeserializationFeature<?>,Object> getFeatureValues()
      Description copied from interface: IConfiguration
      Get the mapping of each feature mapped to its value.
      Specified by:
      getFeatureValues in interface IConfiguration<DeserializationFeature<?>>
      Returns:
      the mapping
    • applyConfiguration

      public IBoundLoader applyConfiguration(@NonNull IConfiguration<DeserializationFeature<?>> other)
      Description copied from interface: IMutableConfiguration
      Replace this configuration with the other configuration.
      Specified by:
      applyConfiguration in interface IBoundLoader
      Specified by:
      applyConfiguration in interface IMutableConfiguration<DeserializationFeature<?>>
      Parameters:
      other - the new configuration
      Returns:
      the updated configuration
    • set

      public IBoundLoader set(DeserializationFeature<?> feature, Object value)
      Description copied from interface: IMutableConfiguration
      Set the value of the provided feature to the provided value.
      Specified by:
      set in interface IBoundLoader
      Specified by:
      set in interface IMutableConfiguration<DeserializationFeature<?>>
      Parameters:
      feature - the feature to set
      value - the value to set
      Returns:
      the updated configuration
      See Also:
    • getBindingContext

      public IBindingContext 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

      public FormatDetector.Result detectFormat(InputStream is, URI resource) throws IOException
      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 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 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 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 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 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 IDocumentNodeItem loadAsNodeItem(URI uri) throws IOException
      Description copied from interface: IDocumentLoader
      Load a Metaschema-based document from a URI resource.

      This is the expected, primary entry point for implementations.

      Specified by:
      loadAsNodeItem in interface IDocumentLoader
      Parameters:
      uri - the resource to load
      Returns:
      a document item representing the contents of the document.
      Throws:
      IOException - if an error occurred while parsing the resource
    • loadAsNodeItem

      public 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 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