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);
}
}
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);
}
}
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);
}
}
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);
}
}
}
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);
}
}
}
Aggregations