Example usage for javax.xml.bind JAXBContext newInstance

List of usage examples for javax.xml.bind JAXBContext newInstance

Introduction

In this page you can find the example usage for javax.xml.bind JAXBContext newInstance.

Prototype

public static JAXBContext newInstance(Class<?>... classesToBeBound) throws JAXBException 

Source Link

Document

Create a new instance of a JAXBContext class.

Usage

From source file:eu.planets_project.tb.impl.serialization.ExperimentRecords.java

/**
 * @param in/*from   w w  w  .jav  a2 s .c o m*/
 * @return
 */
public static ExperimentRecords readFromInputStream(InputStream in) {
    try {
        JAXBContext jc = JAXBContext.newInstance(ExperimentRecords.class);
        Unmarshaller u = jc.createUnmarshaller();
        ExperimentRecords exp = (ExperimentRecords) u.unmarshal(in);
        return exp;
    } catch (JAXBException e) {
        log.fatal("Reading Experiments from XML failed: " + e);
        return null;
    }
}

From source file:org.wallerlab.yoink.molecular.data.AbstractJaxbWriter.java

/**
 * use JAXB writer to write out an instance to a file.
 * /*from  w  ww. j  a v a2  s  . c  o m*/
 * @param nameOfFile
 *            - the name of out put file
 * @param jaxbObject
 *            - the instance will be written into a file
 */
protected void marshall() {
    try {
        jaxbContext = JAXBContext.newInstance(Class.forName(jaxbObject.getClass().getName()));
        jaxbMarshaller = jaxbContext.createMarshaller();
        jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        marshal();
    } catch (JAXBException e) {
        e.printStackTrace();
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    }
}

From source file:se.inera.intyg.intygstjanst.web.integration.converter.SendMessageToCareConverter.java

public String convertToXmlString(SendMessageToCareType sendMessageToCareType) throws JAXBException {
    ObjectFactory objectFactory = new ObjectFactory();
    JAXBContext jaxbContext = JAXBContext.newInstance(SendMessageToCareType.class);
    Marshaller marshaller = jaxbContext.createMarshaller();
    StringWriter stringWriter = new StringWriter();
    marshaller.marshal(objectFactory.createSendMessageToCare(sendMessageToCareType), stringWriter);
    return stringWriter.toString().replaceAll("[\\n\\t ]", "");
}

From source file:StringAdapter.java

public Main() throws JAXBException {
    jc = JAXBContext.newInstance(Root.class);
}

From source file:org.hisp.dhis.dxf2.importsummary.ImportSummaryTest.java

@Test
public void marshallImportSummary() throws Exception {
    ImportSummary summary = new ImportSummary();
    summary.setDescription("Testing");
    summary.setStatus(ImportStatus.SUCCESS);
    summary.setDataValueCount(new ImportCount(2, 1, 4));

    JAXBContext jaxbContext = JAXBContext.newInstance(ImportSummary.class);

    Marshaller jaxbmarshaller = jaxbContext.createMarshaller();
    jaxbmarshaller.marshal(summary, System.out);
}

From source file:fr.mael.microrss.xml.RSSFeedParser.java

@Override
public List<Article> readArticles(Feed feed) throws Exception {
    List<Article> articles = new ArrayList<Article>();
    JAXBContext jc = JAXBContext.newInstance("fr.mael.microrss.xml.rss");
    Unmarshaller unmarshaller = jc.createUnmarshaller();
    HttpGet get = new HttpGet(feed.getUrl());
    HttpResponse response = client.execute(get);
    try {//from   w ww . j  av  a 2s .co m
        Rss rss = (Rss) unmarshaller.unmarshal(response.getEntity().getContent());
        for (RssItem item : rss.getChannel().getItem()) {
            Article article = readArticle(item);
            article.getFeeds().add(feed);
            articles.add(article);
        }
        return articles;
    } catch (Exception e) {
        EntityUtils.consume(response.getEntity());
        throw new Exception(e);
    }
}

From source file:org.bremersee.sms.test.ModelTests.java

@Before
public void createJAXBContext() throws JAXBException {
    this.jaxbContext = JAXBContext
            .newInstance(org.bremersee.sms.model.ObjectFactory.class.getPackage().getName());
}

From source file:org.osmtools.api.SchemaService.java

public Marshaller createOsmMarshaller() {
    try {/* www.ja v a  2  s.c  o  m*/
        return JAXBContext.newInstance(Osm.class).createMarshaller();
    } catch (JAXBException e) {
        throw new RuntimeException(e);
    }
}

From source file:com.sharksharding.util.xml.CreateCoreXml.java

public CreateCoreXml() {
    try {//  w w  w.  j a  v a2 s  .  co  m
        JAXBContext jAXBContext = JAXBContext.newInstance(Beans.class);
        marshaller = jAXBContext.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.googlecode.sardine.Factory.java

/** */
public Factory() {
    try {/*from   www .  j  a v a  2s .  c o  m*/
        if (this.context == null)
            this.context = JAXBContext.newInstance(ObjectFactory.class);
    } catch (JAXBException e) {
        e.printStackTrace();
    }
}