Example usage for javax.xml.bind Unmarshaller unmarshal

List of usage examples for javax.xml.bind Unmarshaller unmarshal

Introduction

In this page you can find the example usage for javax.xml.bind Unmarshaller unmarshal.

Prototype

public Object unmarshal(javax.xml.stream.XMLEventReader reader) throws JAXBException;

Source Link

Document

Unmarshal XML data from the specified pull parser and return the resulting content tree.

Usage

From source file:org.cbio.portal.pipelines.foundation.FoundationFileTasklet.java

/**
 * Extract the case data from source xml file by root tag
 * @param xmlFile//from w  ww .  jav  a  2  s .  c  o m
 * @return
 * @throws JAXBException
 * @throws IOException
 * @throws ParserConfigurationException
 * @throws SAXException 
 */
private List<CaseType> extractFileCaseData(File xmlFile)
        throws JAXBException, IOException, ParserConfigurationException, SAXException {
    List<CaseType> newCases = new ArrayList();

    // get the document root and determine how to unmarshal document
    Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(xmlFile);
    Element root = document.getDocumentElement();
    if (root.getNodeName().equals("ClientCaseInfo")) {
        // unmarshal document with root tag = ClientCaseInfo
        JAXBContext context = JAXBContext.newInstance(ClientCaseInfoType.class);
        Unmarshaller jaxbUnmarshaller = context.createUnmarshaller();
        ClientCaseInfoType cci = (ClientCaseInfoType) jaxbUnmarshaller.unmarshal(root);
        newCases.addAll(cci.getCases().getCase());
    } else {
        // unmarshal document with root tag = ResultsReport
        JAXBContext context = JAXBContext.newInstance(ResultsReportType.class);
        Unmarshaller jaxbUnmarshaller = context.createUnmarshaller();
        ResultsReportType rrt = (ResultsReportType) jaxbUnmarshaller.unmarshal(root);
        newCases.add(new CaseType(rrt.getVariantReport()));
    }

    return newCases;
}

From source file:org.jasig.portlet.courses.dao.xml.MockCoursesSectionDao.java

@Override
public TermList getTermList(PortletRequest request) {
    try {/*from w w w .  ja v a2s.c  o  m*/
        JAXBContext jaxbContext = JAXBContext.newInstance(TermsAndCourses.class);
        Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
        this.summary = (TermsAndCourses) unmarshaller.unmarshal(mockData.getInputStream());
    } catch (IOException e) {
        log.error("Failed to read mock data for TermList", e);
    } catch (JAXBException e) {
        log.error("Failed to unmarshall mock data for TermList", e);
    }
    return summary.getTermList();
}

From source file:org.vertx.java.http.eventbusbridge.unit.EventBusBridgeRequestTest.java

@Test
public void testUnmarshallingFromXml() throws JAXBException, IOException {
    JAXBContext jaxbContext = JAXBContext.newInstance(EventBusBridgeRequest.class);
    Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
    InputStream input = getClass().getResourceAsStream("/unit/test-request.xml");
    EventBusBridgeRequest request = (EventBusBridgeRequest) jaxbUnmarshaller.unmarshal(input);
    assertEquals("testaddress", request.getAddress());
    assertEquals(Base64.decodeAsString("SGVsbG8gV29ybGQ="), new String(request.getMessage()));
    assertEquals("http://www.test.com/response", request.getResponseUrl());
    assertEquals("String", request.getEventBusMessageType().toString());
    assertEquals("application/xml", request.getResponseMediaType().toString());
}

From source file:com.moss.bdbadmin.client.service.BdbClient.java

public DbInfo dbInfo(IdProof assertion, String path) throws ServiceException {
    try {//from  w  w w  .j a v a2  s  . co  m
        GetMethod method = new GetMethod(baseUrl + "/" + path);
        method.setRequestHeader(AuthenticationHeader.HEADER_NAME, AuthenticationHeader.encode(assertion));

        int result = httpClient.executeMethod(method);
        if (result != 200) {
            throw new ServiceException(result);
        } else {
            Unmarshaller u = context.createUnmarshaller();
            return (DbInfo) u.unmarshal(method.getResponseBodyAsStream());
        }
    } catch (Exception ex) {
        throw new ServiceFailure(ex);
    }
}

