Example usage for javax.xml.bind Marshaller marshal

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

Introduction

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

Prototype

public void marshal(Object jaxbElement, javax.xml.stream.XMLEventWriter writer) throws JAXBException;

Source Link

Document

Marshal the content tree rooted at jaxbElement into a javax.xml.stream.XMLEventWriter .

Usage

From source file:com.springsource.hq.plugin.tcserver.serverconfig.ProfileMarshaller.java

public void marshal(Profile graph, Result result) throws JAXBException, IOException {
    Marshaller marshaller = jaxbContext.createMarshaller();
    marshaller.setSchema(profileSchema);
    marshaller.marshal(graph, result);
}

From source file:com.redhat.akashche.wixgen.jaxb.SampleInstallerTest.java

@Test
public void test() throws Exception {
    JAXBContext jaxb = JAXBContext.newInstance(SampleInstallerTest.class.getPackage().getName());
    InputStream is = null;/*w  w w  .ja  va2 s. c  om*/
    Writer writer = null;
    try {
        is = SampleInstallerTest.class.getResourceAsStream("SampleInstaller.wxs");
        Reader reader = new InputStreamReader(is, Charset.forName("UTF-8"));
        Wix wix = (Wix) jaxb.createUnmarshaller().unmarshal(reader);
        wix.getProduct().setName(wix.getProduct().getName() + " (JAXB)");
        //            OutputStream os = new FileOutputStream("SampleInstaller_JAXB.wxs");
        OutputStream os = new NullOutputStream();
        writer = new OutputStreamWriter(os, Charset.forName("UTF-8"));
        Marshaller marshaller = jaxb.createMarshaller();
        marshaller.setProperty(JAXB_FORMATTED_OUTPUT, true);
        marshaller.marshal(wix, writer);
    } finally {
        closeQuietly(is);
        closeQuietly(writer);
    }
}

From source file:Product.java

public String toXML() throws JAXBException {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    JAXBContext context = JAXBContext.newInstance(Product.class);
    Marshaller m = context.createMarshaller();
    m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
    m.marshal(this, out);
    return out.toString();
}

From source file:com.mycompany.dao.report.XMLReport.java

@Override
public void generate() throws JAXBException {
    JAXBContext jaxbContext = JAXBContext.newInstance(Books.class);
    Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
    Books books = (Books) jaxbUnmarshaller.unmarshal(new File(fileName));

    for (Iterator<Book> iterator = books.getBooks().iterator(); iterator.hasNext();) {
        Book book = iterator.next();
        if (book.getQuantity() != 0) {
            // Remove the current element from the iterator and the list.
            iterator.remove();/*from  w w w .  j av a 2 s. c  o  m*/
        }
    }

    Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
    jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
    jaxbMarshaller.marshal(books, new File(fileName2));

}

From source file:com.trifork.batchcopy.client.BatchCopyClient.java

private String createRequestString(ReplicationRequestType request) throws JAXBException {

    StringWriter writer = new StringWriter();
    Marshaller marshaller = jaxContext.createMarshaller();
    marshaller.marshal(
            new JAXBElement<ReplicationRequestType>(serviceName, ReplicationRequestType.class, request),
            writer);/*from ww w. ja  v  a  2s .c  o  m*/
    return writer.toString();
}

From source file:com.microsoft.exchange.impl.RequestServerVersionClientInterceptor.java

@Override
public boolean handleRequest(MessageContext messageContext) throws WebServiceClientException {
    WebServiceMessage request = messageContext.getRequest();
    if (request instanceof SoapMessage) {
        SoapMessage soapMessage = (SoapMessage) request;
        SoapEnvelope envelope = soapMessage.getEnvelope();
        SoapHeader header = envelope.getHeader();
        RequestServerVersion rsv = new RequestServerVersion();
        rsv.setVersion(exchangeVersionType);

        try {/*  w w w . j a  va2  s .  c o m*/
            Marshaller m = jaxbContext.createMarshaller();
            m.marshal(rsv, header.getResult());
        } catch (JAXBException e) {
            log.error("JAXBException raised while attempting to add RequestServerVersion to soap header " + rsv,
                    e);
            throw new ExchangeWebServicesRuntimeException(
                    "JAXBException raised while attempting to add RequestServerVersion to soap header " + rsv,
                    e);
        }
    }
    return true;
}

From source file:com.jaspersoft.jasperserver.rest.services.RESTAttribute.java

private String generateProfileAttributeReport(List<ProfileAttribute> atts) {
    try {//ww  w.  ja v a2  s .c om
        StringWriter sw = new StringWriter();

        JAXBList<ProfileAttribute> lst;
        lst = new JAXBList<ProfileAttribute>(atts);

        Marshaller m = restUtils.getMarshaller(JAXBList.class, ProfileAttributeImpl.class);
        m.marshal(lst, sw);
        if (log.isDebugEnabled()) {
            log.debug("finished marshaling attributes: " + lst.size());
        }

        return sw.toString();
    } catch (JAXBException e) {
        throw new ServiceException(e.getMessage());
    }
}

From source file:com.photon.phresco.plugins.util.WarConfigProcessor.java

public void save() throws JAXBException {
    JAXBContext jaxbContext = JAXBContext.newInstance(Assembly.class);
    Marshaller marshal = jaxbContext.createMarshaller();
    marshal.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
    marshal.marshal(assembly, file);
}

From source file:com.codercowboy.photo.organizer.service.LibraryMarshaller.java

public void saveLibrary(Library library, String fileName) throws Exception {
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    try {//from   w  ww .j ava  2  s.c om
        Marshaller marshaller = this.createContext().createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        marshaller.marshal(library, outputStream);
        FileUtils.writeByteArrayToFile(new File(fileName), outputStream.toByteArray());
    } finally {
        outputStream.close();
    }
}

From source file:org.openmrs.module.dhisreport.api.dxf2.DataValueSetTest.java

@Test
public void marshallDataValueSet() throws Exception {
    DataValueSet dvset = new DataValueSet();
    dvset.setDataSet("ANC");
    dvset.setOrgUnit("OU1");
    dvset.setPeriod("2012-09");
    List<DataValue> dataValues = dvset.getDataValues();
    dataValues.add(new DataValue("DE1", "45"));
    dataValues.add(new DataValue("DE2", "45"));
    dataValues.add(new DataValue("DE3", "r543efdgty2", "53"));

    Writer xmlWriter = new StringWriter();
    JAXBContext jaxbContext = JAXBContext.newInstance(DataValueSet.class);

    Marshaller jaxbmarshaller = jaxbContext.createMarshaller();
    jaxbmarshaller.marshal(dvset, xmlWriter);
    String xml = xmlWriter.toString();

    //System.out.println( xml );
    assertEquals("3", xpathTest("count(//d:dataValue)", xml));
    assertEquals("53", xpathTest("//d:dataValue[3]/@value", xml));
    assertEquals("r543efdgty2", xpathTest("//d:dataValue[3]/@categoryOptionCombo", xml));

}