List of usage examples for javax.xml.bind JAXBContext createUnmarshaller
public abstract Unmarshaller createUnmarshaller() throws JAXBException;
From source file:org.biopax.paxtools.client.BiopaxValidatorClient.java
/** * Converts a biopax-validator XML response to the java object. * * @param xml input XML data - validation report - to import * @return validation report object/*from www.j a va 2 s . c om*/ * @throws JAXBException when there is an JAXB unmarshalling error */ public static ValidatorResponse unmarshal(String xml) throws JAXBException { JAXBContext jaxbContext = JAXBContext.newInstance("org.biopax.validator.jaxb"); Unmarshaller un = jaxbContext.createUnmarshaller(); Source src = new StreamSource(new StringReader(xml)); ValidatorResponse resp = un.unmarshal(src, ValidatorResponse.class).getValue(); return resp; }
From source file:com.tomtom.speedtools.services.lbs.geocode.implementation.TomTomLbsGeoCodeEngine.java
/** * Do the heavy lifting of binding the input stream to the JAX-B annotated objects. * * @param stream Stream to read from.// www . j a v a2 s.co m * @return Valid GeoCoderResponse object or null on error. * @throws JAXBException If an error occurs unmarshalling. */ @Nullable private static GeoCodeEngineResponse unmarshalGeoCoderResponseBody(@Nonnull final InputStream stream) throws JAXBException { assert stream != null; final JAXBContext context = JAXBContext.newInstance(GeoCodeEngineResponse.class); final Unmarshaller unmarshaller = context.createUnmarshaller(); final GeoCodeEngineResponse response = (GeoCodeEngineResponse) unmarshaller.unmarshal(stream); return response; }
From source file:com.aurel.track.exchange.docx.exporter.NumberingUtil.java
static void setNumbering(WordprocessingMLPackage newPkg) { java.io.InputStream is = null; try {/* www .j av a 2s . com*/ is = ResourceUtils.getResource("com/aurel/track/exchange/docx/exporter/numbering.xml"); } catch (IOException e) { LOGGER.error("Getting the KnownStyles.xml failed with " + e.getMessage()); LOGGER.debug(ExceptionUtils.getStackTrace(e)); } JAXBContext jc = Context.jc; Unmarshaller unmarshaller = null; try { unmarshaller = jc.createUnmarshaller(); } catch (JAXBException e) { LOGGER.error("Creating a JAXB unmarshaller failed with " + e.getMessage()); LOGGER.debug(ExceptionUtils.getStackTrace(e)); } try { unmarshaller.setEventHandler(new JaxbValidationEventHandler()); } catch (JAXBException e) { LOGGER.error("Setting the event handler for JAXB unmarshaller failed with " + e.getMessage()); LOGGER.debug(ExceptionUtils.getStackTrace(e)); } Numbering numbering = null; try { numbering = (Numbering) unmarshaller.unmarshal(is); } catch (JAXBException e) { LOGGER.error("Unmarshalling the numbering.xml failed with " + e.getMessage()); LOGGER.debug(ExceptionUtils.getStackTrace(e)); } NumberingDefinitionsPart numberingDefinitionsPart = null; try { numberingDefinitionsPart = new NumberingDefinitionsPart(); } catch (InvalidFormatException e) { LOGGER.error("Creating the styles definition part failed with " + e.getMessage()); LOGGER.debug(ExceptionUtils.getStackTrace(e)); } numberingDefinitionsPart.setPackage(newPkg); numberingDefinitionsPart.setJaxbElement(numbering); try { newPkg.getMainDocumentPart().addTargetPart(numberingDefinitionsPart); } catch (InvalidFormatException e) { LOGGER.error("Adding the target part to MainDocumentPart failed with " + e.getMessage()); LOGGER.debug(ExceptionUtils.getStackTrace(e)); } }
From source file:ch.admin.suis.msghandler.common.Receipt.java
/** * Creates a receipt from this reader./*w w w.j a v a 2s . c o m*/ * * @param inputStream The flow of data representing a receipt * @return A receipt * @throws IOException if an error occures while reading XML * @throws JAXBException if an error occures while parsing XML */ public static Receipt createFrom(InputStream inputStream) throws IOException, JAXBException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); org.apache.commons.io.IOUtils.copy(inputStream, baos); byte[] bytes = baos.toByteArray(); try { JAXBContext jaxbContext = JAXBContext.newInstance(V2Receipt.class); Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); V2Receipt envelope = (V2Receipt) jaxbUnmarshaller.unmarshal(new ByteArrayInputStream(bytes)); return ReceiptTypeParent.toReceipt(envelope); } catch (UnmarshalException e) { JAXBContext jaxbContext = JAXBContext.newInstance(V1Receipt.class); Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); V1Receipt envelope = (V1Receipt) jaxbUnmarshaller.unmarshal(new ByteArrayInputStream(bytes)); return ReceiptTypeParent.toReceipt(envelope); } }
From source file:com.aionemu.packetsamurai.utils.collector.data.npcskills.NpcSkillsTool.java
public static void load() { try {// w ww . j a v a2s .c o m JAXBContext jc = JAXBContext.newInstance("com.aionemu.packetsamurai.utils.collector.data.npcskills"); Unmarshaller unmarshaller = jc.createUnmarshaller(); NpcSkillTemplates collection; collection = (NpcSkillTemplates) unmarshaller.unmarshal(new File("data/npc_skills/npc_skills.xml")); PacketSamurai.getUserInterface() .log("Skills [Npcs] - Loaded " + collection.getNpcskills().size() + " Npc Skills "); for (NpcSkillList npc : collection.getNpcskills()) { skillsByNpcId.put(npc.getNpcid(), npc); } } catch (JAXBException e) { PacketSamurai.getUserInterface().log("Skills [Npcs] - Error on loading NpcSkills Template: " + e); } }
From source file:mx.bigdata.sat.cfd.CFDv2.java
private static Comprobante load(InputStream in, String... contexts) throws Exception { JAXBContext context = getContext(contexts); try {/*from w ww.j a v a 2s. c om*/ Unmarshaller u = context.createUnmarshaller(); return (Comprobante) u.unmarshal(in); } finally { in.close(); } }
From source file:Main.java
public static <T> T unmarshal(JAXBContext context, Class<T> clazz, String source) throws JAXBException { if (source == null) { return null; }/*from w w w .j a va 2 s. c o m*/ StringReader reader = new StringReader(source); if (context == null) { context = JAXBContext.newInstance(clazz); } Unmarshaller un = context.createUnmarshaller(); return (T) un.unmarshal(reader); }
From source file:Main.java
public static Object xml2Bean(Class<?> zClass, String xml) { Object obj = null;// w w w .j av a 2s . c o m JAXBContext context = null; if (null == xml || "".equals(xml) || "null".equalsIgnoreCase(xml) || xml.length() < 1) return obj; try { context = JAXBContext.newInstance(zClass); InputStream iStream = new ByteArrayInputStream(xml.getBytes()); Unmarshaller um = context.createUnmarshaller(); obj = (Object) um.unmarshal(iStream); return obj; } catch (JAXBException e) { e.printStackTrace(); } return obj; }
From source file:com.tomtom.speedtools.services.lbs.route.implementation.TomTomLbsRouteEngineRouteEngineActorImpl.java
/** * Do the heavy lifting of binding the input stream to the JAX-B annotated objects. * * @param stream Stream to read from./* w ww .j a v a 2 s . c o m*/ * @return Valid route response object or null on error. * @throws JAXBException Thrown if unmarshalling fails. */ @Nonnull private static TomTomLbsRouteEngineResponse unmarshalRouterResponseBody(@Nonnull final InputStream stream) throws JAXBException { assert stream != null; final JAXBContext context = JAXBContext.newInstance(TomTomLbsRouteEngineResponse.class); final Unmarshaller unmarshaller = context.createUnmarshaller(); final TomTomLbsRouteEngineResponse response = (TomTomLbsRouteEngineResponse) unmarshaller.unmarshal(stream); if (response == null) { throw new JAXBException("Response cannot be unmarshalled"); } return response; }
From source file:Main.java
public static Object xml2BeanUtf8(Class<?> zClass, String xml) { Object obj = null;// ww w . j a v a 2s. c om JAXBContext context = null; if (null == xml || "".equals(xml) || "null".equalsIgnoreCase(xml) || xml.length() < 1) return obj; try { context = JAXBContext.newInstance(zClass); InputStream iStream = new ByteArrayInputStream(xml.getBytes("UTF-8")); Unmarshaller um = context.createUnmarshaller(); obj = (Object) um.unmarshal(iStream); return obj; } catch (Exception e) { e.printStackTrace(); } return obj; }