List of usage examples for javax.xml.bind Unmarshaller unmarshal
public <T> JAXBElement<T> unmarshal(javax.xml.stream.XMLEventReader reader, Class<T> declaredType) throws JAXBException;
From source file:se.inera.intyg.intygstjanst.web.service.impl.CertificateSenderServiceImplTest.java
public RegisterMedicalCertificateType request() throws IOException, JAXBException { Unmarshaller unmarshaller = JAXBContext.newInstance(RegisterMedicalCertificateResponseType.class) .createUnmarshaller();// w w w . j av a 2 s .c om return unmarshaller.unmarshal( new StreamSource( new ClassPathResource("CertificateSenderServiceImplTest/utlatande.xml").getInputStream()), RegisterMedicalCertificateType.class).getValue(); }
From source file:esg.node.components.registry.ShardsListGleaner.java
public synchronized ShardsListGleaner loadMyShardsWhitelist() { log.info("Loading my SHARDS Whitelist info from " + shardsListPath + shardsListFile); try {/* ww w.java2s.c o m*/ JAXBContext jc = JAXBContext.newInstance(Shards.class); Unmarshaller u = jc.createUnmarshaller(); JAXBElement<Shards> root = u.unmarshal(new StreamSource(new File(shardsListPath + shardsListFile)), Shards.class); shardlist = root.getValue(); } catch (Exception e) { log.error(e); } return this; }
From source file:esg.node.components.registry.ShardsListGleaner.java
public Shards createShardsWhitelistFromString(String shardsListContentString) { log.info("Loading my SHARDS info from \n" + shardsListContentString + "\n"); Shards fromContentShardsList = null; try {//ww w . j a v a2 s . com JAXBContext jc = JAXBContext.newInstance(Shards.class); Unmarshaller u = jc.createUnmarshaller(); JAXBElement<Shards> root = u.unmarshal(new StreamSource(new StringReader(shardsListContentString)), Shards.class); fromContentShardsList = root.getValue(); } catch (Exception e) { log.error(e); } return fromContentShardsList; }
From source file:org.javelin.sws.ext.bind.SweJaxbUnmarshallerTest.java
@Test public void unmarshalVeryComplexContentExplicit() throws Exception { JAXBContext context = JAXBContext.newInstance("org.javelin.sws.ext.bind.context1"); // ClassWithVeryComplexContent value = new ClassWithVeryComplexContent("test", "str", new ClassWithComplexContent("test", 42, "inside")); Unmarshaller um = context.createUnmarshaller(); InputStream inputStream = new ClassPathResource("very-complex-content-01.xml", this.getClass()) .getInputStream();/*from w ww. j ava2 s .c o m*/ JAXBElement<ClassWithVeryComplexContent> je = um.unmarshal( XMLInputFactory.newFactory().createXMLEventReader(inputStream), ClassWithVeryComplexContent.class); assertTrue(je.getDeclaredType() == ClassWithVeryComplexContent.class); assertFalse("Should not be nil", je.isNil()); assertTrue(je.getValue() instanceof ClassWithVeryComplexContent); ClassWithVeryComplexContent ob = (ClassWithVeryComplexContent) je.getValue(); assertThat(ob.getStr(), equalTo("test-1")); assertThat(ob.getInside(), equalTo("str")); assertThat(ob.getInside2().getNumber(), equalTo(42)); assertThat(ob.getInside2().getStr(), equalTo("test-2")); assertThat(ob.getInside2().getInside(), equalTo("inside")); }
From source file:edu.wisc.cypress.dm.CypressJaxbTest.java
private <T> T unmarshall(String resource, Class<T> clazz) throws Exception { final JAXBContext context = JAXBContext.newInstance(clazz.getPackage().getName()); final Unmarshaller unmarshaller = context.createUnmarshaller(); final InputStream xmlStream = this.getClass().getResourceAsStream(resource); try {//from w ww .j ava 2 s . co m assertNotNull(xmlStream); final JAXBElement<T> statements = unmarshaller.unmarshal(new StreamSource(xmlStream), clazz); return statements.getValue(); } finally { IOUtils.closeQuietly(xmlStream); } }
From source file:esg.node.components.registry.AtsWhitelistGleaner.java
public synchronized AtsWhitelistGleaner loadMyAtsWhitelist() { log.info("Loading my ATS Whitelist info from " + atsWhitelistPath + atsWhitelistFile); try {/* www . j a v a 2s . c om*/ JAXBContext jc = JAXBContext.newInstance(AtsWhitelist.class); Unmarshaller u = jc.createUnmarshaller(); JAXBElement<AtsWhitelist> root = u .unmarshal(new StreamSource(new File(atsWhitelistPath + atsWhitelistFile)), AtsWhitelist.class); atss = root.getValue(); } catch (Exception e) { log.error(e); } return this; }
From source file:esg.node.components.registry.AtsWhitelistGleaner.java
public AtsWhitelist createAtsWhitelistFromString(String atsWhitelistContentString) { log.info("Loading my ATS Whitelist info from \n" + atsWhitelistContentString + "\n"); AtsWhitelist fromContentAtsWhitelist = null; try {// w w w . j a va 2s . c o m JAXBContext jc = JAXBContext.newInstance(AtsWhitelist.class); Unmarshaller u = jc.createUnmarshaller(); JAXBElement<AtsWhitelist> root = u .unmarshal(new StreamSource(new StringReader(atsWhitelistContentString)), AtsWhitelist.class); fromContentAtsWhitelist = root.getValue(); } catch (Exception e) { log.error(e); } return fromContentAtsWhitelist; }
From source file:org.apache.taverna.scufl2.translator.t2flow.defaultactivities.AbstractActivityParser.java
public <ConfigType> ConfigType unmarshallElement(T2FlowParser t2FlowParser, Element element, Class<ConfigType> configType) throws ReaderException { Unmarshaller unmarshaller2 = t2FlowParser.getUnmarshaller(); unmarshaller2.setSchema(null);/* ww w . ja v a2s .c o m*/ try { JAXBElement<ConfigType> configElemElem = unmarshaller2.unmarshal(element, configType); return configElemElem.getValue(); } catch (JAXBException | ClassCastException e) { throw new ReaderException("Can't parse element " + element, e); } }