Example usage for javax.xml.bind Marshaller setAdapter

List of usage examples for javax.xml.bind Marshaller setAdapter

Introduction

In this page you can find the example usage for javax.xml.bind Marshaller setAdapter.

Prototype

public <A extends XmlAdapter> void setAdapter(Class<A> type, A adapter);

Source Link

Document

Associates a configured instance of XmlAdapter with this marshaller.

Usage

From source file:org.gitools.resource.AbstractXmlFormat.java

public void beforeWrite(OutputStream out, IResourceLocator resourceLocator, R resource, Marshaller marshaller,
        IProgressMonitor progressMonitor) throws PersistenceException {
    dependencies = new ArrayList<>();
    marshaller.setAdapter(ResourceReferenceXmlAdapter.class,
            new ResourceReferenceXmlAdapter(dependencies, resourceLocator));
}

From source file:org.paxle.core.doc.impl.BasicDocumentFactory.java

public <Doc> Map<String, DataHandler> marshal(Doc document, OutputStream output) throws IOException {
    try {/*from   w  ww . j ava  2 s  .  co m*/

        final JaxbAttachmentMarshaller am = new JaxbAttachmentMarshaller();
        final Marshaller m = context.createMarshaller();

        m.setAdapter(JaxbDocAdapter.class, new JaxbDocAdapter());
        m.setAdapter(JaxbFileAdapter.class, new JaxbFileAdapter(this.tempFileManager));
        m.setAdapter(JaxbFieldMapAdapter.class, new JaxbFieldMapAdapter(this.tempFileManager));
        m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
        //         m.setProperty("com.sun.xml.bind.ObjectFactory", new BasicJaxbFactory());
        m.setAttachmentMarshaller(am);

        m.marshal(document, output);
        output.flush();

        return am.getAttachmentsMap();
    } catch (JAXBException e) {
        final IOException ioe = new IOException(
                String.format("Unable to marshal the document '%s'.", document.getClass().getName()));
        ioe.initCause(e);
        throw ioe;
    }
}