use of org.eclipse.persistence.exceptions.XMLMarshalException in project eclipselink by eclipse-ee4j.
the class JAXBUnmarshaller method unmarshal.
/**
* Unmarshal the object based on the binding metadata associated with the
* TypeMappingInfo.
*/
public JAXBElement unmarshal(Source source, TypeMappingInfo type) throws JAXBException {
try {
Class<?> unmarshalClass = jaxbContext.getTypeMappingInfoToGeneratedType().get(type);
RootLevelXmlAdapter adapter = jaxbContext.getTypeMappingInfoToJavaTypeAdapters().get(type);
if (unmarshalClass != null) {
JAXBElement unmarshalled = unmarshal(source, unmarshalClass);
Class<?> declaredClass = null;
if (type.getType() instanceof Class) {
declaredClass = (Class) type.getType();
} else {
declaredClass = Object.class;
}
Object value = unmarshalled.getValue();
if (adapter != null) {
try {
value = adapter.getXmlAdapter().unmarshal(value);
} catch (Exception ex) {
throw new JAXBException(XMLMarshalException.marshalException(ex));
}
}
JAXBElement returnVal = new JAXBElement(unmarshalled.getName(), declaredClass, unmarshalled.getScope(), value);
return returnVal;
} else if (type.getType() instanceof Class) {
if (adapter != null) {
JAXBElement element = unmarshal(source, adapter.getBoundType());
try {
Object value = adapter.getXmlAdapter().unmarshal(element.getValue());
element.setValue(value);
return element;
} catch (Exception ex) {
throw new JAXBException(XMLMarshalException.marshalException(ex));
}
}
return unmarshal(source, (Class) type.getType());
} else if (type.getType() instanceof ParameterizedType) {
return unmarshal(source, ((ParameterizedType) type.getType()).getRawType());
}
return null;
} catch (XMLMarshalException xmlMarshalException) {
throw handleXMLMarshalException(xmlMarshalException);
}
}
use of org.eclipse.persistence.exceptions.XMLMarshalException 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.XMLMarshalException in project eclipselink by eclipse-ee4j.
the class JAXBUnmarshaller method unmarshal.
@Override
public JAXBElement unmarshal(XMLStreamReader streamReader, Class javaClass) throws JAXBException {
if (null == streamReader || null == javaClass) {
throw new IllegalArgumentException();
}
try {
XMLStreamReaderReader staxReader = new XMLStreamReaderReader(xmlUnmarshaller);
XMLStreamReaderInputSource inputSource = new XMLStreamReaderInputSource(streamReader);
if (XMLConversionManager.getDefaultJavaTypes().get(javaClass) != null || CoreClassConstants.XML_GREGORIAN_CALENDAR.isAssignableFrom(javaClass) || CoreClassConstants.DURATION.isAssignableFrom(javaClass)) {
PrimitiveContentHandler primitiveContentHandler = new PrimitiveContentHandler(javaClass);
staxReader.setContentHandler(primitiveContentHandler);
staxReader.parse(inputSource);
return primitiveContentHandler.getJaxbElement();
}
Class<?> classToUnmarshalTo = getClassToUnmarshalTo(javaClass);
// xmlbindings + object (xmlelement) + "nomappings.SomeClass" + "jaxb.stax.EndEventRoot"
JAXBElement unmarshalled = validateAndBuildJAXBElement(xmlUnmarshaller.unmarshal(staxReader, inputSource, classToUnmarshalTo), javaClass);
if (classToUnmarshalTo != javaClass) {
JAXBElement returnVal = new JAXBElement(unmarshalled.getName(), javaClass, unmarshalled.getScope(), unmarshalled.getValue());
return returnVal;
}
return unmarshalled;
} catch (XMLMarshalException xmlMarshalException) {
// Exception [EclipseLink-25004] cvc-maxInclusive-valid: Value '1234567' is not facet-valid with respect to maxInclusive '999999' for type 'id-type'.
throw handleXMLMarshalException(xmlMarshalException);
} catch (Exception e) {
throw new JAXBException(e);
}
}
use of org.eclipse.persistence.exceptions.XMLMarshalException in project eclipselink by eclipse-ee4j.
the class JAXBUnmarshaller method unmarshal.
public JAXBElement unmarshal(XMLStreamReader streamReader, Type type) throws JAXBException {
if (null == streamReader || null == type) {
throw new IllegalArgumentException();
}
try {
if (jaxbContext.getTypeToTypeMappingInfo() != null) {
TypeMappingInfo tmi = jaxbContext.getTypeToTypeMappingInfo().get(type);
if (tmi != null) {
return unmarshal(streamReader, tmi);
}
}
Class<?> unmarshalClass = jaxbContext.getCollectionClassesToGeneratedClasses().get(type);
if (unmarshalClass != null) {
JAXBElement unmarshalled = unmarshal(streamReader, unmarshalClass);
Class<?> declaredClass = null;
if (type instanceof Class) {
declaredClass = (Class) type;
} else {
declaredClass = Object.class;
}
JAXBElement returnVal = new JAXBElement(unmarshalled.getName(), declaredClass, unmarshalled.getScope(), unmarshalled.getValue());
return returnVal;
} else if (type instanceof Class) {
return unmarshal(streamReader, (Class) type);
}
return null;
} catch (XMLMarshalException xmlMarshalException) {
throw handleXMLMarshalException(xmlMarshalException);
}
}
use of org.eclipse.persistence.exceptions.XMLMarshalException in project eclipselink by eclipse-ee4j.
the class JAXBUnmarshaller method unmarshal.
/**
* Unmarshal the object based on the binding metadata associated with the
* TypeMappingInfo.
*/
public JAXBElement unmarshal(XMLEventReader eventReader, TypeMappingInfo type) throws JAXBException {
try {
if (jaxbContext.getTypeMappingInfoToGeneratedType() == null) {
return unmarshal(eventReader, type.getType());
}
Class<?> unmarshalClass = jaxbContext.getTypeMappingInfoToGeneratedType().get(type);
RootLevelXmlAdapter adapter = jaxbContext.getTypeMappingInfoToJavaTypeAdapters().get(type);
if (unmarshalClass != null) {
JAXBElement unmarshalled = unmarshal(eventReader, unmarshalClass);
Class<?> declaredClass = null;
if (type.getType() instanceof Class) {
declaredClass = (Class) type.getType();
} else {
declaredClass = Object.class;
}
Object value = unmarshalled.getValue();
if (adapter != null) {
try {
value = adapter.getXmlAdapter().unmarshal(value);
} catch (Exception ex) {
throw new JAXBException(XMLMarshalException.marshalException(ex));
}
}
JAXBElement returnVal = new JAXBElement(unmarshalled.getName(), declaredClass, unmarshalled.getScope(), value);
return returnVal;
} else if (type.getType() instanceof Class) {
if (adapter != null) {
JAXBElement element = unmarshal(eventReader, adapter.getBoundType());
try {
Object value = adapter.getXmlAdapter().unmarshal(element.getValue());
element.setValue(value);
return element;
} catch (Exception ex) {
throw new JAXBException(XMLMarshalException.marshalException(ex));
}
}
return unmarshal(eventReader, (Class) type.getType());
} else if (type.getType() instanceof ParameterizedType) {
return unmarshal(eventReader, ((ParameterizedType) type.getType()).getRawType());
}
return null;
} catch (XMLMarshalException xmlMarshalException) {
throw handleXMLMarshalException(xmlMarshalException);
}
}
Aggregations