List of usage examples for javax.xml.bind Unmarshaller unmarshal
public Object unmarshal(javax.xml.stream.XMLEventReader reader) throws JAXBException;
From source file:com.moss.veracity.core.config.ConfigManager.java
private Configuration read() throws Exception { if (file.exists()) { if (log.isDebugEnabled()) { log.debug("Reading configuration: " + file); }/*from w ww .jav a 2 s . co m*/ Unmarshaller u = jaxbContext.createUnmarshaller(); return (Configuration) u.unmarshal(file); } else { if (log.isDebugEnabled()) { log.debug("Configuration file missing, creating default configuration: " + file); } Configuration config = new Configuration(); write(config); return config; } }
From source file:ch.windmobile.server.file.FileDataSource.java
public List<StationData> getStationDataList(boolean allStation) throws DataSourceException { try {//w ww . j a v a 2 s . c o m Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); StationDatas stationDatas = (StationDatas) unmarshaller .unmarshal(getStationDatasResource().getInputStream()); return stationDatas.getStationDatas(); } catch (Exception e) { throw new DataSourceException(DataSourceException.Error.INVALID_DATA, "Unable to parse the test data", e); } }
From source file:com.codercowboy.photo.organizer.service.LibraryMarshaller.java
public Library loadLibrary(String fileName) throws Exception { byte[] fileData = FileUtils.readFileToByteArray(new File(fileName)); ByteArrayInputStream bais = new ByteArrayInputStream(fileData); try {/*w w w . ja va 2 s. c om*/ Unmarshaller unmarshaller = this.createContext().createUnmarshaller(); @SuppressWarnings("unchecked") JAXBElement<Library> jaxbElement = (JAXBElement<Library>) unmarshaller.unmarshal(bais); return jaxbElement.getValue(); } finally { bais.close(); } }
From source file:it.iit.genomics.cru.structures.bridges.eppic.client.EppicJaxbClient.java
private EppicAnalysisList getPdbInterfaces(String fileName) { try {//w ww .ja v a2s. c o m XMLInputFactory xmlif = XMLInputFactory.newInstance(); XMLStreamReader xmler = xmlif.createXMLStreamReader(new FileReader(fileName)); JAXBContext jaxbContext = JAXBContext.newInstance(EppicAnalysisList.class); Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); EppicAnalysisList result; result = (EppicAnalysisList) jaxbUnmarshaller.unmarshal(xmler); return result; } catch (JAXBException | IOException | XMLStreamException e) { logger.error(null, e); } return null; }
From source file:ch.windmobile.server.file.FileDataSource.java
@Override public List<StationInfo> getStationInfoList(boolean allStation) throws DataSourceException { try {/* ww w.j av a 2s . c o m*/ Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); StationInfos stationInfos = (StationInfos) unmarshaller .unmarshal(getStationInfosResource().getInputStream()); return stationInfos.getStationInfos(); } catch (Exception e) { throw new DataSourceException(DataSourceException.Error.INVALID_DATA, "Unable to parse the test data", e); } }
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);// w w w. ja v a2s . com }
From source file:com.quangphuong.crawler.util.XMLUtil.java
public <T> T unmarshallUtil(String xmlPath, Class<T> entityClass) throws Exception { // try { JAXBContext cxt = JAXBContext.newInstance(entityClass); Unmarshaller unmarshaller = cxt.createUnmarshaller(); File file = new File(rootPath, xmlPath); T result = (T) unmarshaller.unmarshal(file); return result; // } catch (Exception e) { // e.printStackTrace(); // }//www . ja va 2s . co m // return null; }
From source file:edu.usc.goffish.gopher.impl.client.DeploymentTool.java
public void setup(String gofsConfig, String managerHost, String coordinatorHost, boolean persist) throws IOException, ConfigurationException { int numberOfProcessors = 0; PropertiesConfiguration gofs = new PropertiesConfiguration(gofsConfig); gofs.load();//ww w. j a v a 2 s . c om String nameNodeRestAPI = gofs.getString(GoFSFormat.GOFS_NAMENODE_LOCATION_KEY); INameNode nameNode = new RemoteNameNode(URI.create(nameNodeRestAPI)); numberOfProcessors = nameNode.getDataNodes().size(); // generate flow graph. FloeGraphGenerator generator = new FloeGraphGenerator(); OMElement xmlOm = generator.createFloe(numberOfProcessors); xmlOm.build(); try { JAXBContext ctx = JAXBContext.newInstance(FloeGraph.class); Unmarshaller um = ctx.createUnmarshaller(); FloeGraph floe = (FloeGraph) um.unmarshal(xmlOm.getXMLStreamReader()); if (persist) { FileOutputStream fileOutputStream = new FileOutputStream(new File(FLOE_GRAPH_PATH)); ctx.createMarshaller().marshal(floe, fileOutputStream); } DefaultClientConfig config = new DefaultClientConfig(); config.getProperties().put(ClientConfig.FEATURE_DISABLE_XML_SECURITY, true); config.getFeatures().put(ClientConfig.FEATURE_DISABLE_XML_SECURITY, true); Client c = Client.create(config); WebResource r = c .resource("http://" + coordinatorHost + ":" + COORDINATOR_PORT + "/Coordinator/createFloe"); c.getProperties().put(ClientConfig.PROPERTY_FOLLOW_REDIRECTS, true); ClientResponse response; c.getProperties().put(ClientConfig.PROPERTY_FOLLOW_REDIRECTS, true); response = r.post(ClientResponse.class, floe); StartFloeInfo startFloeInfo = response.getEntity(StartFloeInfo.class); createClientConfig(startFloeInfo, managerHost, coordinatorHost); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:org.jasig.portlet.degreeprogress.dao.mock.MockDegreeProgressDaoImpl.java
@Override public void afterPropertiesSet() throws Exception { try {/* w w w . j a v a 2s. c om*/ JAXBContext jaxbContext = JAXBContext .newInstance(org.jasig.portlet.degreeprogress.model.xml.DegreeProgressReport.class); Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); this.report = (DegreeProgressReport) unmarshaller.unmarshal(mockData.getInputStream()); for (DegreeRequirementSection section : report.getDegreeRequirementSections()) { for (JAXBElement<? extends GeneralRequirementType> requirement : section.getGeneralRequirements()) { GeneralRequirementType req = requirement.getValue(); if (req instanceof GpaRequirement) { section.setRequiredGpa(((GpaRequirement) req).getRequiredGpa()); } } for (CourseRequirement req : section.getCourseRequirements()) { for (Course course : req.getCourses()) { StudentCourseRegistration registration = new StudentCourseRegistration(); registration.setCredits(course.getCredits()); registration.setSource(course.getSource()); registration.setSemester(course.getSemester()); registration.setCourse(course); Grade grade = new Grade(); grade.setCode(course.getGrade().getCode()); registration.setGrade(grade); req.getRegistrations().add(registration); } } this.report.addSection(section); } } catch (IOException e) { log.error("Failed to read mock data", e); } catch (JAXBException e) { log.error("Failed to unmarshall mock data", e); } }
From source file:cz.cas.lib.proarc.common.export.mets.MetsUtils.java
/** * * Reads and unmarshalls Digital Object/*from w w w . j a v a 2 s .c om*/ * * @param path * @return */ public static DigitalObject readFoXML(String path) throws MetsExportException { DigitalObject foXMLObject; File file = new File(path); try { JAXBContext jaxbContext = JAXBContext.newInstance(DigitalObject.class); Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); foXMLObject = (DigitalObject) unmarshaller.unmarshal(file); return foXMLObject; } catch (JAXBException e) { throw new MetsExportException("Unable to read FoXML document " + path, false, e); } }