List of usage examples for javax.xml.bind JAXBContext createUnmarshaller
public abstract Unmarshaller createUnmarshaller() throws JAXBException;
From source file:de.tudarmstadt.ukp.integration.alignment.xml.AlignmentXmlReader.java
public AlignmentXmlReader(File inputLocation) throws IOException { fs = null;/* w w w.ja va 2 s . co m*/ try { fs = new FileInputStream(inputLocation); XMLInputFactory xmlInputFactory = XMLInputFactory.newInstance(); xmlEventReader = xmlInputFactory.createXMLEventReader(fs); JAXBContext context; context = JAXBContext.newInstance(XmlMeta.class, Alignments.class); unmarshaller = context.createUnmarshaller(); } catch (JAXBException | XMLStreamException e1) { throw new IOException(e1); } }
From source file:be.fedict.eid.idp.model.bean.AttributeServiceManagerBean.java
@SuppressWarnings("unchecked") public List<IdentityProviderAttributeType> getAttributeServiceTypes() { List<IdentityProviderAttributeType> attributeServices = new LinkedList<IdentityProviderAttributeType>(); ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); Enumeration<URL> resources; try {/* w ww .j a v a2 s . co m*/ resources = classLoader.getResources("META-INF/eid-idp-attribute.xml"); } catch (IOException e) { LOG.error("I/O error: " + e.getMessage(), e); return attributeServices; } Unmarshaller unmarshaller; try { JAXBContext jaxbContext = JAXBContext.newInstance(ObjectFactory.class); unmarshaller = jaxbContext.createUnmarshaller(); } catch (JAXBException e) { LOG.error("JAXB error: " + e.getMessage(), e); return attributeServices; } while (resources.hasMoreElements()) { URL resource = resources.nextElement(); LOG.debug("resource URL: " + resource.toString()); JAXBElement<IdentityProviderAttributesType> jaxbElement; try { jaxbElement = (JAXBElement<IdentityProviderAttributesType>) unmarshaller.unmarshal(resource); } catch (JAXBException e) { LOG.error("JAXB error: " + e.getMessage(), e); continue; } IdentityProviderAttributesType identityProviderAttributes = jaxbElement.getValue(); for (IdentityProviderAttributeType identityProviderAttribute : identityProviderAttributes .getIdentityProviderAttribute()) { attributeServices.add(identityProviderAttribute); } } return attributeServices; }
From source file:com.discogs.api.webservice.impl.HttpClientWebService.java
private Resp createResp(InputStream inputStream) { Resp resp = null;/* w w w. j a v a2 s .c o m*/ try { JAXBContext jaxbContext = JAXBContext.newInstance("com.discogs.api.model"); Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); resp = (Resp) unmarshaller.unmarshal(inputStream); } catch (JAXBException e) { logger.error(e.getMessage()); } return resp; }
From source file:com.castlemock.web.basis.support.FileRepositorySupport.java
public <T> Collection<T> load(Class<T> entityClass, String directory, String postfix) { final Collection<T> loadedTypes = new ArrayList<T>(); final Path path = FileSystems.getDefault().getPath(directory); if (!Files.exists(path)) { try {/*from ww w . j av a2 s. co m*/ LOGGER.debug("Creating the following directory: " + path); Files.createDirectories(path); } catch (IOException e) { LOGGER.error("Unable to create the following directory: " + path, e); throw new IllegalStateException("Unable to create the following folder: " + directory); } } if (!Files.isDirectory(path)) { throw new IllegalStateException("The provided path is not a directory: " + path); } final File folder = new File(directory); try { LOGGER.debug("Start loading files for the following type: " + entityClass.getSimpleName()); for (final File file : folder.listFiles()) { if (file.isFile() && file.getName().endsWith(postfix)) { JAXBContext jaxbContext = JAXBContext.newInstance(entityClass); Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); T type = (T) jaxbUnmarshaller.unmarshal(file); loadedTypes.add(type); LOGGER.debug("\tLoaded " + file.getName()); } } } catch (JAXBException e) { LOGGER.error("Unable to parse files for type " + entityClass.getSimpleName(), e); } return loadedTypes; }
From source file:org.openmrs.module.dhisreport.api.dxf2.DataValueSetTest.java
@Test public void unMarshallDataValueSet() throws Exception { ClassPathResource resource = new ClassPathResource("dvset.xml"); JAXBContext jaxbContext = JAXBContext.newInstance(DataValueSet.class); Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); DataValueSet dvset = (DataValueSet) jaxbUnmarshaller.unmarshal(resource.getInputStream()); assertEquals(5, dvset.getDataValues().size()); }
From source file:org.camelcookbook.rest.binding.BindingModeSpringTest.java
@Test public void testGetOneXml() throws Exception { final Item origItem = getItemService().getItem(0); String out = fluentTemplate().to("undertow:http://localhost:" + port1 + "/items/0/xml") .withHeader(Exchange.HTTP_METHOD, "GET").request(String.class); JAXBContext jaxbContext = JAXBContext.newInstance(Item.class); Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); Item itemOut = (Item) jaxbUnmarshaller.unmarshal(new StringReader(out)); assertEquals(origItem, itemOut);//from w w w. j a va 2 s .c o m }
From source file:be.fedict.eid.idp.model.bean.ProtocolServiceManagerBean.java
@SuppressWarnings("unchecked") public List<IdentityProviderProtocolType> getProtocolServices() { List<IdentityProviderProtocolType> protocolServices = new LinkedList<IdentityProviderProtocolType>(); ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); Enumeration<URL> resources; try {/*ww w .jav a 2 s . c om*/ resources = classLoader.getResources("META-INF/eid-idp-protocol.xml"); } catch (IOException e) { LOG.error("I/O error: " + e.getMessage(), e); return protocolServices; } Unmarshaller unmarshaller; try { JAXBContext jaxbContext = JAXBContext.newInstance(ObjectFactory.class); unmarshaller = jaxbContext.createUnmarshaller(); } catch (JAXBException e) { LOG.error("JAXB error: " + e.getMessage(), e); return protocolServices; } while (resources.hasMoreElements()) { URL resource = resources.nextElement(); LOG.debug("resource URL: " + resource.toString()); JAXBElement<IdentityProviderProtocolsType> jaxbElement; try { jaxbElement = (JAXBElement<IdentityProviderProtocolsType>) unmarshaller.unmarshal(resource); } catch (JAXBException e) { LOG.error("JAXB error: " + e.getMessage(), e); continue; } IdentityProviderProtocolsType identityProviderProtocols = jaxbElement.getValue(); for (IdentityProviderProtocolType identityProviderProtocol : identityProviderProtocols .getIdentityProviderProtocol()) { protocolServices.add(identityProviderProtocol); } } return protocolServices; }
From source file:in.gov.uidai.core.aua.client.OtpClient.java
private OtpRes parseOtpResponseXML(String xmlToParse) throws JAXBException { //Create an XMLReader to use with our filter try {/*from w ww . ja v a2 s .c o m*/ //Prepare JAXB objects JAXBContext jc = JAXBContext.newInstance(OtpRes.class); Unmarshaller u = jc.createUnmarshaller(); XMLReader reader; reader = XMLReaderFactory.createXMLReader(); //Create the filter (to add namespace) and set the xmlReader as its parent. NamespaceFilter inFilter = new NamespaceFilter("http://www.uidai.gov.in/auth/otp/1.6", true); inFilter.setParent(reader); //Prepare the input, in this case a java.io.File (output) InputSource is = new InputSource(new StringReader(xmlToParse)); //Create a SAXSource specifying the filter SAXSource source = new SAXSource(inFilter, is); //Do unmarshalling OtpRes res = u.unmarshal(source, OtpRes.class).getValue(); return res; } catch (Exception e) { e.printStackTrace(); throw new RuntimeException("Erorr while parsing response XML" + e.getMessage()); } }
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 {//w ww . j a v a 2 s . co 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:com.spend.spendService.DomainLearning.java
private SearchEngines getSearchEnginesFromXml() { try {/*from w w 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("DomainLearning.java getSearchEnginesFromXml function ERROR " + ex.getMessage()); ex.printStackTrace(); } return null; }