List of usage examples for org.springframework.oxm ValidationFailureException ValidationFailureException
public ValidationFailureException(String msg, Throwable cause)
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} *//*from w w w .j a va2 s . c om*/ 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.xmlbeans.XmlBeansMarshaller.java
/** * Validate the given <code>XmlObject</code>. * @param object the xml object to validate * @throws ValidationFailureException if the given object is not valid *//* ww w . ja va 2 s . c o m*/ protected void validate(XmlObject object) throws ValidationFailureException { if (isValidating() && object != null) { // create a temporary xmlOptions just for validation XmlOptions validateOptions = getXmlOptions() != null ? getXmlOptions() : new XmlOptions(); List errorsList = new ArrayList(); validateOptions.setErrorListener(errorsList); if (!object.validate(validateOptions)) { StringBuilder builder = new StringBuilder("Could not validate XmlObject :"); for (Object anErrorsList : errorsList) { XmlError xmlError = (XmlError) anErrorsList; if (xmlError instanceof XmlValidationError) { builder.append(xmlError.toString()); } } throw new ValidationFailureException("XMLBeans validation failure", new XmlException(builder.toString(), null, errorsList)); } } }
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> *///from w w w .j a v a2 s .co 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); } }