List of usage examples for javax.xml.bind JAXBContext createUnmarshaller
public abstract Unmarshaller createUnmarshaller() throws JAXBException;
From source file:att.jaxrs.util.Marshal.java
public static <T> T unmarshal(Class<T> xmlType, HttpResponse httpResponse) throws JAXBException { String namespace = ""; try {/*w w w.jav a 2 s .c o m*/ namespace = Util.getStringFromInputStream(httpResponse.getEntity().getContent()); System.out.println(namespace); } catch (IOException e) { System.out.println(e.getMessage()); } System.out.println(namespace); namespace = namespace.replaceAll(Constants.DATA_SERVICE_XMLNS, ""); System.out.println(namespace); InputStream stream = Util.getInputStreamFromString(namespace); JAXBContext jaxbContext = JAXBContext.newInstance(xmlType); Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); return (T) unmarshaller.unmarshal(stream); }
From source file:eurecom.common.util.WSUtils.java
/** * Read an XML file and transforms XML data into RDF data * @param file//from www . j ava 2 s. co m * @return * @throws JAXBException * @throws FileNotFoundException */ public static Measurements readXMLFile(String file) throws JAXBException, FileNotFoundException { JAXBContext context = JAXBContext.newInstance(Measurements.class); Unmarshaller um = context.createUnmarshaller(); Measurements measurement = (Measurements) um.unmarshal(new FileReader(file)); return measurement; }
From source file:com.esri.geoevent.test.performance.OrchestratorMain.java
private static Fixtures fromXML(String xmlLocation) throws JAXBException { JAXBContext jaxbContext = JAXBContext.newInstance(Fixtures.class); Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); StreamSource xml = new StreamSource(xmlLocation); return (Fixtures) unmarshaller.unmarshal(xml); }
From source file:de.hybris.platform.b2b.punchout.PunchOutUtils.java
public static CXML unmarshallCXMLFromFile(final String relativeFilePath) throws FileNotFoundException { final InputStream fileInputStream = PunchOutUtils.class.getClassLoader() .getResourceAsStream(relativeFilePath); if (fileInputStream == null) { throw new FileNotFoundException("Could not find file [" + relativeFilePath + "]"); }//from w w w .j av a 2 s .c o m try { final JAXBContext jaxbContext = JAXBContext.newInstance(CXML.class); final Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); return (CXML) unmarshaller.unmarshal(fileInputStream); } catch (final JAXBException e) { throw new PunchOutException(e.getErrorCode(), e.getMessage()); } }
From source file:edu.cwru.sepia.Main.java
private static StateCreator getStateCreator(Configuration config) throws JAXBException { String mapFilename = config.getString("Map"); JAXBContext context = JAXBContext.newInstance(XmlState.class); XmlState state = (XmlState) context.createUnmarshaller().unmarshal(new File(mapFilename)); return new XmlStateCreator(state); }
From source file:com.common.util.mapper.JaxbMapper.java
/** * UnMarshaller.//from w w w. jav a 2 s . c om * ???pooling */ public static Unmarshaller createUnmarshaller(Class clazz) throws JAXBException { JAXBContext jaxbContext = getJaxbContext(clazz); return jaxbContext.createUnmarshaller(); }
From source file:at.ac.tuwien.dsg.comot.m.cs.UtilsCs.java
public static Definitions loadTosca(String path) throws JAXBException, IOException { JAXBContext context = JAXBContext.newInstance(CONTEXT_TOSCA); Unmarshaller unmarshaller = context.createUnmarshaller(); return (Definitions) unmarshaller.unmarshal(Utils.loadFileFromSystem(path)); }
From source file:eu.planets_project.tb.impl.serialization.ExperimentRecords.java
/** * @param in//from w ww . j av a 2 s. com * @return */ public static ExperimentRecords readFromInputStream(InputStream in) { try { JAXBContext jc = JAXBContext.newInstance(ExperimentRecords.class); Unmarshaller u = jc.createUnmarshaller(); ExperimentRecords exp = (ExperimentRecords) u.unmarshal(in); return exp; } catch (JAXBException e) { log.fatal("Reading Experiments from XML failed: " + e); return null; } }
From source file:com.dnastack.bob.rest.BasicTest.java
public static Object readObject(Class c, String url) throws JAXBException, MalformedURLException { JAXBContext jc = JAXBContext.newInstance(c); Unmarshaller unmarshaller = jc.createUnmarshaller(); unmarshaller.setProperty(JAXBContextProperties.MEDIA_TYPE, "application/json"); unmarshaller.setProperty(JAXBContextProperties.JSON_INCLUDE_ROOT, false); StreamSource source = new StreamSource(url); JAXBElement jaxbElement = unmarshaller.unmarshal(source, c); return jaxbElement.getValue(); }
From source file:com.netsteadfast.greenstep.util.ExportData2CsvUtils.java
private static ExportDataConfig getConfig(String configXmlFile) throws Exception { InputStream is = ExportData2CsvUtils.class.getClassLoader().getResource(META_CONF_DIR + "/" + configXmlFile) .openStream();//from w ww .j av a2 s .c om byte[] xmlContent = IOUtils.toString(is, Constants.BASE_ENCODING).getBytes(); JAXBContext jaxbContext = JAXBContext.newInstance(ExportDataConfig.class); Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); ByteArrayInputStream bais = new ByteArrayInputStream(xmlContent); ExportDataConfig config = (ExportDataConfig) jaxbUnmarshaller.unmarshal(bais); return config; }