Class JAXBHelper


  • public class JAXBHelper
    extends Object
    This class provides a mechanism to obtain the EclipseLink implementation of various JAXB runtime classes based on a given JAXB class/interface. This is useful for accessing extended EclipseLink features. Using this helper class will alleviate the need for consumers of EclipseLink JAXB to perform casts where their code makes use of the standard JAXB API. In addition, a given JAXB class/interface can be unwrapped based on a user-specified class. This will allow access - in certain cases - to a given JAXB implementation class' underlying class(es). For example, a Marshaller could be unwrapped resulting in an EclipseLink JAXBMarshaller, or its underlying XMLMarshaller.
    • Constructor Summary

      Constructors 
      Constructor Description
      JAXBHelper()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static JAXBBinder getBinder​(jakarta.xml.bind.Binder jaxbBinder)
      Return the EclipseLink implementation of Binder.
      static JAXBContext getJAXBContext​(jakarta.xml.bind.JAXBContext jaxbContext)
      Return the EclipseLink implementation of JAXBContext.
      static JAXBMarshaller getMarshaller​(jakarta.xml.bind.Marshaller jaxbMarshaller)
      Return the EclipseLink implementation of Marshaller.
      static JAXBUnmarshaller getUnmarshaller​(jakarta.xml.bind.Unmarshaller jaxbUnmarshaller)
      Return the EclipseLink implementation of Unmarshaller.
      static <T> T unwrap​(jakarta.xml.bind.Binder jaxbBinder, Class<T> clazz)
      Unwraps a given Binder resulting in an EclipseLink JAXBBinder, or the EclipseLink JAXBBinder's underlying XMLBinder.
      static <T> T unwrap​(jakarta.xml.bind.JAXBContext jaxbContext, Class<T> clazz)
      Unwraps a given JAXBContext resulting in an EclipseLink JAXBContext, or the EclipseLink JAXBContext's underlying XMLContext.
      static <T> T unwrap​(jakarta.xml.bind.Marshaller jaxbMarshaller, Class<T> clazz)
      Unwraps a given Marshaller resulting in an EclipseLink JAXBMarshaller, or the EclipseLink JAXBMarshaller's underlying XMLMarshaller.
      static <T> T unwrap​(jakarta.xml.bind.Unmarshaller jaxbUnmarshaller, Class<T> clazz)
      Unwraps a given Unmarshaller resulting in an EclipseLink JAXBUnmarshaller, or the EclipseLink JAXBUnmarshaller's underlying XMLUnmarshaller.
    • Constructor Detail

      • JAXBHelper

        public JAXBHelper()
    • Method Detail

      • getJAXBContext

        public static JAXBContext getJAXBContext​(jakarta.xml.bind.JAXBContext jaxbContext)
                                          throws IllegalArgumentException
        Return the EclipseLink implementation of JAXBContext. The given JAXBContext is assumed to be an instance of JAXBContext. If not, an exception will be thrown.
        Parameters:
        jaxbContext -
        Returns:
        Throws:
        IllegalArgumentException
      • unwrap

        public static <T> T unwrap​(jakarta.xml.bind.JAXBContext jaxbContext,
                                   Class<T> clazz)
                            throws IllegalArgumentException
        Unwraps a given JAXBContext resulting in an EclipseLink JAXBContext, or the EclipseLink JAXBContext's underlying XMLContext. Assumes that the given JAXBContext is an instance of EclipseLink JAXBContext, and clazz is one of org.eclipse.persistence.jaxb.JAXBContext or org.eclipse.persistence.oxm.XMLContext.
        Type Parameters:
        T -
        Parameters:
        jaxbContext -
        clazz -
        Returns:
        Throws:
        IllegalArgumentException
        See Also:
        JAXBContext, XMLContext
      • unwrap

        public static <T> T unwrap​(jakarta.xml.bind.Unmarshaller jaxbUnmarshaller,
                                   Class<T> clazz)
                            throws IllegalArgumentException
        Unwraps a given Unmarshaller resulting in an EclipseLink JAXBUnmarshaller, or the EclipseLink JAXBUnmarshaller's underlying XMLUnmarshaller. Assumes that the given Unmarshaller is an instance of EclipseLink JAXBUnmarshaller, and clazz is one of org.eclipse.persistence.jaxb.JAXBUnmarshaller or org.eclipse.persistence.oxm.XMLUnmarshaller.
        Type Parameters:
        T -
        Parameters:
        jaxbUnmarshaller -
        clazz -
        Returns:
        Throws:
        IllegalArgumentException
        See Also:
        JAXBUnmarshaller, XMLUnmarshaller
      • unwrap

        public static <T> T unwrap​(jakarta.xml.bind.Marshaller jaxbMarshaller,
                                   Class<T> clazz)
                            throws IllegalArgumentException
        Unwraps a given Marshaller resulting in an EclipseLink JAXBMarshaller, or the EclipseLink JAXBMarshaller's underlying XMLMarshaller. Assumes that the given Marshaller is an instance of EclipseLink JAXBMarshaller, and clazz is one of org.eclipse.persistence.jaxb.JAXBMarshaller or org.eclipse.persistence.oxm.XMLMarshaller.
        Type Parameters:
        T -
        Parameters:
        jaxbMarshaller -
        clazz -
        Returns:
        Throws:
        IllegalArgumentException
        See Also:
        JAXBMarshaller, XMLMarshaller
      • unwrap

        public static <T> T unwrap​(jakarta.xml.bind.Binder jaxbBinder,
                                   Class<T> clazz)
                            throws IllegalArgumentException
        Unwraps a given Binder resulting in an EclipseLink JAXBBinder, or the EclipseLink JAXBBinder's underlying XMLBinder. Assumes that the given Binder is an instance of EclipseLink JAXBBinderr, and clazz is one of org.eclipse.persistence.jaxb.JAXBinder or org.eclipse.persistence.oxm.XMLBinder.
        Type Parameters:
        T -
        Parameters:
        jaxbBinder -
        clazz -
        Returns:
        Throws:
        IllegalArgumentException
        See Also:
        JAXBBinder, XMLBinder