Search in sources :

Example 1 with BeanValidationException

use of org.eclipse.persistence.exceptions.BeanValidationException in project eclipselink by eclipse-ee4j.

the class JAXBUnmarshaller method unmarshal.

@Override
public Object unmarshal(InputStream inputStream) throws JAXBException {
    try {
        if (xmlUnmarshaller.isAutoDetectMediaType() || xmlUnmarshaller.getMediaType() == MediaType.APPLICATION_JSON || null == jaxbContext.getXMLInputFactory() || XMLUnmarshaller.NONVALIDATING != xmlUnmarshaller.getValidationMode()) {
            // xml bindings + object inside inputStream
            return validateAndTransformIfRequired(xmlUnmarshaller.unmarshal(inputStream));
        } else {
            if (null == inputStream) {
                throw XMLMarshalException.nullArgumentException();
            }
            XMLStreamReader xmlStreamReader;
            xmlStreamReader = jaxbContext.getXMLInputFactory().createXMLStreamReader(inputStream);
            Object value = unmarshal(xmlStreamReader);
            xmlStreamReader.close();
            return value;
        }
    } catch (JAXBException jaxbException) {
        throw jaxbException;
    } catch (BeanValidationException bve) {
        throw new UnmarshalException(bve.getMessage(), String.valueOf(bve.getErrorCode()), bve);
    } catch (XMLMarshalException xmlMarshalException) {
        throw handleXMLMarshalException(xmlMarshalException);
    } catch (Exception exception) {
        throw new UnmarshalException(exception);
    }
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) UnmarshalException(jakarta.xml.bind.UnmarshalException) JAXBException(jakarta.xml.bind.JAXBException) BeanValidationException(org.eclipse.persistence.exceptions.BeanValidationException) XMLMarshalException(org.eclipse.persistence.exceptions.XMLMarshalException) XMLMarshalException(org.eclipse.persistence.exceptions.XMLMarshalException) BeanValidationException(org.eclipse.persistence.exceptions.BeanValidationException) SAXException(org.xml.sax.SAXException) UnmarshalException(jakarta.xml.bind.UnmarshalException) PropertyException(jakarta.xml.bind.PropertyException) JAXBException(jakarta.xml.bind.JAXBException)

Example 2 with BeanValidationException

use of org.eclipse.persistence.exceptions.BeanValidationException in project eclipselink by eclipse-ee4j.

the class JAXBUnmarshaller method unmarshal.

@Override
public Object unmarshal(XMLStreamReader streamReader) throws JAXBException {
    if (null == streamReader) {
        throw new IllegalArgumentException();
    }
    try {
        XMLStreamReaderReader staxReader = new XMLStreamReaderReader(xmlUnmarshaller);
        XMLStreamReaderInputSource inputSource = new XMLStreamReaderInputSource(streamReader);
        Object value = xmlUnmarshaller.unmarshal(staxReader, inputSource);
        // xml bindings + object
        return validateAndTransformIfRequired(value);
    } catch (XMLMarshalException xmlMarshalException) {
        throw handleXMLMarshalException(xmlMarshalException);
    } catch (BeanValidationException bve) {
        throw new UnmarshalException(bve.getMessage(), String.valueOf(bve.getErrorCode()), bve);
    }
}
Also used : XMLStreamReaderReader(org.eclipse.persistence.internal.oxm.record.XMLStreamReaderReader) UnmarshalException(jakarta.xml.bind.UnmarshalException) BeanValidationException(org.eclipse.persistence.exceptions.BeanValidationException) XMLStreamReaderInputSource(org.eclipse.persistence.internal.oxm.record.XMLStreamReaderInputSource) XMLMarshalException(org.eclipse.persistence.exceptions.XMLMarshalException)

Example 3 with BeanValidationException

use of org.eclipse.persistence.exceptions.BeanValidationException in project eclipselink by eclipse-ee4j.

the class JAXBUnmarshaller method unmarshal.

@Override
public Object unmarshal(Reader reader) throws JAXBException {
    try {
        if (xmlUnmarshaller.isAutoDetectMediaType() || xmlUnmarshaller.getMediaType() == MediaType.APPLICATION_JSON || null == jaxbContext.getXMLInputFactory() || XMLUnmarshaller.NONVALIDATING != xmlUnmarshaller.getValidationMode()) {
            // xml bindings + object inside reader
            return validateAndTransformIfRequired(xmlUnmarshaller.unmarshal(reader));
        } else {
            if (null == reader) {
                throw XMLMarshalException.nullArgumentException();
            }
            XMLStreamReader xmlStreamReader = jaxbContext.getXMLInputFactory().createXMLStreamReader(reader);
            Object value = unmarshal(xmlStreamReader);
            xmlStreamReader.close();
            return value;
        }
    } catch (JAXBException jaxbException) {
        throw jaxbException;
    } catch (XMLMarshalException xmlMarshalException) {
        throw handleXMLMarshalException(xmlMarshalException);
    } catch (BeanValidationException bve) {
        throw new UnmarshalException(bve.getMessage(), String.valueOf(bve.getErrorCode()), bve);
    } catch (Exception exception) {
        throw new UnmarshalException(exception);
    }
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) UnmarshalException(jakarta.xml.bind.UnmarshalException) JAXBException(jakarta.xml.bind.JAXBException) BeanValidationException(org.eclipse.persistence.exceptions.BeanValidationException) XMLMarshalException(org.eclipse.persistence.exceptions.XMLMarshalException) XMLMarshalException(org.eclipse.persistence.exceptions.XMLMarshalException) BeanValidationException(org.eclipse.persistence.exceptions.BeanValidationException) SAXException(org.xml.sax.SAXException) UnmarshalException(jakarta.xml.bind.UnmarshalException) PropertyException(jakarta.xml.bind.PropertyException) JAXBException(jakarta.xml.bind.JAXBException)