From source file:org.fcrepo.auth.oauth.integration.api.ContainerWrapper.java

public void start() throws Exception {

    final JAXBContext context = JAXBContext.newInstance(WebAppConfig.class);
    final Unmarshaller u = context.createUnmarshaller();
    final WebAppConfig o = (WebAppConfig) u.unmarshal(getClass().getResource(this.configLocation));

    final URI uri = URI.create("http://localhost:" + port + "/");

    final Map<String, String> initParams = new HashMap<String, String>();

    server = GrizzlyWebContainerFactory.create(uri, initParams);

    // create a "root" web application
    final WebappContext wac = new WebappContext(o.displayName(), "");

    for (final ContextParam p : o.contextParams()) {
        wac.addContextInitParameter(p.name(), p.value());
    }/*from w  w w .java 2s.com*/

    for (final Listener l : o.listeners) {
        wac.addListener(l.className());
    }

    for (final Servlet s : o.servlets) {
        final ServletRegistration servlet = wac.addServlet(s.servletName(), s.servletClass());

        final Collection<ServletMapping> mappings = o.servletMappings(s.servletName());
        for (final ServletMapping sm : mappings) {
            servlet.addMapping(sm.urlPattern());
        }
        for (final InitParam p : s.initParams()) {
            servlet.setInitParameter(p.name(), p.value());
        }
    }

    for (final Filter f : o.filters) {
        final FilterRegistration filter = wac.addFilter(f.filterName(), f.filterClass());

        final Collection<FilterMapping> mappings = o.filterMappings(f.filterName());
        for (final FilterMapping sm : mappings) {
            final String urlPattern = sm.urlPattern();
            final String servletName = sm.servletName();
            if (urlPattern != null) {
                filter.addMappingForUrlPatterns(null, urlPattern);
            } else {
                filter.addMappingForServletNames(null, servletName);
            }

        }
        for (final InitParam p : f.initParams()) {
            filter.setInitParameter(p.name(), p.value());
        }
    }

    wac.deploy(server);

    final URL webXml = this.getClass().getResource("/web.xml");
    logger.error(webXml.toString());

    logger.debug("started grizzly webserver endpoint at " + server.getHttpHandler().getName());
}

From source file:org.fcrepo.integration.auth.oauth.api.ContainerWrapper.java

public void start() throws Exception {

    final JAXBContext context = JAXBContext.newInstance(WebAppConfig.class);
    final Unmarshaller u = context.createUnmarshaller();
    final WebAppConfig o = (WebAppConfig) u.unmarshal(getClass().getResource(this.configLocation));

    final URI uri = URI.create("http://localhost:" + port + "/");

    final Map<String, String> initParams = new HashMap<>();

    server = GrizzlyWebContainerFactory.create(uri, initParams);

    // create a "root" web application
    final WebappContext wac = new WebappContext(o.displayName(), "");

    for (final ContextParam p : o.contextParams()) {
        wac.addContextInitParameter(p.name(), p.value());
    }/* w ww  . jav  a2 s  .  co m*/

    for (final Listener l : o.listeners) {
        wac.addListener(l.className());
    }

    for (final Servlet s : o.servlets) {
        final ServletRegistration servlet = wac.addServlet(s.servletName(), s.servletClass());

        final Collection<ServletMapping> mappings = o.servletMappings(s.servletName());
        for (final ServletMapping sm : mappings) {
            servlet.addMapping(sm.urlPattern());
        }
        for (final InitParam p : s.initParams()) {
            servlet.setInitParameter(p.name(), p.value());
        }
    }

    for (final Filter f : o.filters) {
        final FilterRegistration filter = wac.addFilter(f.filterName(), f.filterClass());

        final Collection<FilterMapping> mappings = o.filterMappings(f.filterName());
        for (final FilterMapping sm : mappings) {
            final String urlPattern = sm.urlPattern();
            final String servletName = sm.servletName();
            if (urlPattern != null) {
                filter.addMappingForUrlPatterns(null, urlPattern);
            } else {
                filter.addMappingForServletNames(null, servletName);
            }

        }
        for (final InitParam p : f.initParams()) {
            filter.setInitParameter(p.name(), p.value());
        }
    }

    wac.deploy(server);

    final URL webXml = this.getClass().getResource("/web.xml");
    logger.error(webXml.toString());

    logger.debug("started grizzly webserver endpoint at " + server.getHttpHandler().getName());
}

