Example usage for javax.xml.bind JAXBContext createUnmarshaller

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

Introduction

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

Prototype

public abstract Unmarshaller createUnmarshaller() throws JAXBException;

Source Link

Document

Create an Unmarshaller object that can be used to convert XML data into a java content tree.

Usage

From source file:org.apache.cxf.systest.jaxrs.JAXRSClientServerStreamingTest.java

private Book readBook(InputStream is) throws Exception {
    JAXBContext c = JAXBContext.newInstance(new Class[] { Book.class });
    Unmarshaller u = c.createUnmarshaller();
    return (Book) u.unmarshal(is);
}

From source file:dk.dma.msinm.common.time.TimeParser.java

/**
 * Parses the time into a {@code TimeModel} model.
 * @param time the time description to parse
 * @return the time model//from  www.j av  a  2 s . c o m
 */
public TimeModel parseModel(String time) throws TimeException {
    String timeXml = null;
    try {
        // Transform the time description into xml
        timeXml = parse(time);

        // Attempt to parse the XML
        JAXBContext jc = JAXBContext.newInstance(TimeModel.class);
        Unmarshaller unmarshaller = jc.createUnmarshaller();
        return (TimeModel) unmarshaller.unmarshal(new StringReader(timeXml));

    } catch (Exception e) {
        throw new TimeException("Failed parsing time description: " + time + "\n" + timeXml, e);
    }
}

From source file:br.eti.danielcamargo.backend.common.config.context.CoreConfig.java

@Bean
public Unmarshaller unmarshaller() throws Exception {
    InputStream is = getClass().getResourceAsStream("/META-INF/hsnpts/programas.xml");
    JAXBContext jaxbContext = JAXBContext.newInstance(HsnPersonal.class);
    Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
    HsnPersonal hsnPersonal = (HsnPersonal) jaxbUnmarshaller.unmarshal(is);
    hsnPersonal.getProgramas();/* www .j  ava2s  . com*/
    return jaxbUnmarshaller;
}

From source file:org.jasig.portlet.blackboardvcportlet.dao.ws.impl.RecordingWSDaoImplTest.java

private BlackboardListRecordingLongResponseCollection getSingleListOfRecordingLong() throws JAXBException {
    final JAXBContext context = JAXBContext.newInstance("com.elluminate.sas");
    final Unmarshaller unmarshaller = context.createUnmarshaller();
    BlackboardListRecordingLongResponseCollection response = (BlackboardListRecordingLongResponseCollection) unmarshaller
            .unmarshal(/*from   ww  w .  j  a  v  a 2 s . c  o  m*/
                    this.getClass().getResourceAsStream("/data/singleListRecordingLongResponseCollection.xml"));

    return response;
}

From source file:org.jasig.portlet.blackboardvcportlet.dao.ws.impl.RecordingWSDaoImplTest.java

private BlackboardListRecordingShortResponseCollection getSingleListOfRecordingShort() throws JAXBException {
    final JAXBContext context = JAXBContext.newInstance("com.elluminate.sas");
    final Unmarshaller unmarshaller = context.createUnmarshaller();
    BlackboardListRecordingShortResponseCollection response = (BlackboardListRecordingShortResponseCollection) unmarshaller
            .unmarshal(this.getClass()
                    .getResourceAsStream("/data/singleListRecordingShortResponseCollection.xml"));

    return response;
}

From source file:org.jasig.services.persondir.support.xml.CachingJaxbLoaderImpl.java

/**
 * @param jaxbContext The context to get an unmarshaller for
 * @return An unmarshaller to use to generate object from the XML
 *//*from   w w  w.  j  a v a2  s  . c om*/
protected Unmarshaller getUnmarshaller(final JAXBContext jaxbContext) {
    try {
        return jaxbContext.createUnmarshaller();
    } catch (JAXBException e) {
        throw new RuntimeException(
                "Failed to create " + Unmarshaller.class + " to unmarshal " + this.loadedType, e);
    }
}

From source file:in.gov.uidai.auth.aua.httpclient.OtpClient.java

private OtpRes parseOtpResponseXML(String xmlToParse) throws JAXBException {

    //Create an XMLReader to use with our filter 
    try {/*from   w  w  w. j a  v  a  2  s .c o m*/
        //Prepare JAXB objects 
        JAXBContext jc = JAXBContext.newInstance(OtpRes.class);
        Unmarshaller u = jc.createUnmarshaller();

        XMLReader reader;
        reader = XMLReaderFactory.createXMLReader();

        //Create the filter (to add namespace) and set the xmlReader as its parent. 
        NamespaceFilter inFilter = new NamespaceFilter("http://www.uidai.gov.in/authentication/otp/1.0", true);
        inFilter.setParent(reader);

        //Prepare the input, in this case a java.io.File (output) 
        InputSource is = new InputSource(new StringReader(xmlToParse));

        //Create a SAXSource specifying the filter 
        SAXSource source = new SAXSource(inFilter, is);

        //Do unmarshalling 
        OtpRes res = u.unmarshal(source, OtpRes.class).getValue();
        return res;
    } catch (Exception e) {
        e.printStackTrace();
        throw new RuntimeException("Erorr while parsing response XML" + e.getMessage());
    }
}

From source file:at.ac.tuwien.dsg.quelle.cloudDescriptionParsers.impl.CloudFileDescriptionParser.java

public CloudProvider getCloudProviderDescription() {
    try {// ww w . ja v a 2s .com
        JAXBContext jAXBContext = JAXBContext.newInstance(CloudProvider.class);
        InputStream fileStream = context.getResource(descriptionFile).getInputStream();
        return (CloudProvider) jAXBContext.createUnmarshaller().unmarshal(fileStream);
    } catch (Exception ex) {
        log.error("Cannot unmarshall : {}", ex.getMessage());
        ex.printStackTrace();
        return new CloudProvider("empty");
    }
}

From source file:at.ac.tuwien.dsg.quelle.cloudDescriptionParsers.impl.CloudFileDescriptionParser.java

public CloudProvider getCloudProviderDescription(String descriptionFile) {
    try {/*from   w ww .j  ava2 s . com*/
        JAXBContext jAXBContext = JAXBContext.newInstance(CloudProvider.class);
        InputStream fileStream = context.getResource(descriptionFile).getInputStream();
        return (CloudProvider) jAXBContext.createUnmarshaller().unmarshal(fileStream);
    } catch (Exception ex) {
        log.error("Cannot unmarshall : {}", ex.getMessage());
        ex.printStackTrace();
        return new CloudProvider("empty");
    }
}

From source file:org.camelcookbook.rest.binding.BindingModeSpringTest.java

@Test
public void testGetOne() throws Exception {
    final Item origItem = getItemService().getItem(0);
    final String origItemJson = objectWriter.writeValueAsString(origItem);

    String outJson = fluentTemplate().to("undertow:http://localhost:" + port1 + "/items/0")
            .withHeader(Exchange.HTTP_METHOD, "GET").withHeader("Accept", "application/json")
            .request(String.class);

    assertEquals(origItemJson, outJson);

    String outXml = fluentTemplate().to("undertow:http://localhost:" + port1 + "/items/0")
            .withHeader(Exchange.HTTP_METHOD, "GET").withHeader("Accept", "application/xml")
            .request(String.class);

    JAXBContext jaxbContext = JAXBContext.newInstance(Item.class);
    Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();

    Item itemOut = (Item) jaxbUnmarshaller.unmarshal(new StringReader(outXml));

    assertEquals(origItem, itemOut);//from w w w .  j  a v  a 2  s  .c o  m
}