Class ExtendedUnmarshaller<R,I>

java.lang.Object
com.foursoft.harness.navext.runtime.ExtendedUnmarshaller<R,I>
Type Parameters:
R - Type of the root element to unmarshall.
I - Type of elements that are identifiable.

public class ExtendedUnmarshaller<R,I> extends Object
Provides extended unmarshalling capabilities for a JAXB model. Capabilities are: This is a wrapper arround an Unmarshaller.

The ExtendedUnmarshaller is required in order to correctly integrate the two phase model post processing (see ModelPostProcessor into the unmarshalling process.

Author:
becker
  • Constructor Details

    • ExtendedUnmarshaller

      public ExtendedUnmarshaller(Class<R> rootElement) throws jakarta.xml.bind.JAXBException
      Throws:
      jakarta.xml.bind.JAXBException
  • Method Details

    • withBackReferences

      public ExtendedUnmarshaller<R,I> withBackReferences()
      Turns on the capability to initialize parent associations and backreferences.
      Returns:
      Returns this for method chaining / fluent initialization.
    • withCustomPostProcessor

      public ExtendedUnmarshaller<R,I> withCustomPostProcessor(ModelPostProcessor modelPostProcessor)
      Adds a custom ModelPostProcessor to the deserialization.
      Parameters:
      modelPostProcessor - the model post processor to use. Must not be null.
      Returns:
      this for fluent API
    • withEventLogging

      public ExtendedUnmarshaller<R,I> withEventLogging(Consumer<jakarta.xml.bind.ValidationEvent> eventConsumer) throws jakarta.xml.bind.JAXBException
      The jaxb unmarshaller has an event handler which is intercepted to provide the event for the consumer. This will reset the handler first to the default handler, and then add the given consumer to it
      Parameters:
      eventConsumer - the consumer for the jaxb validation event
      Returns:
      this for fluent API
      Throws:
      jakarta.xml.bind.JAXBException - if the unmarshalling goes wrong
    • withIdMapper

      public ExtendedUnmarshaller<R,I> withIdMapper(Class<I> classOfIdentifiableElements, Function<I,String> idMapper)
      Defines an id mapper to create a IdLookupProvider during the unmarshalling process.

      If no id mapper is defined, the resulting JaxbModel will have no IdLookupProvider initialized.

      If more than one id mapper is registered, all are processed and the result is merged into one IdLookupProvider. This allows a common the handling of all classes during the unmarshalling, even if the do not have a shared superclass or interface.

      Parameters:
      classOfIdentifiableElements - the class of the identifiable element
      idMapper - the mapper function to get the id of each element
      Returns:
      this for fluent API
    • unmarshall

      public JaxbModel<R,I> unmarshall(InputStream resource) throws jakarta.xml.bind.JAXBException
      Throws:
      jakarta.xml.bind.JAXBException
    • getUnmarshaller

      public jakarta.xml.bind.Unmarshaller getUnmarshaller()
      Provides access to the internal jax-b unmarshaller for further configuration. Use with caution.
      Returns:
      the internal jax-b unmarshaller
    • getXMLReader

      protected XMLReader getXMLReader() throws jakarta.xml.bind.JAXBException
      Obtains a configured XMLReader.

      Unmarshaller is not re-entrant, so we will only use one instance of XMLReader.

      Overriden in order to fix potential security issue. See jakarta.xml.bind.helpers.AbstractUnmarshallerImpl#getXMLReader()

      Throws:
      jakarta.xml.bind.JAXBException