List of usage examples for javax.xml.bind JAXBContext createUnmarshaller
public abstract Unmarshaller createUnmarshaller() throws JAXBException;
From source file:com.healthcit.cacure.businessdelegates.export.DataImporterTest.java
@Test public void testConstructFormXML() throws JAXBException { assertNotNull(dataImporter);/*from w w w.j ava 2 s . co m*/ JAXBContext jc = JAXBContext.newInstance("com.healthcit.cacure.export.model"); Unmarshaller m = jc.createUnmarshaller(); //String formId = "9712"; //String formId = "9724"; String formId = "9731"; //long formId = 9833; long moduleId = 9750; String fileName = "C:\\temp\\cure-" + formId + ".xml"; //Cure xml = dataExport.constructFormXML(9712l); //Cure xml = dataExport.constructFormXML(9724); //m.marshal(xml, new File("C:\\temp\\caure-9724.xml")); //m.unmarshal( new File("C:\\temp\\caure-9731.xml")); Module module = (Module) moduleManager.getModule(moduleId); List<BaseForm> forms = module.getForms(); int lastFormIndex = 0; if (forms != null) { lastFormIndex = forms.size(); } Cure cure = (Cure) m.unmarshal(new File(fileName)); dataImporter.importData(cure, module, lastFormIndex + 1); }
From source file:org.openmrs.module.dhisreport.api.model.ReportTemplatesTest.java
@Test public void unMarshallReportTemplates() throws Exception { ClassPathResource resource = new ClassPathResource("templates_ethiopia.xml"); JAXBContext jaxbContext = JAXBContext.newInstance(ReportTemplates.class); Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); ReportTemplates reportTemplates = (ReportTemplates) jaxbUnmarshaller.unmarshal(resource.getInputStream()); assertNotNull(reportTemplates);//from www. ja va 2 s . c o m List<ReportDefinition> reportDefinitions = reportTemplates.getReportDefinitions(); assertEquals(2, reportDefinitions.size()); for (ReportDefinition rd : reportDefinitions) { for (DataValueTemplate dvt : rd.getDataValueTemplates()) { assertNotNull(dvt.getDataelement()); assertNotNull(dvt.getDataelement().getCode()); assertNotNull(dvt.getDataelement().getName()); assertNotNull(dvt.getDataelement().getUid()); assertNotNull(dvt.getDisaggregation()); assertNotNull(dvt.getDisaggregation().getCode()); assertNotNull(dvt.getDisaggregation().getName()); assertNotNull(dvt.getDisaggregation().getUid()); } } }
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(); // }/* w ww . ja v a2s . c om*/ // return null; }
From source file:at.ac.tuwien.dsg.cloud.utilities.messaging.discovery.LightweightSalsaDiscovery.java
public String discoverHost(String serviceName) { try {// w w w . j a v a2s . co m URI statusUri = UriBuilder.fromPath(restCommand).build(serviceName); HttpGet method = new HttpGet(statusUri); HttpHost host = new HttpHost(this.config.getIp(), this.config.getPort()); HttpClient client = new DefaultHttpClient(); HttpResponse response = client.execute(host, method); if (response.getStatusLine().getStatusCode() == 200) { try { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); response.getEntity().writeTo(outputStream); String serviceDescription = new String(outputStream.toByteArray()); JAXBContext a = JAXBContext.newInstance(DeploymentDescription.class); Unmarshaller u = a.createUnmarshaller(); if (!serviceDescription.equalsIgnoreCase("")) { Object object = u.unmarshal(new StringReader(serviceDescription)); DeploymentDescription deploymentInfo = (DeploymentDescription) object; for (DeploymentUnit unit : deploymentInfo.getDeployments()) { if (unit.getServiceUnitID().contains("RabbitServer")) { return unit.getAssociatedVM().get(0).getIp(); } } } } catch (JAXBException e) { //todo: log } } } catch (IOException ex) { //todo: log } return null; }
From source file:org.apache.falcon.regression.core.response.ServiceResponse.java
/** * Retrieves EntitySummaryResult from a message if possible. * @return EntitiesResult/* w ww .j a v a 2 s . c om*/ */ public EntitySummaryResult getEntitySummaryResult() { try { JAXBContext jc = JAXBContext.newInstance(EntitySummaryResult.class); Unmarshaller u = jc.createUnmarshaller(); return (EntitySummaryResult) u.unmarshal(new StringReader(message)); } catch (JAXBException e) { LOGGER.info("getEntitySummaryResult() failed:\n" + ExceptionUtils.getStackTrace(e)); return null; } }
From source file:com.iata.ndc.trial.controllers.DefaultController.java
@RequestMapping(method = RequestMethod.GET) public String index(ModelMap map) throws JAXBException, ClientProtocolException, ClientException, IOException { ClassLoader classLoader = getClass().getClassLoader(); File file = new File(classLoader.getResource("AirShopping.xml").getFile()); JAXBContext jaxbContext = JAXBContext.newInstance(AirShoppingRQ.class); Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); AirShoppingRQ request = (AirShoppingRQ) jaxbUnmarshaller.unmarshal(file); NdcClient client = new NdcClient("http://iata.api.mashery.com/athena/api", "jhttds6eh5bgq92zvqnruehx"); List<FlightConnection> response = new AirShoppingResonseMapper() .mapAirShoppingResponse(client.airShopping(request)); return "index"; }
From source file:com.spend.spendService.SearchText.java
private SearchEngines getSearchEnginesFromXml() { try {/*ww w . ja v a 2 s . c o m*/ 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 ex) { System.out.println("SearchText.java getSearchEnginesFromXml function ERROR " + ex.getMessage()); ex.printStackTrace(); } return null; }
From source file:com.github.haixing_hu.ilibrary.service.impl.DocumentTemplateServiceImpl.java
public DocumentTemplateServiceImpl(final String resourcePattern) { logger = LoggerFactory.getLogger(DocumentTemplateServiceImpl.class); templates = new HashMap<String, DocumentTemplate>(); // load all the field templates final PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(); try {//from w w w .j a v a 2 s . c om final JAXBContext context = JAXBContext.newInstance(DocumentTemplate.class); final Unmarshaller unmarshaller = context.createUnmarshaller(); final Resource[] resources = resolver.getResources(resourcePattern); for (final Resource resource : resources) { final InputStream is = resource.getInputStream(); final DocumentTemplate document = (DocumentTemplate) unmarshaller.unmarshal(is); final String name = document.getName(); logger.info("Adds a document template: {}", name); templates.put(name, document); } } catch (final Exception e) { logger.error("Failed to load the document templates from: {}", resourcePattern, e); throw new RuntimeException(e); } }
From source file:fish.payara.examples.jdays2016.springboot.DataLoaderServiceImpl.java
@Override public long parseFile(File file) { JAXBContext jc; int count = 0; try {// ww w. j a v a 2s . co m jc = JAXBContext.newInstance("fish.payara.examples.jdays2016.jaxb"); Unmarshaller um = jc.createUnmarshaller(); HaPlannedRoadworks rw = (HaPlannedRoadworks) um.unmarshal(file); for (HaPlannedRoadworks.HaPlannedWorks works : rw.getHaPlannedWorks()) { PlannedWorks pw = new PlannedWorks(works); repo.save(pw); count++; } } catch (JAXBException ex) { Logger.getLogger(DataLoaderServlet.class.getName()).log(Level.SEVERE, null, ex); } return count; }
From source file:gov.nih.nci.cacis.sa.mirthconnect.SemanticAdapterChannelIntegrationTest.java
/** * This test calls out acceptSource(..) operation on SematicAdapter WS. * and expects the service to return an Exception * * @throws Exception exception// w w w. j a v a 2 s . c o m */ //ToDo Remove ignore after CDO-1257 @Ignore @Test(expected = AcceptSourceFault.class) public void failure() throws Exception { //NOPMD final JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean(); factory.setServiceClass(AcceptSourcePortType.class); factory.setAddress(ADDRESS); final AcceptSourcePortType client = (AcceptSourcePortType) factory.create(); final InputStream sampleMessageIS = FileUtils .openInputStream(new File(getClass().getClassLoader().getResource("SARequestSample.xml").toURI())); final JAXBContext jc = JAXBContext.newInstance(CaCISRequest.class); final CaCISRequest request = (CaCISRequest) jc.createUnmarshaller().unmarshal(sampleMessageIS); client.acceptSource(request); }