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

@Override
public CoursesByTerm getCoursesByTerm(PortletRequest request, String termCode, TermList termList) {
    try {/* w  w  w  . j  a  v a  2s.c  om*/
        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 CourseByTerm", e);
    } catch (JAXBException e) {
        log.error("Failed to unmarshall mock data for CourseByTerm", e);
    }
    CoursesByTerm courseByTerm = this.summary.getCoursesByTerm(termCode);
    final List<Course> courses = courseByTerm.getCourses();
    //sort courses
    Collections.sort(courses, new CourseCompareByDeptAndCatalog());
    return courseByTerm;
}

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

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

From source file:org.fcrepo.http.commons.test.util.ContainerWrapper.java

@PostConstruct
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);

    server = createHttpServer(uri);//from  w  w  w .  j  a  v  a2  s .co m

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

    for (final ContextParam p : o.contextParams()) {
        appContext.addContextInitParameter(p.name(), p.value());
    }

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

    for (final Servlet s : o.servlets()) {
        final ServletRegistration servlet = appContext.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 = appContext.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());
        }
    }

    appContext.deploy(server);

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

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

@Override
public Course getCoursesBySection(PortletRequest request, String termCode, String catalogNbr,
        String subjectCode, String courseId, String classNbr, TermList termList) {
    try {//from   ww  w  .  j  a  v  a2  s. co 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 CourseByTerm", e);
    } catch (JAXBException e) {
        log.error("Failed to unmarshall mock data for CourseByTerm", e);
    }
    CoursesByTerm courseByTerm = this.summary.getCoursesByTerm(termCode);
    for (Course course : courseByTerm.getCourses()) {
        if (course.getId().equals(courseId)) {
            log.debug("Course Found !!!!");
            return course;
        }
    }
    return null;
}

From source file:org.opennms.opennms.pris.plugins.defaults.source.HttpRequisitionSource.java

@Override
public Object dump() throws Exception {
    Requisition requisition = null;/*w w  w  .  jav a  2s .  co m*/

    if (getUrl() != null) {
        HttpClientBuilder builder = HttpClientBuilder.create();

        // If username and password was found, inject the credentials
        if (getUserName() != null && getPassword() != null) {

            CredentialsProvider provider = new BasicCredentialsProvider();

            // Create the authentication scope
            AuthScope scope = new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM);

            // Create credential pair
            UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(getUserName(),
                    getPassword());

            // Inject the credentials
            provider.setCredentials(scope, credentials);

            // Set the default credentials provider
            builder.setDefaultCredentialsProvider(provider);
        }

        HttpClient client = builder.build();
        HttpGet request = new HttpGet(getUrl());
        HttpResponse response = client.execute(request);
        try {

            BufferedReader bufferedReader = new BufferedReader(
                    new InputStreamReader(response.getEntity().getContent()));
            JAXBContext jaxbContext = JAXBContext.newInstance(Requisition.class);

            Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
            requisition = (Requisition) jaxbUnmarshaller.unmarshal(bufferedReader);

        } catch (JAXBException e) {
            LOGGER.error("The response did not contain a valid requisition as xml.", e);
        }
        LOGGER.debug("Got Requisition {}", requisition);
    } else {
        LOGGER.error("Parameter requisition.url is missing in requisition.properties");
    }
    if (requisition == null) {
        LOGGER.error("Requisition is null for unknown reasons");
        return null;
    }
    LOGGER.info("HttpRequisitionSource delivered for requisition '{}'", requisition.getNodes().size());
    return requisition;
}

From source file:com.sap.prd.mobile.ios.mios.xcodeprojreader.jaxb.JAXBPlistParser.java

private Plist unmarshallPlist(InputSource project)
        throws SAXException, ParserConfigurationException, JAXBException {
    InputSource dtd = new InputSource(this.getClass().getResourceAsStream("/PropertyList-1.0.dtd"));
    SAXSource ss = createSAXSource(project, dtd);
    JAXBContext ctx = JAXBContext.newInstance(com.sap.prd.mobile.ios.mios.xcodeprojreader.jaxb.JAXBPlist.class);
    Unmarshaller unmarshaller = ctx.createUnmarshaller();

    // unexpected elements should cause an error
    unmarshaller.setEventHandler(new ValidationEventHandler() {
        @Override//w  w  w  .  ja  v a2  s.  com
        public boolean handleEvent(ValidationEvent event) {
            return false;
        }
    });

    return (Plist) unmarshaller.unmarshal(ss);
}

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 av a  2 s  . co  m*/
    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);
}

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

@Override
public List<Course> getClassSchedule(PortletRequest request, String termCode, TermList termList) {
    List<Course> courseList = new ArrayList<Course>();
    try {//from w w  w  . ja va2 s  .  c om
        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("CLASS")) {
                        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:org.jasig.portlet.blackboardvcportlet.dao.ws.impl.SessionWSDaoTest.java

private JAXBElement<BlackboardUrlResponse> mockSessionUrlResponse() throws JAXBException {
    final JAXBContext context = JAXBContext.newInstance("com.elluminate.sas");
    final Unmarshaller unmarshaller = context.createUnmarshaller();
    @SuppressWarnings("unchecked")
    JAXBElement<BlackboardUrlResponse> response = (JAXBElement<BlackboardUrlResponse>) unmarshaller
            .unmarshal(this.getClass().getResourceAsStream("/data/mockSessionCreatorUrl.xml"));

    return response;
}

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  ww. j a v a  2 s.co 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;

}