From source file:com.moss.bdbadmin.client.service.BdbClient.java

public Category map(IdProof assertion) throws ServiceException {
    try {/*from  w w  w  .  j av a 2 s . c  o  m*/
        OptionsMethod method = new OptionsMethod(baseUrl);
        method.setRequestHeader(AuthenticationHeader.HEADER_NAME, AuthenticationHeader.encode(assertion));

        int result = httpClient.executeMethod(method);
        if (result != 200) {
            throw new ServiceException(result);
        } else {
            Unmarshaller u = context.createUnmarshaller();
            return (Category) u.unmarshal(method.getResponseBodyAsStream());
        }
    } catch (Exception ex) {
        throw new ServiceFailure(ex);
    }
}

From source file:com.moss.bdbadmin.client.service.BdbClient.java

public EntryInfo entryInfo(IdProof assertion, String path) throws ServiceException {
    try {//  w w  w . j av  a2s  . co  m
        OptionsMethod method = new OptionsMethod(baseUrl + "/" + path);
        method.setRequestHeader(AuthenticationHeader.HEADER_NAME, AuthenticationHeader.encode(assertion));

        int result = httpClient.executeMethod(method);
        if (result != 200) {
            throw new ServiceException(result);
        } else {
            Unmarshaller u = context.createUnmarshaller();
            return (EntryInfo) u.unmarshal(method.getResponseBodyAsStream());
        }
    } catch (Exception ex) {
        throw new ServiceFailure(ex);
    }
}

From source file:mx.bigdata.cfdi.CFDv3.java

private Comprobante copy(Comprobante comprobante) throws Exception {
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    dbf.setNamespaceAware(true);/*from  www.j  av  a  2  s .  c  o m*/
    DocumentBuilder db = dbf.newDocumentBuilder();
    Document doc = db.newDocument();
    Marshaller m = CONTEXT.createMarshaller();
    m.marshal(comprobante, doc);
    Unmarshaller u = CONTEXT.createUnmarshaller();
    return (Comprobante) u.unmarshal(doc);
}

From source file:eu.apenet.dpt.standalone.gui.eag2012.Eag2012Frame.java

public void createFrame(InputStream eagStream, boolean isNew) {
    timeMaintenance = null;//from  w w w .j  a  va  2  s.c  om
    personResponsible = null;
    inUse(true);
    addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            inUse(false);
        }
    });
    Eag eag = null;
    try {
        JAXBContext jaxbContext = JAXBContext.newInstance(Eag.class);

        Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
        eag = (Eag) jaxbUnmarshaller.unmarshal(eagStream);
        eagStream.close();
    } catch (Exception e) {
        e.printStackTrace();
    }

    buildPanel(eag, isNew);
    this.getContentPane().add(mainTabbedPane);

    Dimension frameDim = new Dimension(((Double) (dimension.getWidth() * 0.95)).intValue(),
            ((Double) (dimension.getHeight() * 0.95)).intValue());
    this.setSize(frameDim);
    this.setPreferredSize(frameDim);
    this.pack();
    this.setVisible(true);
    this.setExtendedState(JFrame.MAXIMIZED_BOTH);
}