Example 4 with BeanValidationException

use of org.eclipse.persistence.exceptions.BeanValidationException in project eclipselink by eclipse-ee4j.

the class JAXBMarshaller method marshal.

@Override
public void marshal(Object object, XMLEventWriter eventWriter) throws JAXBException {
    if (object == null || eventWriter == null) {
        throw new IllegalArgumentException();
    }
    Listener listener = getListener();
    if (listener != null) {
        if (object instanceof JAXBElement) {
            listener.beforeMarshal(object);
        }
    }
    // xml bindings + object
    Object oxmObject = validateAndTransformIfNeeded(object);
    try {
        XMLEventWriterRecord record = new XMLEventWriterRecord(eventWriter);
        record.setMarshaller(this.xmlMarshaller);
        this.xmlMarshaller.marshal(oxmObject, record);
    } catch (BeanValidationException bve) {
        throw new MarshalException(bve.getMessage(), String.valueOf(bve.getErrorCode()), bve);
    } catch (Exception ex) {
        throw new MarshalException(ex);
    }
    if (listener != null) {
        if (object instanceof JAXBElement) {
            listener.afterMarshal(object);
        }
    }
}
Also used : XMLMarshalException(org.eclipse.persistence.exceptions.XMLMarshalException) MarshalException(jakarta.xml.bind.MarshalException) XMLMarshalListener(org.eclipse.persistence.oxm.XMLMarshalListener) XMLEventWriterRecord(org.eclipse.persistence.oxm.record.XMLEventWriterRecord) BeanValidationException(org.eclipse.persistence.exceptions.BeanValidationException) JAXBElement(jakarta.xml.bind.JAXBElement) XMLMarshalException(org.eclipse.persistence.exceptions.XMLMarshalException) BeanValidationException(org.eclipse.persistence.exceptions.BeanValidationException) PropertyException(jakarta.xml.bind.PropertyException) MarshalException(jakarta.xml.bind.MarshalException) JAXBException(jakarta.xml.bind.JAXBException)

Example 5 with BeanValidationException

use of org.eclipse.persistence.exceptions.BeanValidationException in project eclipselink by eclipse-ee4j.

the class JAXBMarshaller method marshal.

@Override
public void marshal(Object object, Node node) throws JAXBException {
    if (object == null || node == null) {
        throw new IllegalArgumentException();
    }
    Listener listener = getListener();
    if (listener != null) {
        if (object instanceof JAXBElement) {
            listener.beforeMarshal(object);
        }
    }
    // xml bindings + object
    Object oxmObject = validateAndTransformIfNeeded(object);
    try {
        xmlMarshaller.marshal(oxmObject, node);
    } catch (BeanValidationException bve) {
        throw new MarshalException(bve.getMessage(), String.valueOf(bve.getErrorCode()), bve);
    } catch (Exception e) {
        throw new MarshalException(e);
    }
    if (listener != null) {
        if (object instanceof JAXBElement) {
            listener.afterMarshal(object);
        }
    }
}
Also used : XMLMarshalException(org.eclipse.persistence.exceptions.XMLMarshalException) MarshalException(jakarta.xml.bind.MarshalException) XMLMarshalListener(org.eclipse.persistence.oxm.XMLMarshalListener) BeanValidationException(org.eclipse.persistence.exceptions.BeanValidationException) JAXBElement(jakarta.xml.bind.JAXBElement) XMLMarshalException(org.eclipse.persistence.exceptions.XMLMarshalException) BeanValidationException(org.eclipse.persistence.exceptions.BeanValidationException) PropertyException(jakarta.xml.bind.PropertyException) MarshalException(jakarta.xml.bind.MarshalException) JAXBException(jakarta.xml.bind.JAXBException)

Aggregations

BeanValidationException (org.eclipse.persistence.exceptions.BeanValidationException)19 XMLMarshalException (org.eclipse.persistence.exceptions.XMLMarshalException)11 JAXBException (jakarta.xml.bind.JAXBException)9 PropertyException (jakarta.xml.bind.PropertyException)9 MarshalException (jakarta.xml.bind.MarshalException)7 JAXBElement (jakarta.xml.bind.JAXBElement)6 StringWriter (java.io.StringWriter)6 JAXBMarshaller (org.eclipse.persistence.jaxb.JAXBMarshaller)6 XMLMarshalListener (org.eclipse.persistence.oxm.XMLMarshalListener)6 ConstraintViolationWrapper (org.eclipse.persistence.jaxb.ConstraintViolationWrapper)5 UnmarshalException (jakarta.xml.bind.UnmarshalException)4 SAXException (org.xml.sax.SAXException)3 XMLStreamReader (javax.xml.stream.XMLStreamReader)2 NonConstrainedClass (org.eclipse.persistence.testing.jaxb.beanvalidation.special.NonConstrainedClass)2 ValidationException (jakarta.validation.ValidationException)1 ValidatorFactory (jakarta.validation.ValidatorFactory)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 SAXParserFactory (javax.xml.parsers.SAXParserFactory)1 XMLEventReaderInputSource (org.eclipse.persistence.internal.oxm.record.XMLEventReaderInputSource)1 XMLEventReaderReader (org.eclipse.persistence.internal.oxm.record.XMLEventReaderReader)1