Class XmlUtilities
JAXB helpers used to read and write engine XML resources.
JAXB contexts are cached by root type. Convenience save methods log marshalling failures and
return the requested path; read(Class, URL) exposes unmarshalling failures to its caller.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> jakarta.xml.bind.JAXBContextgetContext(Class<T> cls) Returns the cached JAXB context for a root type, creating it when necessary.static <T> TUnmarshals an XML resource and resolves relative URLs against that resource.static PathMarshals an object to a file using formatted XML output.static PathMarshals an object after ensuring that the destination has an extension.static voidsaveWithCustomIndentation(ByteArrayInputStream input, OutputStream fos, int indentation) Writes XML with custom indentation and closes the output stream after a successful transformation.
-
Method Details
-
saveWithCustomIndentation
public static void saveWithCustomIndentation(ByteArrayInputStream input, OutputStream fos, int indentation) Writes XML with custom indentation and closes the output stream after a successful transformation.
If
inputis the result of JAXB marshalling, setMarshaller.JAXB_FORMATTED_OUTPUTtofalseso existing indentation does not interfere. Transformation, flushing, and closing failures are logged rather than propagated. The input stream is not closed.- Parameters:
input- The input stream that contains the original XML.fos- The output stream that is used to save the XML.indentation- The indentation with which the XML should be saved.
-
getContext
Returns the cached JAXB context for a root type, creating it when necessary.
Context-creation failures are logged.
- Type Parameters:
T- The root type.- Parameters:
cls- The JAXB root type.- Returns:
- The cached context, or
nullif it could not be created.
-
read
Unmarshals an XML resource and resolves relative URLs against that resource.- Type Parameters:
T- The root type.- Parameters:
cls- The expected root type.path- The resource URL.- Returns:
- The unmarshalled object, or
nullif a JAXB context could not be created. - Throws:
jakarta.xml.bind.JAXBException- if unmarshalling fails.
-
save
Marshals an object to a file using formatted XML output.
Marshalling failures are logged rather than thrown.
- Parameters:
object- The JAXB object to save.filePath- The destination path.- Returns:
filePath, ornullwhen the path or JAXB context is unavailable.
-
save
Marshals an object after ensuring that the destination has an extension.- Parameters:
object- The JAXB object to save.path- The destination path without or with an extension.extension- The required extension, with or without a leading dot.- Returns:
- The actual destination path, or
nullif saving could not be initialized.
-