Last active
August 29, 2015 14:21
-
-
Save jonashackt/f8580d18a5b3ae67840d to your computer and use it in GitHub Desktop.
Marhall an JAXBObject into org.w3c.dom.Document
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static Document marhallJaxbElement(Object jaxbElement) throws BusinessException { | |
Document jaxbDoc = null; | |
try { | |
Marshaller marshaller = setUpMarshaller(jaxbElement.getClass()); | |
jaxbDoc = createNewDocument(); | |
marshaller.marshal(jaxbElement, jaxbDoc); | |
} catch (Exception exception) { | |
throw new BusinessException("Problem beim marshallen des JAXBElements in ein Document: " + exception.getMessage()); | |
} | |
return jaxbDoc; | |
} | |
private static Document createNewDocument() throws BusinessException { | |
return setUpDocumentBuilder().newDocument(); | |
} | |
private static <T> Marshaller setUpMarshaller(Class<T> jaxbElementClass) throws JAXBException { | |
JAXBContext jaxbContext = JAXBContext.newInstance(jaxbElementClass); | |
return jaxbContext.createMarshaller(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment