List of usage examples for javax.xml.bind Unmarshaller unmarshal
public Object unmarshal(javax.xml.stream.XMLEventReader reader) throws JAXBException;
From source file:org.jasig.portlet.courses.dao.xml.MockCoursesSectionDao.java
@Override public CoursesByTerm getCoursesByTerm(PortletRequest request, String termCode, TermList termList) { try {/*from www .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()); } 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:it.isislab.sof.core.engine.hadoop.sshclient.connection.SofManager.java
public static boolean checkParamMakeSimulationFolder(String[] params) throws ParameterException { int SIMULATION_PSE_THRESHOLD = 7; //params[0]/*TOOLKIT TYPE MASON - NETLOGO -GENERIC*/, //params[1],/*SIM NAME*/ //params[2],/*INPUT.XML PATH*/ //params[3],/*OUTPUT.XML PATH */ //params[4],/*DESCRIPTION SIM*/ //params[5],/*SIMULATION EXEC PATH */ //params[6] //generic interpreter path /*params[0]MODEL TYPE MASON - NETLOGO -GENERIC, params[1],SIM NAME/*from w ww . ja v a 2s .c om*/ params[2],domain_pathname params[3],bashCommandForRunnableFunctionSelect params[4],bashCommandForRunnableFunctionEvaluate params[5],output_description_filename params[6],executable_selection_function_filename params[7],executable_rating_function_filename params[8],description_simulation params[9],executable_simulation_filename params[10] //generic interpreter path*/ if (!(params[0].equalsIgnoreCase("netlogo") || params[0].equalsIgnoreCase("mason") || params[0].equalsIgnoreCase("generic"))) { throw new ParameterException("TOOLKIT NAME ERROR\n Use: [netlogo|mason|generic]\n"); } JAXBContext context; if (params.length > SIMULATION_PSE_THRESHOLD) { Domain dom = new Domain(); try { context = JAXBContext.newInstance(Domain.class); Unmarshaller unmarshal = context.createUnmarshaller(); dom = (Domain) unmarshal.unmarshal(new File(params[2])); } catch (JAXBException e) { throw new ParameterException("Invalid file DOMAIN.xml\n" + e.getMessage()); } } else { Inputs i = new Inputs(); try { context = JAXBContext.newInstance(Inputs.class); Unmarshaller unmarshal = context.createUnmarshaller(); i = (Inputs) unmarshal.unmarshal(new File(params[2])); } catch (JAXBException e) { throw new ParameterException("Invalid file INPUT.xml"); } } Output out = new Output(); try { context = JAXBContext.newInstance(Output.class); Unmarshaller unmarshal = context.createUnmarshaller(); if (params.length > SIMULATION_PSE_THRESHOLD) out = (Output) unmarshal.unmarshal(new File(params[5])); else out = (Output) unmarshal.unmarshal(new File(params[3])); } catch (JAXBException e) { throw new ParameterException("Invalid file OUTPUT.xml"); } if (params[0].equalsIgnoreCase("netlogo")) if (params.length > SIMULATION_PSE_THRESHOLD) { if (!params[9].endsWith(".nlogo")) throw new ParameterException("Invalid file extension netlogo"); } else { if (!params[5].endsWith(".nlogo")) throw new ParameterException("Invalid file extension netlogo"); } if (params[0].equalsIgnoreCase("mason")) if (params.length > SIMULATION_PSE_THRESHOLD) { if (!params[9].endsWith(".jar")) throw new ParameterException("Invalid file extension mason"); } else { if (!params[5].endsWith(".jar")) throw new ParameterException("Invalid file extension mason"); } return true; }
From source file:mx.bigdata.cfdi.CFDv3.java
private Comprobante load(InputStream source) throws Exception { try {// ww w . j a va 2s .c om Unmarshaller u = CONTEXT.createUnmarshaller(); return (Comprobante) u.unmarshal(source); } finally { source.close(); } }
From source file:org.opennms.opennms.pris.plugins.defaults.source.HttpRequisitionSource.java
@Override public Object dump() throws Exception { Requisition requisition = null;//w ww . j a v a 2 s .c o 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: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. ja va2 s . c o 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 {/* www. ja v a2 s .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); for (Course course : courseByTerm.getCourses()) { if (course.getId().equals(courseId)) { log.debug("Course Found !!!!"); return course; } } return null; }
From source file:com.spend.spendService.MainPage.java
private SearchEngines getSearchEnginesFromXml() { try {/*from ww w.j ava 2 s . com*/ File file = new File("SearchEngines.xml"); JAXBContext jaxbContext = JAXBContext.newInstance(SearchEngines.class); Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); SearchEngines searchEngineList = (SearchEngines) jaxbUnmarshaller.unmarshal(file); return searchEngineList; } catch (JAXBException e) { e.printStackTrace(); } return null; }
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 . 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("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.geosdi.geoplatform.connector.server.request.GPPostConnectorRequest.java
@Override public T getResponse() throws IllegalParameterFault, ServerInternalFault, IOException { T response = null;/*from w w w . j a v a2s . c om*/ try { HttpResponse httpResponse = super.securityConnector.secure(this, this.getPostMethod()); HttpEntity responseEntity = httpResponse.getEntity(); if (responseEntity != null) { InputStream is = responseEntity.getContent(); Unmarshaller unmarshaller = getUnmarshaller(); Object content = unmarshaller.unmarshal(is); if (!(content instanceof JAXBElement)) { // ExceptionReport logger.error("\n#############\n{}\n#############", content); throw new ServerInternalFault("Connector Server Error: incorrect responce"); } JAXBElement<T> elementType = (JAXBElement<T>) content; response = elementType.getValue(); EntityUtils.consume(responseEntity); } else { throw new ServerInternalFault("Connector Server Error: Connection " + "problem"); } } catch (JAXBException ex) { logger.error("\n@@@@@@@@@@@@@@@@@@ JAXBException *** {} ***", ex.getMessage()); throw new ServerInternalFault("*** JAXBException ***" + ex); } catch (ClientProtocolException ex) { logger.error("\n@@@@@@@@@@@@@@@@@@ ClientProtocolException *** {} ***", ex.getMessage()); throw new ServerInternalFault("*** ClientProtocolException ***"); } return response; }