Example usage for javax.xml.bind JAXB marshal

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

Introduction

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

Prototype

public static void marshal(Object jaxbObject, Result xml) 

Source Link

Document

Writes a Java object tree to XML and store it to the specified location.

Usage

From source file:Main.java

/**
 * Marshal an arbitrary object with JAXB.
 *
 * @param object Object/*from ww w.  ja v a  2 s  .c om*/
 * @param stream Output stream to write to
 */
public static void marshal(Object object, OutputStream stream) throws Exception {
    JAXB.marshal(object, stream);
    stream.close();
}

From source file:com.meschbach.psi.util.rest.JAXBEntityBuilder.java

public HttpEntity buildEntity() throws PSIException {
    try {/*from w  w  w  .j a v  a2 s  .  c  om*/
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        JAXB.marshal(target, baos);
        return new StringEntity(baos.toString());
    } catch (Exception e) {
        throw new PSIException("Unable to marshall object " + target + "via JAXB", e);
    }
}

From source file:com.hp.mercury.ci.jenkins.plugins.oo.http.JaxbEntity.java

public void writeTo(final OutputStream outstream) throws IOException {
    JAXB.marshal(jaxbObject, outstream);
}

From source file:com.coupa.api.impl.DefaultRepository.java

public List<T> findAll(T prototype, boolean exactMatch) {
    OutputStream outputStream = new ByteArrayOutputStream();
    JAXB.marshal(prototype, outputStream);
    Map<String, String> conditions = XMLToHashMapAdapter.convertToMap(outputStream.toString());
    return findAll(conditions, exactMatch, 0, null);
}

From source file:it.geosolutions.unredd.stats.model.config.ConfigTest.java

public void testClassificationLayer() throws IOException {
    ClassificationLayer cl = new ClassificationLayer();
    cl.setFile("filename");
    //        cl.setLayerName("layername");
    cl.setPivot(Arrays.asList(1.0, 2.0, 3.0));
    cl.setZonal(false);/*from ww w .j  a v a 2s  .  co m*/
    cl.setNodata(65535d);

    //        File outFile = File.createTempFile("classif", ".xml");
    //        System.out.println("Creating file " + outFile);
    JAXB.marshal(cl, System.out);
}

From source file:net.javacrumbs.airline.server.VanillaTest.java

@Test
public void testGetFlightsXml() throws AirlineException, DatatypeConfigurationException, TransformerException {
    GetFlightsRequest request = JAXB.unmarshal(getStream("request1.xml"), GetFlightsRequest.class);

    GetFlightsResponse response = endpoint.getFlights(request);

    DOMResult domResponse = new DOMResult();
    JAXB.marshal(response, domResponse);

    XMLUnit.setIgnoreWhitespace(true);/*from   www.j  a v  a2  s .c  o  m*/
    XMLAssert.assertXMLEqual(getDocument("response1.xml"), (Document) domResponse.getNode());

}

From source file:ca.uhn.hl7v2.testpanel.model.conn.InboundConnectionList.java

@Override
public String exportConfigToXml() {
    StringWriter writer = new StringWriter();
    JAXB.marshal(this, writer);
    return writer.toString();
}

From source file:it.geosolutions.unredd.stats.model.config.ConfigTest.java

public void testStatistic() throws IOException {
    StatisticConfiguration s = new StatisticConfiguration();
    s.setName("test_stat");
    s.setTitle("A sample statistic");
    s.setDescription("A sample statistic definition for testing purposes");

    s.setTopics(Arrays.asList("test", "stat", "example"));

    s.setStats(Arrays.asList(StatsType.SUM, StatsType.COUNT));

    ClassificationLayer cl1 = new ClassificationLayer();
    cl1.setFile("filename");
    List<Double> pivot = new ArrayList<Double>();
    pivot.add(1.0);//from   w ww . j  av  a 2  s.com
    pivot.add(20.0);
    pivot.add(300.0);
    //        cl1.setPivot(Arrays.asList(1.0, 20.0, 300.0));
    cl1.setPivot(pivot);
    cl1.setZonal(false);

    ClassificationLayer cl2 = new ClassificationLayer();
    cl2.setFile("filename2");

    s.setClassifications(Arrays.asList(cl1, cl2));

    assertNotNull(cl1.getPivot());
    assertTrue(cl1.isPivotDefined());
    //        File outFile = File.createTempFile("classif", ".xml");
    //        System.out.println("Creating file " + outFile);
    JAXB.marshal(s, System.out);
}

From source file:edu.kit.cockpit.valuationserver.pollgenerator.PollGenerator.java

/**
 * Generate a poll message based on an evaluation
 * //from w  w  w. j a v  a 2 s  .  c  o  m
 * @param attribTypeList
 * @param eval
 * @param isVisible
 * @return
 * @throws DatatypeConfigurationException
 */
public static PollType createPoll(EvaluationE eval, boolean isVisible) throws DatatypeConfigurationException {

    // List<AttributeType> attribTypeList =
    // getComparableSFMAttributes(eval);

    PollType poll = new PollType();

    poll.setType(POLL_TYPE_ASPECT_COMPARISON);

    assert (eval.getId() != null);
    poll.setEvaluationId(String.valueOf(eval.getId()));

    poll.setVisible(isVisible);

    if (eval.getPollDeadline() != null)
        poll.setEndDate(DateUtil.getXmlGregCal(eval.getPollDeadline()));

    if (eval.getName() != null)
        poll.setTitle(eval.getName());

    if (eval.getDescription() != null)
        poll.setSubtitle(eval.getDescription());

    if (eval.getServiceId() != null)
        poll.setServiceId(eval.getServiceId());

    if (eval.getPollId() != null)
        poll.setPollId(eval.getPollId());

    // generate aspects from exclusive pairs of attribute types
    poll.setAspects(new PollType.Aspects());
    String[][] attribArray = getAttributePairings(eval);
    for (int i = 0; i < attribArray.length; i++) {
        PollType.Aspects.Aspect aspect = new PollType.Aspects.Aspect();
        aspect.setFeature1(attribArray[i][0]);
        aspect.setFeature2(attribArray[i][1]);
        poll.getAspects().getAspect().add(aspect);
    }

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    JAXB.marshal(poll, baos);
    log.info("Poll generated: " + System.getProperty("line.separator") + baos.toString());

    return poll;
}

From source file:bigbluej.Client.java

private String toXml(ModulesCommand modulesCommand) {
    Modules modules = new Modules();
    modules.setModules(new ArrayList<Module>());
    for (ModuleCommand moduleCommand : modulesCommand.getModules()) {
        Module module = new Module();
        module.setName(moduleCommand.getName());
        module.setDocuments(new ArrayList<Document>());
        for (DocumentCommand documentCommand : moduleCommand.getDocuments()) {
            Document document = new Document();
            document.setUrl(documentCommand.getUrl());
            if (StringUtils.isNotBlank(documentCommand.getName())) {
                document.setName(documentCommand.getName());
                document.setValue(Base64.encodeBase64String(documentCommand.getContent()));
                System.out.println("base64 value> " + document.getValue());
            }//  ww w  .jav a 2 s  .  c o  m
            module.getDocuments().add(document);
        }
        modules.getModules().add(module);
    }
    StringWriter stringWriter = new StringWriter();
    JAXB.marshal(modules, stringWriter);
    return stringWriter.getBuffer().toString();
}