List of usage examples for javax.xml.bind JAXBContext newInstance
public static JAXBContext newInstance(Class<?>... classesToBeBound) throws JAXBException
From source file:au.id.hazelwood.xmltvguidebuilder.binding.BindingService.java
public BindingService(String contextPath) throws JAXBException { StopWatch stopWatch = new StopWatch(); stopWatch.start();/* ww w. j a v a2s. com*/ JAXBContext jaxbContext = JAXBContext.newInstance(contextPath); marshaller = jaxbContext.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); stopWatch.stop(); LOGGER.debug("BindingService created for {} in {}", contextPath, formatDurationWords(stopWatch.getTime())); }
From source file:mx.bigdata.sat.cfdi.TFDv11.java
private static JAXBContext createContext() { if (CONTEXT == null) { try {//from w w w. j a v a2 s. c o m return JAXBContext.newInstance("mx.bigdata.sat.cfdi.v33.schema"); } catch (JAXBException e) { throw new Error(e); } } return CONTEXT; }
From source file:Main.java
/** * * @param io/* w ww . j av a2 s .c om*/ * @param cls * @return * @throws JAXBException */ public static Object deserialize(InputStream io, Class cls) throws JAXBException { final Unmarshaller um = JAXBContext.newInstance(cls).createUnmarshaller(); return um.unmarshal(io); }
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);// w w w. j a va2 s . co 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:fr.mael.microrss.xml.AtomFeedParser.java
@Override public List<Article> readArticles(Feed feed) throws Exception { List<Article> articles = new ArrayList<Article>(); JAXBContext jc = JAXBContext.newInstance("fr.mael.microrss.xml.atom"); Unmarshaller unmarshaller = jc.createUnmarshaller(); HttpGet get = new HttpGet(feed.getUrl()); HttpResponse response = client.execute(get); try {/* ww w.j a v a2s. c o m*/ Object o = unmarshaller.unmarshal(response.getEntity().getContent()); if (o instanceof JAXBElement) { JAXBElement element = (JAXBElement) o; FeedType feedType = (FeedType) element.getValue(); articles = readEntries(feedType.getAuthorOrCategoryOrContributor(), feed, feedType); } return articles; } catch (Exception e) { EntityUtils.consume(response.getEntity()); throw new Exception(e); } }
From source file:org.jasig.portlet.campuslife.dao.MockDataService.java
@Override public void afterPropertiesSet() throws Exception { try {//from www. j a va 2s . c o m JAXBContext jaxbContext = JAXBContext.newInstance(getPackageName()); Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); this.data = (T) unmarshaller.unmarshal(feed.getInputStream()); } 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:gov.nih.nci.cabig.caaers.web.rule.ContextListener.java
private RuleUi load(String fileName) { InputStream inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(fileName); try {//from www. j a va 2 s . com Unmarshaller unmarshaller = JAXBContext.newInstance("com.semanticbits.rules.ui").createUnmarshaller(); RuleUi ruleUi = (RuleUi) unmarshaller.unmarshal(inputStream); return ruleUi; } catch (JAXBException e) { throw new CaaersSystemException(e.getMessage(), e); } finally { IOUtils.closeQuietly(inputStream); } }
From source file:cz.muni.fi.editor.typemanager.TypeServiceImpl.java
public TypeServiceImpl() throws JAXBException { JAXBContext context = JAXBContext.newInstance(Type.class); this.unmarshaller = context.createUnmarshaller(); this.marshaller = context.createMarshaller(); this.marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); }
From source file:org.mule.module.apikit.leagues.Teams.java
@Transformer(resultMimeType = "text/xml") public String toXml(Teams teams) throws IOException, JAXBException { JAXBContext context = JAXBContext.newInstance(getClass()); Marshaller m = context.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); ByteArrayOutputStream boas = new ByteArrayOutputStream(); m.marshal(teams, boas);//from w ww .ja va 2 s . c o m return new String(boas.toByteArray()); }
From source file:org.javelin.sws.ext.bind.SweJaxbContextFactoryTest.java
@Test(expected = JAXBException.class) public void defaultPackageForJaxbRi() throws Exception { JAXBContext.newInstance(""); }