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.jasig.portlet.courses.dao.xml.MockCoursesSectionDao.java

@Override
public List<Course> getFinalExams(PortletRequest request, String termCode, TermList termList) {
    List<Course> courseList = new ArrayList<Course>();
    try {//from  w w w .  j  av a  2  s  .c  o m
        JAXBContext jaxbContext = JAXBContext.newInstance(TermsAndCourses.class);
        Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
        this.summary = (TermsAndCourses) unmarshaller.unmarshal(mockData.getInputStream());
        CoursesByTerm courseByTerm = this.summary.getCoursesByTerm(termCode);
        courseList = courseByTerm.getCourses();
        for (Course course : courseList) {
            for (CourseSection courseSection : course.getCourseSections()) {
                List<CourseMeeting> courseMeetings = new ArrayList<CourseMeeting>();
                for (CourseMeeting courseMeeting : courseSection.getCourseMeetings()) {
                    if (courseMeeting.getType().equals("EXAM")) {
                        courseMeetings.add(courseMeeting);
                    }
                }
                courseSection.getCourseMeetings().clear();
                courseSection.getCourseMeetings().addAll(courseMeetings);
            }
        }

    } catch (IOException e) {
        log.error("Failed to read mock data for CourseByTerm", e);
    } catch (JAXBException e) {
        log.error("Failed to unmarshall mock data for CourseByTerm", e);
    }
    return courseList;

}

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  .  ja v a2 s  .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.jasig.portlet.blackboardvcportlet.dao.ws.impl.GlobalSettingsWSDaoTest.java

private BlackboardGetServerQuotasResponseCollection getServerQuotaMock() throws JAXBException {
    final JAXBContext context = JAXBContext.newInstance(BlackboardGetServerQuotasResponseCollection.class);
    final Unmarshaller unmarshaller = context.createUnmarshaller();
    final BlackboardGetServerQuotasResponseCollection result = (BlackboardGetServerQuotasResponseCollection) unmarshaller
            .unmarshal(this.getClass().getResourceAsStream("/data/serverQuotaResponse.xml"));
    return result;
}

From source file:py.una.pol.karaku.menu.server.MenuServerLogic.java

/**
 * Retorna el men del sistema.//from   w w  w. jav a  2  s.  co m
 * 
 * @return Men del sistema actual
 */
public List<Menu> getCurrentSystemMenu() {

    try {
        Resource resource = new ClassPathResource(util.get(KARAKU_MENU_LOCATION_KEY));
        BufferedReader reader = new BufferedReader(
                new InputStreamReader(resource.getInputStream(), CharEncoding.ISO_8859_1));
        Unmarshaller um = JAXBContext.newInstance(Menu.class).createUnmarshaller();
        Menu m = (Menu) um.unmarshal(reader);
        configMenu(m);
        if (skip(m)) {
            return m.getItems();
        }
        return Arrays.asList(m);
    } catch (UnsupportedEncodingException e) {
        throw new KarakuRuntimeException("Cant open the menu (wrong encoding)", e);
    } catch (IOException e) {
        throw new KarakuRuntimeException("Cant open the menu (file not found)", e);
    } catch (JAXBException e) {
        throw new KarakuRuntimeException("Cant open the menu (wrong XML)", e);
    }
}

From source file:com.geewhiz.pacify.managers.EntityManager.java

private PMarker unmarshal(File file) throws JAXBException {
    Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
    jaxbUnmarshaller.setSchema(schema);/*from w w w .  j  a  v a  2s.  co m*/

    return (PMarker) jaxbUnmarshaller.unmarshal(file);
}

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

private BlackboardGetServerVersionResponseCollection getServerVersionsMock() throws JAXBException {
    final JAXBContext context = JAXBContext.newInstance(BlackboardGetServerVersionResponseCollection.class);
    final Unmarshaller unmarshaller = context.createUnmarshaller();
    final BlackboardGetServerVersionResponseCollection result = (BlackboardGetServerVersionResponseCollection) unmarshaller
            .unmarshal(this.getClass().getResourceAsStream("/data/serverVersionsResponse.xml"));
    return result;
}

From source file:org.javelin.sws.ext.bind.SweJaxbUnmarshallerTest.java

@Test(expected = UnmarshalException.class)
public void unmarshalVeryComplexContent() throws Exception {
    JAXBContext context = JAXBContext.newInstance("org.javelin.sws.ext.bind.context1");
    // ClassWithVeryComplexContent value = new ClassWithVeryComplexContent("test", "str", new ClassWithComplexContent("test", 42, "inside"));
    Unmarshaller um = context.createUnmarshaller();
    InputStream inputStream = new ClassPathResource("very-complex-content-01.xml", this.getClass())
            .getInputStream();/*  w  ww .j  a  v  a 2  s  .co m*/
    um.unmarshal(XMLInputFactory.newFactory().createXMLEventReader(inputStream));
}

From source file:com.moss.error_reporting.server.ReportingServiceImpl.java

public ErrorReport getReport(ReportId id) {
    log.debug("Retrieving report " + id);
    InputStream stream = documentRepository.getStream(id.getUuid());

    log.debug("Stream is " + stream);

    if (stream == null) {
        return null;
    }/*from  w w  w  .  j  av  a  2  s  . co  m*/

    ErrorReport report = null;
    try {
        log.debug("creating unmarshaller");
        Unmarshaller unmarshaller = jaxb.createUnmarshaller();
        log.debug("created it, now using it");
        report = (ErrorReport) unmarshaller.unmarshal(stream);
        stream.close();
        log.debug("report unmarshalled");
    } catch (Exception ex) {
        ex.printStackTrace();
    }

    return report;
}

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

private TimbreFiscalDigital getTimbreFiscalDigital(Comprobante document) throws Exception {
    Comprobante.Complemento comp = document.getComplemento();
    if (comp == null) {
        return null;
    }//from  w  w w  . java  2s  . c o m
    List<Element> list = comp.getAny();
    for (Element e : list) {
        Unmarshaller u = CONTEXT.createUnmarshaller();
        Object o = u.unmarshal(e);
        if (o instanceof TimbreFiscalDigital) {
            return (TimbreFiscalDigital) o;
        }
    }
    return null;
}

From source file:cz.lbenda.dataman.db.ExtConfFactory.java

private void loadExConfType(Reader reader) {
    if (reader == null) {
        loadExConfType((ExConfType) null);
    } else {//from w  w  w. j a v  a  2 s  .  co  m
        try {
            JAXBContext jc = JAXBContext.newInstance(cz.lbenda.dataman.schema.exconf.ObjectFactory.class);
            Unmarshaller u = jc.createUnmarshaller();
            JAXBElement o = (JAXBElement) u.unmarshal(reader);
            if (o.getValue() instanceof ExConfType) {
                loadExConfType((ExConfType) o.getValue());
            } else {
                LOG.error("The file didn't contains expected configuration: " + o.getClass().getName());
            }
        } catch (JAXBException e) {
            LOG.error("Problem with reading extended configuration: " + e.toString(), e);
        }
    }
}