List of usage examples for javax.xml.bind JAXBContext createUnmarshaller
public abstract Unmarshaller createUnmarshaller() throws JAXBException;
From source file:ait.ffma.service.preservation.riskmanagement.api.riskanalysis.risk.RiskUtils.java
/** * This method initializes a set of risk properties loaded from XML file. * /*w ww . j a v a 2s .com*/ * @param xmlFile * The XML file containing properties definitions * @return property set in risk analysis format */ public static RiskAnalysis loadRiskPropertiesFromXML(String xmlFile) { try { JAXBContext jc = JAXBContext.newInstance(RiskAnalysis.class); Unmarshaller u = jc.createUnmarshaller(); InputStream in = RiskUtils.class.getResourceAsStream(xmlFile); ra = (RiskAnalysis) u.unmarshal(in); } catch (JAXBException e) { LOG.log(Level.SEVERE, e.getMessage()); return null; } // resetProperties(ra.getRiskFactors()); return ra; }
From source file:com.wso2telco.core.config.ConfigLoader.java
/** * Inits the m connect config.// ww w . java 2 s. c om * * @return the mobile connect config * @throws JAXBException the JAXB exception */ private MobileConnectConfig initMConnectConfig() throws JAXBException { String configPath = CarbonUtils.getCarbonConfigDirPath() + File.separator + "mobile-connect.xml"; File file = new File(configPath); JAXBContext ctx = JAXBContext.newInstance(MobileConnectConfig.class); Unmarshaller um = ctx.createUnmarshaller(); return (MobileConnectConfig) um.unmarshal(file); }
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 w w . ja va 2 s . com 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.openmrs.module.dhisreport.api.model.ReportTemplatesTest.java
@Test public void marshallReportTemplates() 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()); Collection<DataValueTemplate> dvts = reportTemplates.getReportDefinitions().get(1).getDataValueTemplates(); for (DataValueTemplate dvt : dvts) { dvt.setQuery("select count(*) from something & something_else"); }//from w w w . j a va2 s. c o m Marshaller jaxbmarshaller = jaxbContext.createMarshaller(); jaxbmarshaller.marshal(reportTemplates, System.out); }
From source file:org.openregistry.core.repository.xml.XmlBasedDisclosureRecalculationStrategyRepositoryImpl.java
public XmlBasedDisclosureRecalculationStrategyRepositoryImpl(final Resource resource) throws JAXBException, IOException { File disclosureCalculationStrategyFile = resource.getFile(); JAXBContext jaxbContext = JAXBContext.newInstance(XmlBasedDisclosureRecalculationStrategyImpl.class); Unmarshaller unMarshaller = jaxbContext.createUnmarshaller(); logger.info("Attempting to load Xml Disclosure recalculation strategy spec from [" + disclosureCalculationStrategyFile.getAbsolutePath() + "]"); Assert.isTrue(disclosureCalculationStrategyFile.isFile() && disclosureCalculationStrategyFile.canRead() && disclosureCalculationStrategyFile.getName().endsWith(".xml")); final FileReader fileReader = new FileReader(disclosureCalculationStrategyFile); disclosureRecalcualationStrategy = (DisclosureRecalculationStrategy) unMarshaller.unmarshal(fileReader); logger.info("Loaded Xml Disclosure recalculation strategy spec with name [" + disclosureRecalcualationStrategy.getName() + "] description [" + disclosureRecalcualationStrategy.getDescription() + "]"); }
From source file:org.apache.falcon.regression.core.response.ServiceResponse.java
/** * Retrieves EntitiesResult from a message if possible. * @return EntitiesResult// w w w. j av a 2 s . co m */ public EntityList getEntityList() { try { JAXBContext jc = JAXBContext.newInstance(EntityList.class); Unmarshaller u = jc.createUnmarshaller(); return (EntityList) u.unmarshal(new StringReader(message)); } catch (JAXBException e) { LOGGER.info("getEntityList() failed:\n" + ExceptionUtils.getStackTrace(e)); return null; } }
From source file:ait.ffma.service.preservation.riskmanagement.api.riskanalysis.risk.RiskUtils.java
/** * This method returns risk analysis object. * @return/* w w w. j a va 2 s . c o m*/ */ public static RiskAnalysis loadRiskAnalysis() { if (RiskUtils.ra == null || RiskUtils.getGeneralProperty("RiskAnalysis.ReloadXML").equalsIgnoreCase("true")) { try { JAXBContext jc = JAXBContext.newInstance(RiskAnalysis.class); Unmarshaller u = jc.createUnmarshaller(); InputStream in = RiskUtils.class .getResourceAsStream(RiskUtils.getGeneralProperty("Riskanalysis.XML")); ra = (RiskAnalysis) u.unmarshal(in); } catch (JAXBException e) { LOG.log(Level.SEVERE, e.getMessage()); return null; } RiskUtils.setGeneralProperty("RiskAnalysis.ReloadXML", "false"); } resetProperties(ra.getRiskFactors()); return ra; }
From source file:nl.stil4m.ideal.executor.RequestExecutor.java
public <T extends Response> T execute(IdealRequest<T> request) throws FailedRequestException { try {/* www .ja va 2 s .c o m*/ HttpGet get = buildHttpRequest(request); HttpResponse httpResponse = httpClient.execute(get); JAXBContext jaxbContext = JAXBContext.newInstance(request.getResponseClass()); Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); T response = (T) jaxbUnmarshaller.unmarshal(httpResponse.getEntity().getContent()); if (!response.succeeded()) { throw new FailedRequestException(request, response); } return response; } catch (IOException | JAXBException | URISyntaxException e) { throw new RequestExecutorException(e); } }
From source file:com.googlecode.refit.runner.TreeRunnerTest.java
public void checkXmlReport(File xmlReport) throws JAXBException { assertTrue(xmlReport.exists());/*from www . j a v a 2s . c o m*/ JAXBContext ctx = JAXBContext.newInstance(ReportIO.CONTEXT_PATH); Unmarshaller unmarshaller = ctx.createUnmarshaller(); @SuppressWarnings("unchecked") JAXBElement<Summary> root = (JAXBElement<Summary>) unmarshaller.unmarshal(xmlReport); Summary summary = root.getValue(); assertTrue(summary.getInputDir().endsWith("src/test/fit")); assertTrue(summary.getOutputDir().endsWith("target/fit")); assertEquals(1, summary.getExceptions()); assertEquals(0, summary.getIgnored()); assertEquals(10, summary.getWrong()); assertEquals(339, summary.getRight()); assertEquals(4, summary.getNumTests()); List<TestResult> results = summary.getTest(); checkResult(results.get(0), 0, 0, 0, 95, true, "MusicExample.html"); checkResult(results.get(1), 1, 0, 0, 95, false, "MusicExampleWithErrors.html"); checkResult(results.get(2), 0, 0, 10, 54, false, "MusicExampleWithFailures.html"); checkResult(results.get(3), 0, 0, 0, 95, true, "subdir/MusicExample.html"); }
From source file:gov.nih.nci.cacis.sa.mirthconnect.SemanticAdapterChannelIntegrationTest.java
/** * This test calls out acceptSource(..) operation on SematicAdapter WS. * The SemanticAdapter WS is the source connector to SemanticAdapterChannel in Mirth. * @throws Exception exception/* w ww. ja va 2 s .c o m*/ */ @Test public void invokeSemanticAdapterWS() 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 Unmarshaller unm = jc.createUnmarshaller(); final CaCISRequest request = (CaCISRequest) unm.unmarshal(sampleMessageIS); final Marshaller m = jc.createMarshaller(); final StringWriter sw = new StringWriter(); final PrintWriter pw = new PrintWriter(sw); m.marshal(request, pw); final String reqStr = sw.toString(); final CaCISResponse response = client.acceptSource(request); assertTrue(response.getStatus() == ResponseStatusType.SUCCESS); }