JAXBTYPE - The JAXB type to be marshaled@NotThreadSafe public class GenericJAXBMarshaller<JAXBTYPE> extends Object implements com.helger.commons.lang.IHasClassLoader, IJAXBReader<JAXBTYPE>, IJAXBWriter<JAXBTYPE>
IJAXBReader.IJAXBUnmarshaller<JAXBTYPE>IJAXBWriter.IJAXBMarshaller<JAXBTYPE>| Modifier and Type | Field and Description |
|---|---|
static boolean |
DEFAULT_READ_SECURE |
USE_JAXB_CHARSET_FIX| Constructor and Description |
|---|
GenericJAXBMarshaller(Class<JAXBTYPE> aType,
Function<? super JAXBTYPE,? extends JAXBElement<JAXBTYPE>> aWrapper)
Constructor without XSD paths.
|
GenericJAXBMarshaller(Class<JAXBTYPE> aType,
List<? extends com.helger.commons.io.resource.ClassPathResource> aXSDs,
Function<? super JAXBTYPE,? extends JAXBElement<JAXBTYPE>> aJAXBElementWrapper)
Constructor with XSD paths.
|
GenericJAXBMarshaller(Class<JAXBTYPE> aType,
QName aQName)
Constructor without XSD paths.
|
| Modifier and Type | Method and Description |
|---|---|
static <T> Function<T,JAXBElement<T>> |
createSimpleJAXBElement(QName aQName,
Class<T> aClass)
Helper function to create a supplier for
JAXBElement objects. |
protected Schema |
createValidationSchema() |
protected void |
customizeMarshaller(Marshaller aMarshaller)
Customize the passed marshaller before marshalling something.
|
protected void |
customizeUnmarshaller(Unmarshaller aUnmarshaller)
Customize the passed unmarshaller before unmarshalling (reading) something.
|
Charset |
getCharset() |
ClassLoader |
getClassLoader() |
String |
getIndentString() |
protected JAXBContext |
getJAXBContext(ClassLoader aClassLoader)
Create the JAXBContext - cached or uncached.
|
NamespaceContext |
getNamespaceContext() |
String |
getNoNamespaceSchemaLocation() |
com.helger.commons.collection.impl.ICommonsList<com.helger.commons.io.resource.ClassPathResource> |
getOriginalXSDs() |
String |
getSchemaLocation() |
protected Class<JAXBTYPE> |
getType() |
IValidationEventHandlerFactory |
getValidationEventHandlerFactory() |
boolean |
isFormattedOutput() |
boolean |
isReadSecure()
Check if secure reading is enabled.
|
boolean |
isUseContextCache() |
JAXBTYPE |
read(IJAXBReader.IJAXBUnmarshaller<JAXBTYPE> aHandler)
Read a document using the passed handler.
|
com.helger.commons.callback.CallbackList<com.helger.commons.callback.exception.IExceptionCallback<JAXBException>> |
readExceptionCallbacks() |
GenericJAXBMarshaller<JAXBTYPE> |
setCharset(Charset aCharset)
Set the charset to be used for writing JAXB objects.
|
GenericJAXBMarshaller<JAXBTYPE> |
setFormattedOutput(boolean bWriteFormatted)
Change the way formatting happens when calling write.
|
GenericJAXBMarshaller<JAXBTYPE> |
setIndentString(String sIndentString)
Set the indent string to be used for writing JAXB objects.
|
GenericJAXBMarshaller<JAXBTYPE> |
setNamespaceContext(NamespaceContext aNSContext)
Set the namespace context (prefix to namespace URL mapping) to be used.
|
GenericJAXBMarshaller<JAXBTYPE> |
setNoNamespaceSchemaLocation(String sNoNamespaceSchemaLocation)
Set the no namespace schema location to be used for writing JAXB objects.
|
GenericJAXBMarshaller<JAXBTYPE> |
setReadSecure(boolean bReadSecure)
Enable or disable secure reading.
|
GenericJAXBMarshaller<JAXBTYPE> |
setSchemaLocation(String sSchemaLocation)
Set the schema location to be used for writing JAXB objects.
|
GenericJAXBMarshaller<JAXBTYPE> |
setUseContextCache(boolean bUseContextCache)
Change whether the context cache should be used or not.
|
GenericJAXBMarshaller<JAXBTYPE> |
setValidationEventHandlerFactory(IValidationEventHandlerFactory aVEHFactory)
Set a factory to be used to create
ValidationEventHandler objects. |
String |
toString() |
com.helger.commons.state.ESuccess |
write(JAXBTYPE aObject,
IJAXBWriter.IJAXBMarshaller<JAXBTYPE> aMarshallerFunc)
Convert the passed object to XML.
|
com.helger.commons.callback.CallbackList<com.helger.commons.callback.exception.IExceptionCallback<JAXBException>> |
writeExceptionCallbacks() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitread, read, read, read, read, read, read, read, read, read, read, read, read, read, read, read, readgetAsByteBuffer, getAsBytes, getAsDocument, getAsInputStream, getAsMicroDocument, getAsMicroElement, getAsString, getXMLWriterSettings, hasCharset, hasIndentString, hasNoNamespaceSchemaLocation, hasSchemaLocation, write, write, write, write, write, write, write, write, writepublic static final boolean DEFAULT_READ_SECURE
public GenericJAXBMarshaller(@Nonnull Class<JAXBTYPE> aType, @Nonnull QName aQName)
aType - The class of the JAXB document implementation type. May not be
null.aQName - The qualified name in which the object should be wrapped. May not be
null.createSimpleJAXBElement(QName, Class)public GenericJAXBMarshaller(@Nonnull Class<JAXBTYPE> aType, @Nonnull Function<? super JAXBTYPE,? extends JAXBElement<JAXBTYPE>> aWrapper)
aType - The class of the JAXB document implementation type. May not be
null.aWrapper - Wrap the passed domain object into a JAXBElement for
marshalling (writing). This can usually be done using the
respective's package ObjectFactory implementation. May not be
null.public GenericJAXBMarshaller(@Nonnull Class<JAXBTYPE> aType, @Nullable List<? extends com.helger.commons.io.resource.ClassPathResource> aXSDs, @Nonnull Function<? super JAXBTYPE,? extends JAXBElement<JAXBTYPE>> aJAXBElementWrapper)
aType - The class of the JAXB document implementation type. May not be
null.aXSDs - The XSDs used to validate document. May be null or
empty indicating, that no XSD check is needed.aJAXBElementWrapper - Wrap the passed domain object into a JAXBElement for
marshalling (writing). This can usually be done using the
respective's package ObjectFactory implementation. May not be
null.@Nonnull protected final Class<JAXBTYPE> getType()
null.@Nullable public final ClassLoader getClassLoader()
getClassLoader in interface com.helger.commons.lang.IHasClassLoader@Nonnull public final GenericJAXBMarshaller<JAXBTYPE> setValidationEventHandlerFactory(@Nullable IValidationEventHandlerFactory aVEHFactory)
ValidationEventHandler objects.
By default none is present.aVEHFactory - The new factory to be used. May be null.@Nullable public final IValidationEventHandlerFactory getValidationEventHandlerFactory()
null if explicitly set.public final boolean isReadSecure()
IJAXBReaderisReadSecure in interface IJAXBReader<JAXBTYPE>true if secure reading is enabled.@Nonnull public final GenericJAXBMarshaller<JAXBTYPE> setReadSecure(boolean bReadSecure)
bReadSecure - true to read secure, false to disable
secure reading.@Nullable public final NamespaceContext getNamespaceContext()
getNamespaceContext in interface IJAXBWriter<JAXBTYPE>null.@Nonnull public final GenericJAXBMarshaller<JAXBTYPE> setNamespaceContext(@Nullable NamespaceContext aNSContext)
aNSContext - The namespace context to be used. May be null.public final boolean isFormattedOutput()
isFormattedOutput in interface IJAXBWriter<JAXBTYPE>true if the JAXB output should be formatted. Default
is false.@Nonnull public final GenericJAXBMarshaller<JAXBTYPE> setFormattedOutput(boolean bWriteFormatted)
bWriteFormatted - true to write formatted output.@Nullable public final Charset getCharset()
getCharset in interface IJAXBWriter<JAXBTYPE>null
by default.@Nonnull public final GenericJAXBMarshaller<JAXBTYPE> setCharset(@Nullable Charset aCharset)
aCharset - The charset to be used by default. May be null.@Nullable public final String getIndentString()
getIndentString in interface IJAXBWriter<JAXBTYPE>null by default. Only used when formatted output is
used.@Nonnull public final GenericJAXBMarshaller<JAXBTYPE> setIndentString(@Nullable String sIndentString)
sIndentString - The indent string to be used. May be null.@Nullable public final String getSchemaLocation()
getSchemaLocation in interface IJAXBWriter<JAXBTYPE>null by
default.@Nonnull public final GenericJAXBMarshaller<JAXBTYPE> setSchemaLocation(@Nullable String sSchemaLocation)
sSchemaLocation - The schema location to be used. May be null.@Nullable public final String getNoNamespaceSchemaLocation()
getNoNamespaceSchemaLocation in interface IJAXBWriter<JAXBTYPE>null by default.@Nonnull public final GenericJAXBMarshaller<JAXBTYPE> setNoNamespaceSchemaLocation(@Nullable String sNoNamespaceSchemaLocation)
sNoNamespaceSchemaLocation - The no namespace schema location to be used. May be
null.public final boolean isUseContextCache()
@Nonnull public final GenericJAXBMarshaller<JAXBTYPE> setUseContextCache(boolean bUseContextCache)
bUseContextCache - true to use it (default), false if not.@Nonnull @ReturnsMutableObject public final com.helger.commons.callback.CallbackList<com.helger.commons.callback.exception.IExceptionCallback<JAXBException>> readExceptionCallbacks()
null.@Nonnull @ReturnsMutableObject public final com.helger.commons.callback.CallbackList<com.helger.commons.callback.exception.IExceptionCallback<JAXBException>> writeExceptionCallbacks()
null.@Nonnull @Nonempty @ReturnsMutableCopy public final com.helger.commons.collection.impl.ICommonsList<com.helger.commons.io.resource.ClassPathResource> getOriginalXSDs()
null.@Nullable protected Schema createValidationSchema()
null
indicating that no validation is required.@Nonnull @OverrideOnDemand protected JAXBContext getJAXBContext(@Nullable ClassLoader aClassLoader) throws JAXBException
aClassLoader - The class loader to be used for XML schema resolving. May be
null.null.JAXBException - In case creation fails@OverrideOnDemand protected void customizeUnmarshaller(@Nonnull Unmarshaller aUnmarshaller)
aUnmarshaller - The object to customize. Never null.@Nullable public final JAXBTYPE read(@Nonnull IJAXBReader.IJAXBUnmarshaller<JAXBTYPE> aHandler)
IJAXBReaderread in interface IJAXBReader<JAXBTYPE>aHandler - The unmarshalling handler. May not be null.null in case reading fails.@OverrideOnDemand protected void customizeMarshaller(@Nonnull Marshaller aMarshaller)
aMarshaller - The object to customize. Never null.@Nonnull public final com.helger.commons.state.ESuccess write(@Nonnull JAXBTYPE aObject, @Nonnull IJAXBWriter.IJAXBMarshaller<JAXBTYPE> aMarshallerFunc)
IJAXBWriterwrite in interface IJAXBWriter<JAXBTYPE>aObject - The object to be converted. May not be null.aMarshallerFunc - The marshalling function. May not be null.ESuccess@Nonnull public static <T> Function<T,JAXBElement<T>> createSimpleJAXBElement(@Nonnull QName aQName, @Nonnull Class<T> aClass)
JAXBElement objects.T - the type to wrapaQName - QName to use. May not be null.aClass - The implementation class to use.null.GenericJAXBMarshaller(Class, QName)Copyright © 2015–2021 Philip Helger. All rights reserved.