Class JAXBMarshallerHelper

java.lang.Object
com.helger.jaxb.JAXBMarshallerHelper

@Immutable public final class JAXBMarshallerHelper extends Object
This class contains utility methods for JAXB Marshaller objects. It allows for setting type-safe properties.
Author:
Philip Helger
  • Method Details

    • getEncoding

      @Nullable public static String getEncoding(@Nonnull jakarta.xml.bind.Marshaller aMarshaller)
    • setEncoding

      public static void setEncoding(@Nonnull jakarta.xml.bind.Marshaller aMarshaller, @Nullable Charset aEncoding)
      Set the standard property for the encoding charset.
      Parameters:
      aMarshaller - The marshaller to set the property. May not be null.
      aEncoding - the value to be set
    • setEncoding

      public static void setEncoding(@Nonnull jakarta.xml.bind.Marshaller aMarshaller, @Nullable String sEncoding)
      Set the standard property for the encoding charset.
      Parameters:
      aMarshaller - The marshaller to set the property. May not be null.
      sEncoding - the value to be set
    • isFormattedOutput

      public static boolean isFormattedOutput(@Nonnull jakarta.xml.bind.Marshaller aMarshaller)
    • setFormattedOutput

      public static void setFormattedOutput(@Nonnull jakarta.xml.bind.Marshaller aMarshaller, boolean bFormattedOutput)
      Set the standard property for formatting the output or not.
      Parameters:
      aMarshaller - The marshaller to set the property. May not be null.
      bFormattedOutput - the value to be set
    • getSchemaLocation

      @Nullable public static String getSchemaLocation(@Nonnull jakarta.xml.bind.Marshaller aMarshaller)
    • setSchemaLocation

      public static void setSchemaLocation(@Nonnull jakarta.xml.bind.Marshaller aMarshaller, @Nullable String sSchemaLocation)
      Set the standard property for setting the namespace schema location
      Parameters:
      aMarshaller - The marshaller to set the property. May not be null.
      sSchemaLocation - the value to be set
    • getNoNamespaceSchemaLocation

      @Nullable public static String getNoNamespaceSchemaLocation(@Nonnull jakarta.xml.bind.Marshaller aMarshaller)
    • setNoNamespaceSchemaLocation

      public static void setNoNamespaceSchemaLocation(@Nonnull jakarta.xml.bind.Marshaller aMarshaller, @Nullable String sSchemaLocation)
      Set the standard property for setting the no-namespace schema location
      Parameters:
      aMarshaller - The marshaller to set the property. May not be null.
      sSchemaLocation - the value to be set
    • isFragment

      public static boolean isFragment(@Nonnull jakarta.xml.bind.Marshaller aMarshaller)
    • setFragment

      public static void setFragment(@Nonnull jakarta.xml.bind.Marshaller aMarshaller, boolean bFragment)
      Set the standard property for marshalling a fragment only.
      Parameters:
      aMarshaller - The marshaller to set the property. May not be null.
      bFragment - the value to be set
    • getJakartaIndentString

      @Nullable public static String getJakartaIndentString(@Nonnull jakarta.xml.bind.Marshaller aMarshaller)
    • setJakartaIndentString

      public static void setJakartaIndentString(@Nonnull jakarta.xml.bind.Marshaller aMarshaller, @Nullable String sIndentString)
      Set the Jakarta specific property for the indent string.
      Parameters:
      aMarshaller - The marshaller to set the property. May not be null.
      sIndentString - the value to be set
    • getJakartaCharacterEscapeHandler

      @Nullable public static Object getJakartaCharacterEscapeHandler(@Nonnull jakarta.xml.bind.Marshaller aMarshaller)
    • setJakartaCharacterEscapeHandler

      public static void setJakartaCharacterEscapeHandler(@Nonnull jakarta.xml.bind.Marshaller aMarshaller, @Nonnull Object aCharacterEscapeHandler)
      Set the Jakarta specific encoding handler. Value must implement com.sun.xml.bind.marshaller.CharacterEscapeHandler
      Parameters:
      aMarshaller - The marshaller to set the property. May not be null.
      aCharacterEscapeHandler - the value to be set
    • getJakartaNamespacePrefixMapper

      @Nullable public static JAXBNamespacePrefixMapper getJakartaNamespacePrefixMapper(@Nonnull jakarta.xml.bind.Marshaller aMarshaller)
    • setJakartaNamespacePrefixMapper

      public static void setJakartaNamespacePrefixMapper(@Nonnull jakarta.xml.bind.Marshaller aMarshaller, @Nonnull NamespaceContext aNamespaceContext)
      Set the Jakarta specific namespace prefix mapper based on a generic NamespaceContext. This method instantiates an JAXBNamespacePrefixMapper.
      Parameters:
      aMarshaller - The marshaller to set the property. May not be null.
      aNamespaceContext - The namespace context to be used. May not be null.
      Throws:
      IllegalArgumentException - If the passed NamespaceContext cannot be set.
      NoClassDefFoundError - if the JAXB reference implementation was not found (requires the com.sun.xml.bind:jaxb-impl artefact)
    • setJakartaNamespacePrefixMapper

      public static void setJakartaNamespacePrefixMapper(@Nonnull jakarta.xml.bind.Marshaller aMarshaller, @Nonnull JAXBNamespacePrefixMapper aNamespacePrefixMapper)
      Set the Jakarta specific namespace prefix mapper.
      Parameters:
      aMarshaller - The marshaller to set the property. May not be null.
      aNamespacePrefixMapper - the value to be set
    • getJakartaXMLHeaders

      @Nullable public static String getJakartaXMLHeaders(@Nonnull jakarta.xml.bind.Marshaller aMarshaller)
    • setJakartaXMLHeaders

      public static void setJakartaXMLHeaders(@Nonnull jakarta.xml.bind.Marshaller aMarshaller, @Nonnull String sXMLHeaders)
      Set the Jakarta specific XML header string.
      Parameters:
      aMarshaller - The marshaller to set the property. May not be null.
      sXMLHeaders - the value to be set
    • isJakartaCanonicalization

      public static boolean isJakartaCanonicalization(@Nonnull jakarta.xml.bind.Marshaller aMarshaller)
    • setJakartaCanonicalization

      public static void setJakartaCanonicalization(@Nonnull jakarta.xml.bind.Marshaller aMarshaller, boolean bCanonicalize)
      Set the Jakarta specific canonicalization property.
      Parameters:
      aMarshaller - The marshaller to set the property. May not be null.
      bCanonicalize - the value to be set
    • isJakartaObjectIdentityCycleDetection

      public static boolean isJakartaObjectIdentityCycleDetection(@Nonnull jakarta.xml.bind.Marshaller aMarshaller)
    • setJakartaObjectIdentityCycleDetection

      public static void setJakartaObjectIdentityCycleDetection(@Nonnull jakarta.xml.bind.Marshaller aMarshaller, boolean bObjectIdentityCycleDetection)
      Set the Jakarta specific canonicalization property.
      Parameters:
      aMarshaller - The marshaller to set the property. May not be null.
      bObjectIdentityCycleDetection - the value to be set
    • isJakartaJAXBMarshaller

      public static boolean isJakartaJAXBMarshaller(@Nullable jakarta.xml.bind.Marshaller aMarshaller)
      Check if the passed Marshaller is a Jakarta JAXB marshaller. Use this method to determined, whether the Jakarta specific methods may be invoked or not.
      Parameters:
      aMarshaller - The marshaller to be checked. May be null.
      Returns:
      true if the passed marshaller is not null and is of the Jakarta class.