net.java.trueupdate.jms.JAXB Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of trueupdate-jms Show documentation
Show all versions of trueupdate-jms Show documentation
Provides services to transmit and receive update messages via JMS.
/*
* Copyright (C) 2013 Schlichtherle IT Services & Stimulus Software.
* All rights reserved. Use is subject to license terms.
*/
package net.java.trueupdate.jms;
import java.io.*;
import javax.xml.bind.*;
import net.java.trueupdate.message.*;
/**
* Provides functions for JAXB.
*
* @author Christian Schlichtherle
*/
final class JAXB {
private static final JAXBContext CONTEXT;
static {
try {
CONTEXT = JAXBContext.newInstance(UpdateMessageDto.class);
} catch (JAXBException ex) {
throw new IllegalStateException(ex);
}
}
static String encode(final UpdateMessage message) throws Exception {
final StringWriter sw = new StringWriter(1024);
final Marshaller m = marshaller();
if (!message.attachedLogs().isEmpty()) try {
m.setProperty("com.sun.xml.internal.bind.namespacePrefixMapper",
new DtoNamespaceMapper());
} catch(Exception anIncompatibleJaxbImplementationIsUsed) {
}
m.marshal(adapter().marshal(message), sw);
return sw.toString();
}
static UpdateMessage decode(String string) throws Exception {
return (UpdateMessage) adapter().unmarshal(
(UpdateMessageDto) unmarshaller().unmarshal(
new StringReader(string)));
}
private static Marshaller marshaller() throws JAXBException {
return CONTEXT.createMarshaller();
}
private static Unmarshaller unmarshaller() throws JAXBException {
return CONTEXT.createUnmarshaller();
}
private static UpdateMessageAdapter adapter() {
return new UpdateMessageAdapter();
}
private JAXB() { }
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy