use of javax.xml.bind.Marshaller in project SmartApplianceEnabler by camueller.
the class SempController method marshall.
private String marshall(Device2EM device2EM) {
StringWriter writer = new StringWriter();
try {
JAXBContext context = JAXBContext.newInstance(Device2EM.class);
Marshaller marshaller = context.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
marshaller.marshal(device2EM, writer);
return writer.toString();
} catch (JAXBException e) {
logger.error("Error marshalling", e);
}
return null;
}
use of javax.xml.bind.Marshaller in project ddf by codice.
the class XmlParser method marshal.
private void marshal(ParserConfigurator configurator, Consumer<Marshaller> marshallerConsumer) throws ParserException {
JAXBContext jaxbContext = getContext(configurator.getContextPath(), configurator.getClassLoader());
ClassLoader tccl = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(configurator.getClassLoader());
Marshaller marshaller = jaxbContext.createMarshaller();
if (configurator.getAdapter() != null) {
marshaller.setAdapter(configurator.getAdapter());
}
if (configurator.getHandler() != null) {
marshaller.setEventHandler(configurator.getHandler());
}
for (Map.Entry<String, Object> propRow : configurator.getProperties().entrySet()) {
marshaller.setProperty(propRow.getKey(), propRow.getValue());
}
marshallerConsumer.accept(marshaller);
} catch (RuntimeException e) {
LOGGER.debug("Error marshalling ", e);
throw new ParserException("Error marshalling ", e);
} catch (JAXBException e) {
LOGGER.debug("Error marshalling ", e);
throw new ParserException("Error marshalling", e);
} finally {
Thread.currentThread().setContextClassLoader(tccl);
}
}
use of javax.xml.bind.Marshaller in project ddf by codice.
the class KMLTransformerImpl method marshalKml.
private String marshalKml(Kml kmlResult) {
String kmlResultString = null;
StringWriter writer = new StringWriter();
try {
Marshaller marshaller = jaxbContext.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.FALSE);
marshaller.setProperty(Marshaller.JAXB_ENCODING, UTF_8);
marshaller.marshal(kmlResult, writer);
} catch (JAXBException e) {
LOGGER.debug("Failed to marshal KML: ", e);
}
kmlResultString = writer.toString();
return kmlResultString;
}
use of javax.xml.bind.Marshaller in project cogcomp-nlp by CogComp.
the class XmlModel method getMarshaller.
private static Marshaller getMarshaller(Object o) throws JAXBException {
Marshaller m = getContext(o.getClass()).createMarshaller();
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
m.setProperty("jaxb.encoding", "UTF-8");
return m;
}
use of javax.xml.bind.Marshaller in project jdk8u_jdk by JetBrains.
the class XmlConfigUtils method toString.
/**
* Creates an XML string representation of the given bean.
* @throws IllegalArgumentException if the bean class is not known by the
* underlying XMLbinding context.
* @return An XML string representation of the given bean.
**/
public static String toString(Object bean) {
try {
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
final Marshaller m = createMarshaller();
m.setProperty(m.JAXB_FRAGMENT, Boolean.TRUE);
m.marshal(bean, baos);
return baos.toString();
} catch (JAXBException x) {
final IllegalArgumentException iae = new IllegalArgumentException("Failed to write SessionConfigBean: " + x, x);
throw iae;
}
}
Aggregations