List of usage examples for org.springframework.oxm UnmarshallingFailureException UnmarshallingFailureException
public UnmarshallingFailureException(String msg, Throwable cause)
From source file:org.javelin.sws.ext.bind.SoapEncodingMarshaller.java
@Override public Object unmarshal(Source source) throws IOException, XmlMappingException { try {/*from www.ja v a 2s . co m*/ XMLStreamReader streamReader = StaxUtils.getXMLStreamReader(source); streamReader.next(); return streamReader.getElementText(); } catch (XMLStreamException e) { throw new UnmarshallingFailureException(e.getMessage(), e); } }
From source file:org.springbyexample.enterprise.solr.CatalogItemMarshaller.java
/** * Implementation of <code>Unmarshaller</code> *//*from ww w. java 2 s.co m*/ @SuppressWarnings("unchecked") public Object unmarshal(Source source) throws XmlMappingException, IOException { List<CatalogItem> lResults = new ArrayList<CatalogItem>(); if (source instanceof StreamSource) { InputStream in = null; try { in = ((StreamSource) source).getInputStream(); SAXReader reader = new SAXReader(); Document document = reader.read(in); List<Node> lNodes = document.selectNodes("//response/result[@name='response']/doc/*"); CatalogItem item = null; // loop over all matching nodes in order, so can create a new bean // instance on the first match and add it to the results on the last for (Node node : lNodes) { if (BooleanUtils.toBoolean(node.valueOf("./@name='id'"))) { item = new CatalogItem(); item.setId(node.getText()); } else if (BooleanUtils.toBoolean(node.valueOf("./@name='inStock'"))) { item.setInStock(BooleanUtils.toBoolean(node.getText())); } else if (BooleanUtils.toBoolean(node.valueOf("./@name='manu'"))) { item.setManufacturer(node.getText()); } else if (BooleanUtils.toBoolean(node.valueOf("./@name='name'"))) { item.setName(node.getText()); } else if (BooleanUtils.toBoolean(node.valueOf("./@name='popularity'"))) { item.setPopularity(Integer.parseInt(node.getText())); } else if (BooleanUtils.toBoolean(node.valueOf("./@name='price'"))) { item.setPrice(Float.parseFloat(node.getText())); lResults.add(item); } } } catch (DocumentException e) { throw new UnmarshallingFailureException(e.getMessage(), e); } finally { IOUtils.closeQuietly(in); } logger.debug("Unmarshalled bean of size {}.", lResults.size()); } return lResults; }
From source file:org.springframework.oxm.jaxb.Jaxb2Marshaller.java
@Override public Object unmarshal(Source source, @Nullable MimeContainer mimeContainer) throws XmlMappingException { source = processSource(source);/* ww w . j a v a2 s . c om*/ try { Unmarshaller unmarshaller = createUnmarshaller(); if (this.mtomEnabled && mimeContainer != null) { unmarshaller.setAttachmentUnmarshaller(new Jaxb2AttachmentUnmarshaller(mimeContainer)); } if (StaxUtils.isStaxSource(source)) { return unmarshalStaxSource(unmarshaller, source); } else if (this.mappedClass != null) { return unmarshaller.unmarshal(source, this.mappedClass).getValue(); } else { return unmarshaller.unmarshal(source); } } catch (NullPointerException ex) { if (!isSupportDtd()) { throw new UnmarshallingFailureException( "NPE while unmarshalling: " + "This can happen due to the presence of DTD declarations which are disabled.", ex); } throw ex; } catch (JAXBException ex) { throw convertJaxbException(ex); } }
From source file:org.springframework.oxm.jaxb.Jaxb2Marshaller.java
/** * Convert the given {@code JAXBException} to an appropriate exception from the * {@code org.springframework.oxm} hierarchy. * @param ex {@code JAXBException} that occurred * @return the corresponding {@code XmlMappingException} *//* ww w . j av a 2 s .com*/ protected XmlMappingException convertJaxbException(JAXBException ex) { if (ex instanceof ValidationException) { return new ValidationFailureException("JAXB validation exception", ex); } else if (ex instanceof MarshalException) { return new MarshallingFailureException("JAXB marshalling exception", ex); } else if (ex instanceof UnmarshalException) { return new UnmarshallingFailureException("JAXB unmarshalling exception", ex); } else { // fallback return new UncategorizedMappingException("Unknown JAXB exception", ex); } }
From source file:org.springframework.oxm.support.AbstractMarshaller.java
/** * Build a new {@link Document} from this marshaller's {@link DocumentBuilderFactory}, * as a placeholder for a DOM node./*w w w.ja v a 2 s.com*/ * @see #createDocumentBuilderFactory() * @see #createDocumentBuilder(DocumentBuilderFactory) */ protected Document buildDocument() { try { DocumentBuilder documentBuilder; synchronized (this.documentBuilderFactoryMonitor) { if (this.documentBuilderFactory == null) { this.documentBuilderFactory = createDocumentBuilderFactory(); } documentBuilder = createDocumentBuilder(this.documentBuilderFactory); } return documentBuilder.newDocument(); } catch (ParserConfigurationException ex) { throw new UnmarshallingFailureException("Could not create document placeholder: " + ex.getMessage(), ex); } }
From source file:org.springframework.oxm.support.AbstractMarshaller.java
/** * Template method for handling {@code DOMSource}s. * <p>This implementation delegates to {@code unmarshalDomNode}. * If the given source is empty, an empty source {@code Document} * will be created as a placeholder.//from w w w . j a v a2s . c o m * @param domSource the {@code DOMSource} * @return the object graph * @throws XmlMappingException if the given source cannot be mapped to an object * @throws IllegalArgumentException if the {@code domSource} is empty * @see #unmarshalDomNode(org.w3c.dom.Node) */ protected Object unmarshalDomSource(DOMSource domSource) throws XmlMappingException { if (domSource.getNode() == null) { domSource.setNode(buildDocument()); } try { return unmarshalDomNode(domSource.getNode()); } catch (NullPointerException ex) { if (!isSupportDtd()) { throw new UnmarshallingFailureException( "NPE while unmarshalling. " + "This can happen on JDK 1.6 due to the presence of DTD " + "declarations, which are disabled.", ex); } throw ex; } }
From source file:org.springframework.oxm.support.AbstractMarshaller.java
/** * Template method for handling {@code SAXSource}s. * <p>This implementation delegates to {@code unmarshalSaxReader}. * @param saxSource the {@code SAXSource} * @return the object graph/* www . j a v a 2 s . c o m*/ * @throws XmlMappingException if the given source cannot be mapped to an object * @throws IOException if an I/O Exception occurs * @see #unmarshalSaxReader(org.xml.sax.XMLReader, org.xml.sax.InputSource) */ protected Object unmarshalSaxSource(SAXSource saxSource) throws XmlMappingException, IOException { if (saxSource.getXMLReader() == null) { try { saxSource.setXMLReader(createXmlReader()); } catch (SAXException ex) { throw new UnmarshallingFailureException("Could not create XMLReader for SAXSource", ex); } } if (saxSource.getInputSource() == null) { saxSource.setInputSource(new InputSource()); } try { return unmarshalSaxReader(saxSource.getXMLReader(), saxSource.getInputSource()); } catch (NullPointerException ex) { if (!isSupportDtd()) { throw new UnmarshallingFailureException( "NPE while unmarshalling. " + "This can happen on JDK 1.6 due to the presence of DTD " + "declarations, which are disabled."); } throw ex; } }
From source file:org.springframework.oxm.xmlbeans.XmlBeansMarshaller.java
/** * Convert the given XMLBeans exception to an appropriate exception from the * <code>org.springframework.oxm</code> hierarchy. * <p>A boolean flag is used to indicate whether this exception occurs during marshalling or * unmarshalling, since XMLBeans itself does not make this distinction in its exception hierarchy. * @param ex XMLBeans Exception that occured * @param marshalling indicates whether the exception occurs during marshalling (<code>true</code>), * or unmarshalling (<code>false</code>) * @return the corresponding <code>XmlMappingException</code> *//* ww w. ja va2 s. c o m*/ protected XmlMappingException convertXmlBeansException(Exception ex, boolean marshalling) { if (ex instanceof XMLStreamValidationException) { return new ValidationFailureException("XmlBeans validation exception", ex); } else if (ex instanceof XmlException || ex instanceof SAXException) { if (marshalling) { return new MarshallingFailureException("XMLBeans marshalling exception", ex); } else { return new UnmarshallingFailureException("XMLBeans unmarshalling exception", ex); } } else { // fallback return new UncategorizedMappingException("Unknown XMLBeans exception", ex); } }