aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'moxy/org.eclipse.persistence.moxy/src/org/eclipse/persistence/jaxb/JAXBUnmarshaller.java')
-rw-r--r--moxy/org.eclipse.persistence.moxy/src/org/eclipse/persistence/jaxb/JAXBUnmarshaller.java810
1 files changed, 438 insertions, 372 deletions
diff --git a/moxy/org.eclipse.persistence.moxy/src/org/eclipse/persistence/jaxb/JAXBUnmarshaller.java b/moxy/org.eclipse.persistence.moxy/src/org/eclipse/persistence/jaxb/JAXBUnmarshaller.java
index c270b3b..07e709c 100644
--- a/moxy/org.eclipse.persistence.moxy/src/org/eclipse/persistence/jaxb/JAXBUnmarshaller.java
+++ b/moxy/org.eclipse.persistence.moxy/src/org/eclipse/persistence/jaxb/JAXBUnmarshaller.java
@@ -9,7 +9,8 @@
*
* Contributors:
* Oracle - initial API and implementation from Oracle TopLink
- * Marcel Valovy - 2.6.0 - added case insensitive unmarshalling property
+ * Marcel Valovy - 2.6.0 - added case insensitive unmarshalling property,
+ * added Bean Validation support.
******************************************************************************/
package org.eclipse.persistence.jaxb;
@@ -21,14 +22,17 @@ import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.net.URL;
import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.StringTokenizer;
-
-import javax.xml.bind.JAXBElement;
-import javax.xml.bind.JAXBException;
-import javax.xml.bind.PropertyException;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+import java.util.StringTokenizer;
+
+import javax.validation.ConstraintViolation;
+import javax.validation.ValidatorFactory;
+import javax.xml.bind.JAXBElement;
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.PropertyException;
import javax.xml.bind.UnmarshalException;
import javax.xml.bind.Unmarshaller;
import javax.xml.bind.UnmarshallerHandler;
@@ -38,12 +42,13 @@ import javax.xml.bind.attachment.AttachmentUnmarshaller;
import javax.xml.namespace.QName;
import javax.xml.stream.XMLEventReader;
import javax.xml.stream.XMLStreamReader;
-import javax.xml.transform.Source;
-import javax.xml.validation.Schema;
-
-import org.w3c.dom.Node;
-import org.xml.sax.Attributes;
-import org.xml.sax.InputSource;
+import javax.xml.transform.Source;
+import javax.xml.validation.Schema;
+
+import org.eclipse.persistence.exceptions.BeanValidationException;
+import org.w3c.dom.Node;
+import org.xml.sax.Attributes;
+import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
@@ -65,14 +70,12 @@ import org.eclipse.persistence.internal.oxm.mappings.DirectCollectionMapping;
import org.eclipse.persistence.internal.oxm.record.namespaces.PrefixMapperNamespaceResolver;
import org.eclipse.persistence.internal.oxm.record.XMLEventReaderInputSource;
import org.eclipse.persistence.internal.oxm.record.XMLEventReaderReader;
-import org.eclipse.persistence.internal.oxm.record.XMLStreamReaderInputSource;
-import org.eclipse.persistence.internal.oxm.record.XMLStreamReaderReader;
-import org.eclipse.persistence.internal.sessions.AbstractSession;
-import org.eclipse.persistence.jaxb.JAXBErrorHandler;
-import org.eclipse.persistence.jaxb.JAXBUnmarshallerHandler;
-import org.eclipse.persistence.jaxb.JAXBContext.RootLevelXmlAdapter;
-import org.eclipse.persistence.jaxb.attachment.AttachmentUnmarshallerAdapter;
-import org.eclipse.persistence.internal.core.helper.CoreClassConstants;
+import org.eclipse.persistence.internal.oxm.record.XMLStreamReaderInputSource;
+import org.eclipse.persistence.internal.oxm.record.XMLStreamReaderReader;
+import org.eclipse.persistence.internal.sessions.AbstractSession;
+import org.eclipse.persistence.jaxb.JAXBContext.RootLevelXmlAdapter;
+import org.eclipse.persistence.jaxb.attachment.AttachmentUnmarshallerAdapter;
+import org.eclipse.persistence.internal.core.helper.CoreClassConstants;
import org.eclipse.persistence.internal.jaxb.IDResolverWrapper;
import org.eclipse.persistence.internal.jaxb.ObjectGraphImpl;
import org.eclipse.persistence.internal.jaxb.WrappedValue;
@@ -94,117 +97,145 @@ import org.eclipse.persistence.internal.jaxb.many.ManyValue;
* @see javax.xml.bind.Unmarshaller
* @see org.eclipse.persistence.jaxb.UnmarshallerProperties
* @see org.eclipse.persistence.oxm.XMLUnmarshaller
- */
-public class JAXBUnmarshaller implements Unmarshaller {
-
- private ValidationEventHandler validationEventHandler;
- private XMLUnmarshaller xmlUnmarshaller;
- private JAXBContext jaxbContext;
- public static final String XML_JAVATYPE_ADAPTERS = "xml-javatype-adapters";
- public static final String STAX_SOURCE_CLASS_NAME = "javax.xml.transform.stax.StAXSource";
-
- private static final String SUN_ID_RESOLVER = "com.sun.xml.bind.IDResolver";
- private static final String SUN_JSE_ID_RESOLVER = "com.sun.xml.internal.bind.IDResolver";
-
- public JAXBUnmarshaller(XMLUnmarshaller newXMLUnmarshaller) {
- super();
- validationEventHandler = JAXBContext.DEFAULT_VALIDATION_EVENT_HANDER;
- xmlUnmarshaller = newXMLUnmarshaller;
- xmlUnmarshaller.setValidationMode(XMLUnmarshaller.NONVALIDATING);
- xmlUnmarshaller.setUnmarshalListener(new JAXBUnmarshalListener(this));
+ */
+public class JAXBUnmarshaller implements Unmarshaller {
+
+ private final JAXBBeanValidator beanValidator;
+
+ private BeanValidationMode beanValidationMode;
+ private ValidatorFactory preferredValidatorFactory;
+ private Class<?>[] beanValidationGroups = JAXBBeanValidator.DEFAULT_GROUP_ARRAY;
+
+ private ValidationEventHandler validationEventHandler;
+ private XMLUnmarshaller xmlUnmarshaller;
+ private JAXBContext jaxbContext;
+
+ public static final String XML_JAVATYPE_ADAPTERS = "xml-javatype-adapters";
+ public static final String STAX_SOURCE_CLASS_NAME = "javax.xml.transform.stax.StAXSource";
+
+ private static final String SUN_ID_RESOLVER = "com.sun.xml.bind.IDResolver";
+ private static final String SUN_JSE_ID_RESOLVER = "com.sun.xml.internal.bind.IDResolver";
+
+ public JAXBUnmarshaller(XMLUnmarshaller newXMLUnmarshaller) {
+ super();
+ validationEventHandler = JAXBContext.DEFAULT_VALIDATION_EVENT_HANDER;
+ beanValidationMode = BeanValidationMode.AUTO;
+ beanValidator = JAXBBeanValidator.getUnmarshallingBeanValidator();
+ xmlUnmarshaller = newXMLUnmarshaller;
+ xmlUnmarshaller.setValidationMode(XMLUnmarshaller.NONVALIDATING);
+ xmlUnmarshaller.setUnmarshalListener(new JAXBUnmarshalListener(this));
xmlUnmarshaller.setErrorHandler(new JAXBErrorHandler(validationEventHandler));
}
public XMLUnmarshaller getXMLUnmarshaller() {
return xmlUnmarshaller;
- }
-
- public Object unmarshal(File file) throws JAXBException {
- try {
- Object value = xmlUnmarshaller.unmarshal(file);
- return createJAXBElementOrUnwrapIfRequired(value);
- } catch (XMLMarshalException xmlMarshalException) {
- throw handleXMLMarshalException(xmlMarshalException);
- }
- }
-
- public Object unmarshal(InputStream inputStream) throws JAXBException {
- try {
- if (xmlUnmarshaller.isAutoDetectMediaType() || xmlUnmarshaller.getMediaType() == MediaType.APPLICATION_JSON || null == jaxbContext.getXMLInputFactory() || XMLUnmarshaller.NONVALIDATING != xmlUnmarshaller.getValidationMode()) {
- return createJAXBElementOrUnwrapIfRequired(xmlUnmarshaller.unmarshal(inputStream));
- } else {
- if (null == inputStream) {
- throw XMLMarshalException.nullArgumentException();
+ }
+
+ public Object unmarshal(File file) throws JAXBException {
+ try {
+ Object value = xmlUnmarshaller.unmarshal(file);
+ return validateAndTransformIfRequired(value); // xml object
+ } catch (XMLMarshalException xmlMarshalException) {
+ throw handleXMLMarshalException(xmlMarshalException);
+ } catch (BeanValidationException bve) {
+ throw new UnmarshalException(bve.getMessage(), String.valueOf(bve.getErrorCode()), bve);
+ }
+ }
+
+
+
+ public Object unmarshal(InputStream inputStream) throws JAXBException {
+ try {
+ if (xmlUnmarshaller.isAutoDetectMediaType() || xmlUnmarshaller.getMediaType() == MediaType.APPLICATION_JSON || null == jaxbContext.getXMLInputFactory() || XMLUnmarshaller.NONVALIDATING != xmlUnmarshaller.getValidationMode()) {
+ return validateAndTransformIfRequired(xmlUnmarshaller.unmarshal(inputStream)); // xml bindings + object inside 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 (XMLMarshalException xmlMarshalException) {
- throw handleXMLMarshalException(xmlMarshalException);
- } catch (Exception exception) {
+ }
+ } 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);
}
}
- public Object unmarshal(URL url) throws JAXBException {
- try {
- Object value = xmlUnmarshaller.unmarshal(url);
- return createJAXBElementOrUnwrapIfRequired(value);
- } catch (XMLMarshalException xmlMarshalException) {
- throw handleXMLMarshalException(xmlMarshalException);
- }
- }
-
- public Object unmarshal(InputSource inputSource) throws JAXBException {
- try {
- Object value = xmlUnmarshaller.unmarshal(inputSource);
- return createJAXBElementOrUnwrapIfRequired(value);
- } catch (XMLMarshalException xmlMarshalException) {
- throw handleXMLMarshalException(xmlMarshalException);
- }
- }
-
- public Object unmarshal(Reader reader) throws JAXBException {
-
- try {
- if (xmlUnmarshaller.isAutoDetectMediaType() || xmlUnmarshaller.getMediaType() == MediaType.APPLICATION_JSON || null == jaxbContext.getXMLInputFactory() || XMLUnmarshaller.NONVALIDATING != xmlUnmarshaller.getValidationMode()) {
-
- return createJAXBElementOrUnwrapIfRequired(xmlUnmarshaller.unmarshal(reader));
- } else {
- if (null == reader) {
- throw XMLMarshalException.nullArgumentException();
- }
+ public Object unmarshal(URL url) throws JAXBException {
+ try {
+ Object value = xmlUnmarshaller.unmarshal(url);
+ return validateAndTransformIfRequired(value); // xml bindings + object
+ } catch (XMLMarshalException xmlMarshalException) {
+ throw handleXMLMarshalException(xmlMarshalException);
+ } catch (BeanValidationException bve) {
+ throw new UnmarshalException(bve.getMessage(), String.valueOf(bve.getErrorCode()), bve);
+ }
+ }
+
+ public Object unmarshal(InputSource inputSource) throws JAXBException {
+ try {
+ Object value = xmlUnmarshaller.unmarshal(inputSource);
+ return validateAndTransformIfRequired(value); // xml bindings + object
+ } catch (XMLMarshalException xmlMarshalException) {
+ throw handleXMLMarshalException(xmlMarshalException);
+ } catch (BeanValidationException bve) {
+ throw new UnmarshalException(bve.getMessage(), String.valueOf(bve.getErrorCode()), bve);
+ }
+ }
+
+ public Object unmarshal(Reader reader) throws JAXBException {
+
+ try {
+ if (xmlUnmarshaller.isAutoDetectMediaType() || xmlUnmarshaller.getMediaType() == MediaType.APPLICATION_JSON || null == jaxbContext.getXMLInputFactory() || XMLUnmarshaller.NONVALIDATING != xmlUnmarshaller.getValidationMode()) {
+
+ return validateAndTransformIfRequired(xmlUnmarshaller.unmarshal(reader)); // xml bindings + object inside 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 (Exception exception) {
- throw new UnmarshalException(exception);
- }
+ 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);
+ }
}
- public Object unmarshal(Node node) throws JAXBException {
- try {
- Object value = xmlUnmarshaller.unmarshal(node);
- return createJAXBElementOrUnwrapIfRequired(value);
- } catch (XMLMarshalException xmlMarshalException) {
- throw handleXMLMarshalException(xmlMarshalException);
- }
- }
-
- /**
- * Create a JAXBElement instance. If the object is an instance
- * of XMLRoot, we will use its field values to create the
+ public Object unmarshal(Node node) throws JAXBException {
+ try {
+ Object value = xmlUnmarshaller.unmarshal(node);
+ return validateAndTransformIfRequired(value); // xml bindings + object
+ } catch (XMLMarshalException xmlMarshalException) {
+ throw handleXMLMarshalException(xmlMarshalException);
+ } catch (BeanValidationException bve) {
+ throw new UnmarshalException(bve.getMessage(), String.valueOf(bve.getErrorCode()), bve);
+ }
+ }
+
+ private JAXBElement validateAndBuildJAXBElement(Object obj, Class declaredClass) throws BeanValidationException {
+ if (beanValidator.shouldValidate(obj, beanValidationMode, preferredValidatorFactory)) beanValidator.validate(obj, beanValidationGroups);
+ return buildJAXBElementFromObject(obj, declaredClass);
+ }
+
+ /**
+ * Create a JAXBElement instance. If the object is an instance
+ * of XMLRoot, we will use its field values to create the
* JAXBElement. If the object is not an XMLRoot instance, we
* will have to determine the 'name' value. This will be done
* using the object's descriptor default root element - any
@@ -223,13 +254,12 @@ public class JAXBUnmarshaller implements Unmarshaller {
jaxbElement.setNil(((Root)obj).isNil());
jaxbElement.setValue(null);
}
- return jaxbElement;
- }
-
-
- if(obj instanceof JAXBElement) {
- return (JAXBElement) obj;
- }
+ return jaxbElement;
+ }
+
+ if(obj instanceof JAXBElement) {
+ return (JAXBElement) obj;
+ }
// at this point, the default root element of the object being marshalled
// to == the root element - here we need to create a JAXBElement
@@ -256,15 +286,15 @@ public class JAXBUnmarshaller implements Unmarshaller {
if (rootNamespaceUri == null) {
qname = new QName(rootName);
} else {
- qname = new QName(rootNamespaceUri, rootName);
- }
- if(declaredClass != null){
- return jaxbContext.createJAXBElement(qname, declaredClass, obj);
- }else{
- return jaxbContext.createJAXBElement(qname, obj.getClass(), obj);
- }
- }
-
+ qname = new QName(rootNamespaceUri, rootName);
+ }
+ if(declaredClass != null){
+ return jaxbContext.createJAXBElement(qname, declaredClass, obj);
+ }else{
+ return jaxbContext.createJAXBElement(qname, obj.getClass(), obj);
+ }
+ }
+
public JAXBElement unmarshal(Node node, Class javaClass) throws JAXBException {
if(null == javaClass) {
throw new IllegalArgumentException();
@@ -274,35 +304,37 @@ public class JAXBUnmarshaller implements Unmarshaller {
if(jaxbContext.getArrayClassesToGeneratedClasses() != null) {
Class generatedClass = jaxbContext.getArrayClassesToGeneratedClasses().get(javaClass.getCanonicalName());
if(generatedClass != null){
- classToUnmarshalTo = generatedClass;
- }
- }
- return buildJAXBElementFromObject(xmlUnmarshaller.unmarshal(node, classToUnmarshalTo), javaClass);
- } catch (XMLMarshalException xmlMarshalException) {
- throw handleXMLMarshalException(xmlMarshalException);
- }
- }
-
- public Object unmarshal(Source source) throws JAXBException {
- try {
- Object value = xmlUnmarshaller.unmarshal(source);
- return createJAXBElementOrUnwrapIfRequired(value);
- } catch (XMLMarshalException xmlMarshalException) {
- throw handleXMLMarshalException(xmlMarshalException);
- }
+ classToUnmarshalTo = generatedClass;
+ }
+ }
+ return validateAndBuildJAXBElement(xmlUnmarshaller.unmarshal(node, classToUnmarshalTo), javaClass); // xmlbindings + object
+ } catch (XMLMarshalException xmlMarshalException) {
+ throw handleXMLMarshalException(xmlMarshalException);
+ }
}
+ public Object unmarshal(Source source) throws JAXBException {
+ try {
+ Object value = xmlUnmarshaller.unmarshal(source);
+ return validateAndTransformIfRequired(value); // xml bindings + object
+ } catch (XMLMarshalException xmlMarshalException) {
+ throw handleXMLMarshalException(xmlMarshalException);
+ } catch (BeanValidationException bve) {
+ throw new UnmarshalException(bve.getMessage(), String.valueOf(bve.getErrorCode()), bve);
+ }
+ }
+
public JAXBElement unmarshal(Source source, Class javaClass) throws JAXBException {
if(null == javaClass) {
- throw new IllegalArgumentException();
- }
- Class classToUnmarshalTo = getClassToUnmarshalTo(javaClass);
-
- try {
- return buildJAXBElementFromObject(xmlUnmarshaller.unmarshal(source, classToUnmarshalTo), javaClass);
- } catch (XMLMarshalException xmlMarshalException) {
- throw handleXMLMarshalException(xmlMarshalException);
- }
+ throw new IllegalArgumentException();
+ }
+ Class classToUnmarshalTo = getClassToUnmarshalTo(javaClass);
+
+ try {
+ return validateAndBuildJAXBElement(xmlUnmarshaller.unmarshal(source, classToUnmarshalTo), javaClass); // json object + xml bindings
+ } catch (XMLMarshalException xmlMarshalException) {
+ throw handleXMLMarshalException(xmlMarshalException);
+ }
}
private JAXBElement unmarshal(Source source, Class javaClass, Class declaredType) {
@@ -310,13 +342,13 @@ public class JAXBUnmarshaller implements Unmarshaller {
if(jaxbContext.getArrayClassesToGeneratedClasses() != null) {
Class generatedClass = jaxbContext.getArrayClassesToGeneratedClasses().get(javaClass.getCanonicalName());
if(generatedClass != null){
- classToUnmarshalTo = generatedClass;
- }
- }
- return buildJAXBElementFromObject(xmlUnmarshaller.unmarshal(source, classToUnmarshalTo), declaredType);
- }
-
- public JAXBElement unmarshal(Source source, Type type) throws JAXBException {
+ classToUnmarshalTo = generatedClass;
+ }
+ }
+ return validateAndBuildJAXBElement(xmlUnmarshaller.unmarshal(source, classToUnmarshalTo), declaredType); // never used in tests. (I guess its only for ParameterizedTypes)
+ }
+
+ public JAXBElement unmarshal(Source source, Type type) throws JAXBException {
if(null == type) {
throw new IllegalArgumentException();
}
@@ -406,21 +438,21 @@ public class JAXBUnmarshaller implements Unmarshaller {
PrimitiveContentHandler primitiveContentHandler = new PrimitiveContentHandler(javaClass);
staxReader.setContentHandler(primitiveContentHandler);
staxReader.parse(inputSource);
- return primitiveContentHandler.getJaxbElement();
- }
- Class classToUnmarshalTo = getClassToUnmarshalTo(javaClass);
- JAXBElement unmarshalled = buildJAXBElementFromObject(xmlUnmarshaller.unmarshal(staxReader, inputSource, classToUnmarshalTo), javaClass);
-
- if(classToUnmarshalTo != javaClass){
- JAXBElement returnVal = new JAXBElement(unmarshalled.getName(), javaClass, unmarshalled.getScope(), unmarshalled.getValue());
+ return primitiveContentHandler.getJaxbElement();
+ }
+ Class classToUnmarshalTo = getClassToUnmarshalTo(javaClass);
+ JAXBElement unmarshalled = validateAndBuildJAXBElement(xmlUnmarshaller.unmarshal(staxReader, inputSource, classToUnmarshalTo), javaClass); // xmlbindings + object (xmlelement) + "nomappings.SomeClass" + "jaxb.stax.EndEventRoot"
+
+ if(classToUnmarshalTo != javaClass){
+ JAXBElement returnVal = new JAXBElement(unmarshalled.getName(), javaClass, unmarshalled.getScope(), unmarshalled.getValue());
return returnVal;
- }
- return unmarshalled;
- } catch (XMLMarshalException xmlMarshalException) {
- throw handleXMLMarshalException(xmlMarshalException);
- } catch (Exception e) {
- throw new JAXBException(e);
- }
+ }
+ return unmarshalled;
+ } catch (XMLMarshalException xmlMarshalException) {
+ throw handleXMLMarshalException(xmlMarshalException); // Exception [EclipseLink-25004] cvc-maxInclusive-valid: Value '1234567' is not facet-valid with respect to maxInclusive '999999' for type 'id-type'.
+ } catch (Exception e) {
+ throw new JAXBException(e);
+ }
}
public JAXBElement unmarshal(XMLStreamReader streamReader, Type type) throws JAXBException {
@@ -481,17 +513,17 @@ public class JAXBUnmarshaller implements Unmarshaller {
staxReader.parse(inputSource);
return primitiveArrayContentHandler.getJaxbElement();
}
- }
-
- if(null != xmlDescriptor && null == getSchema()) {
- RootLevelXmlAdapter adapter= null;
- if(jaxbContext.getTypeMappingInfoToJavaTypeAdapters().size() >0){
- adapter = jaxbContext.getTypeMappingInfoToJavaTypeAdapters().get(type);
- }
- UnmarshalRecord wrapper = (UnmarshalRecord) xmlDescriptor.getObjectBuilder().createRecord((AbstractSession) xmlUnmarshaller.getXMLContext().getSession());
- org.eclipse.persistence.internal.oxm.record.UnmarshalRecord unmarshalRecord = (org.eclipse.persistence.internal.oxm.record.UnmarshalRecord) wrapper.getUnmarshalRecord();
- XMLStreamReaderReader staxReader = new XMLStreamReaderReader(xmlUnmarshaller);
- unmarshalRecord.setUnmarshaller(xmlUnmarshaller);
+ }
+
+ if(null != xmlDescriptor && null == getSchema()) {
+ RootLevelXmlAdapter adapter= null;
+ if(jaxbContext.getTypeMappingInfoToJavaTypeAdapters().size() >0){
+ adapter = jaxbContext.getTypeMappingInfoToJavaTypeAdapters().get(type);
+ }
+ UnmarshalRecord wrapper = (UnmarshalRecord) xmlDescriptor.getObjectBuilder().createRecord((AbstractSession) xmlUnmarshaller.getXMLContext().getSession());
+ org.eclipse.persistence.internal.oxm.record.UnmarshalRecord unmarshalRecord = (org.eclipse.persistence.internal.oxm.record.UnmarshalRecord) wrapper.getUnmarshalRecord();
+ XMLStreamReaderReader staxReader = new XMLStreamReaderReader(xmlUnmarshaller);
+ unmarshalRecord.setUnmarshaller(xmlUnmarshaller);
unmarshalRecord.setXMLReader(staxReader);
staxReader.setContentHandler(unmarshalRecord);
staxReader.parse(streamReader);
@@ -499,17 +531,17 @@ public class JAXBUnmarshaller implements Unmarshaller {
if(unmarshalRecord.isNil()) {
value = null;
} else {
- value = unmarshalRecord.getCurrentObject();
- }
- if(value instanceof WrappedValue){
- value = ((WrappedValue)value).getValue();
- }
-
- if(value instanceof ManyValue){
- value = ((ManyValue)value).getItem();
- }
- if(adapter != null) {
- try {
+ value = unmarshalRecord.getCurrentObject();
+ }
+ if(value instanceof WrappedValue){
+ value = ((WrappedValue)value).getValue();
+ }
+
+ if(value instanceof ManyValue){
+ value = ((ManyValue)value).getItem();
+ }
+ if(adapter != null) {
+ try {
value = adapter.getXmlAdapter().unmarshal(value);
} catch(Exception ex) {
throw new JAXBException(XMLMarshalException.marshalException(ex));
@@ -525,20 +557,20 @@ public class JAXBUnmarshaller implements Unmarshaller {
}
if(jaxbContext.getTypeMappingInfoToGeneratedType() == null) {
return unmarshal(streamReader, type.getType());
- }
- RootLevelXmlAdapter adapter= null;
- if(jaxbContext.getTypeMappingInfoToJavaTypeAdapters().size() >0){
- adapter = jaxbContext.getTypeMappingInfoToJavaTypeAdapters().get(type);
- }
- Class unmarshalClass = null;
- if(jaxbContext.getTypeMappingInfoToGeneratedType().size() >0){
- unmarshalClass = jaxbContext.getTypeMappingInfoToGeneratedType().get(type);
- }
-
- if(unmarshalClass != null){
- JAXBElement unmarshalled = unmarshal(streamReader, unmarshalClass);
- Class declaredClass = null;
- if(type.getType() instanceof Class){
+ }
+ RootLevelXmlAdapter adapter= null;
+ if(jaxbContext.getTypeMappingInfoToJavaTypeAdapters().size() >0){
+ adapter = jaxbContext.getTypeMappingInfoToJavaTypeAdapters().get(type);
+ }
+ Class unmarshalClass = null;
+ if(jaxbContext.getTypeMappingInfoToGeneratedType().size() >0){
+ unmarshalClass = jaxbContext.getTypeMappingInfoToGeneratedType().get(type);
+ }
+
+ if(unmarshalClass != null){
+ JAXBElement unmarshalled = unmarshal(streamReader, unmarshalClass);
+ Class declaredClass = null;
+ if(type.getType() instanceof Class){
declaredClass = (Class)type.getType();
}else{
declaredClass = Object.class;
@@ -581,27 +613,29 @@ public class JAXBUnmarshaller implements Unmarshaller {
throw new IllegalArgumentException();
}
try {
- XMLStreamReaderReader staxReader = new XMLStreamReaderReader(xmlUnmarshaller);
- XMLStreamReaderInputSource inputSource = new XMLStreamReaderInputSource(streamReader);
- Object value = xmlUnmarshaller.unmarshal(staxReader, inputSource);
- return createJAXBElementOrUnwrapIfRequired(value);
- } catch (XMLMarshalException xmlMarshalException) {
- throw handleXMLMarshalException(xmlMarshalException);
- }
- }
-
+ XMLStreamReaderReader staxReader = new XMLStreamReaderReader(xmlUnmarshaller);
+ XMLStreamReaderInputSource inputSource = new XMLStreamReaderInputSource(streamReader);
+ Object value = xmlUnmarshaller.unmarshal(staxReader, inputSource);
+ return validateAndTransformIfRequired(value); // xml bindings + object
+ } catch (XMLMarshalException xmlMarshalException) {
+ throw handleXMLMarshalException(xmlMarshalException);
+ } catch (BeanValidationException bve) {
+ throw new UnmarshalException(bve.getMessage(), String.valueOf(bve.getErrorCode()), bve);
+ }
+ }
+
public JAXBElement unmarshal(XMLEventReader eventReader, Class javaClass) throws JAXBException {
if(null == eventReader || null == javaClass) {
throw new IllegalArgumentException();
}
try {
- Class classToUnmarshalTo = getClassToUnmarshalTo(javaClass);
- XMLEventReaderReader staxReader = new XMLEventReaderReader(xmlUnmarshaller);
- XMLEventReaderInputSource inputSource = new XMLEventReaderInputSource(eventReader);
- JAXBElement unmarshalled = buildJAXBElementFromObject(xmlUnmarshaller.unmarshal(staxReader, inputSource, classToUnmarshalTo), javaClass);
-
- if(classToUnmarshalTo != javaClass){
- JAXBElement returnVal = new JAXBElement(unmarshalled.getName(), javaClass, unmarshalled.getScope(), unmarshalled.getValue());
+ Class classToUnmarshalTo = getClassToUnmarshalTo(javaClass);
+ XMLEventReaderReader staxReader = new XMLEventReaderReader(xmlUnmarshaller);
+ XMLEventReaderInputSource inputSource = new XMLEventReaderInputSource(eventReader);
+ JAXBElement unmarshalled = validateAndBuildJAXBElement(xmlUnmarshaller.unmarshal(staxReader, inputSource, classToUnmarshalTo), javaClass); // json object + xml bindings
+
+ if(classToUnmarshalTo != javaClass){
+ JAXBElement returnVal = new JAXBElement(unmarshalled.getName(), javaClass, unmarshalled.getScope(), unmarshalled.getValue());
return returnVal;
}
return unmarshalled;
@@ -697,15 +731,17 @@ public class JAXBUnmarshaller implements Unmarshaller {
throw new IllegalArgumentException();
}
try {
- XMLEventReaderReader staxReader = new XMLEventReaderReader(xmlUnmarshaller);
- XMLEventReaderInputSource inputSource = new XMLEventReaderInputSource(eventReader);
- Object value = xmlUnmarshaller.unmarshal(staxReader, inputSource);
- return createJAXBElementOrUnwrapIfRequired(value);
- } catch (XMLMarshalException xmlMarshalException) {
- throw handleXMLMarshalException(xmlMarshalException);
- }
- }
-
+ XMLEventReaderReader staxReader = new XMLEventReaderReader(xmlUnmarshaller);
+ XMLEventReaderInputSource inputSource = new XMLEventReaderInputSource(eventReader);
+ Object value = xmlUnmarshaller.unmarshal(staxReader, inputSource);
+ return validateAndTransformIfRequired(value); // xml bindings + object
+ } catch (XMLMarshalException xmlMarshalException) {
+ throw handleXMLMarshalException(xmlMarshalException);
+ } catch (BeanValidationException bve) {
+ throw new UnmarshalException(bve.getMessage(), String.valueOf(bve.getErrorCode()), bve);
+ }
+ }
+
public UnmarshallerHandler getUnmarshallerHandler() {
return new JAXBUnmarshallerHandler(this);
}
@@ -749,10 +785,10 @@ public class JAXBUnmarshaller implements Unmarshaller {
if(value instanceof MediaType) {
mType = (MediaType) value;
} else if(value instanceof String) {
- mType = MediaType.getMediaType((String)value);
- }
+ mType = MediaType.getMediaType((String)value);
+ }
if(mType == null){
- throw new PropertyException(key, Constants.EMPTY_STRING);
+ throw new PropertyException(key, Constants.EMPTY_STRING);
}
xmlUnmarshaller.setMediaType(mType);
} else if (key.equals(UnmarshallerProperties.UNMARSHALLING_CASE_INSENSITIVE)){
@@ -761,60 +797,75 @@ public class JAXBUnmarshaller implements Unmarshaller {
}
xmlUnmarshaller.setCaseInsensitive((Boolean)value);
} else if (key.equals(UnmarshallerProperties.AUTO_DETECT_MEDIA_TYPE)){
- if(value == null){
- throw new PropertyException(key, Constants.EMPTY_STRING);
- }
- xmlUnmarshaller.setAutoDetectMediaType((Boolean)value);
- } else if (key.equals(UnmarshallerProperties.JSON_ATTRIBUTE_PREFIX)){
- xmlUnmarshaller.setAttributePrefix((String)value);
- } else if (UnmarshallerProperties.JSON_INCLUDE_ROOT.equals(key)) {
- if(value == null){
- throw new PropertyException(key, Constants.EMPTY_STRING);
- }
- xmlUnmarshaller.setIncludeRoot((Boolean)value);
- } else if (UnmarshallerProperties.JSON_NAMESPACE_PREFIX_MAPPER.equals(key)){
- if (value == null){
- xmlUnmarshaller.setNamespaceResolver(null);
- } else if (value instanceof Map){
- Map<String, String> namespaces = (Map<String, String>)value;
- NamespaceResolver nr = new NamespaceResolver();
- Iterator<Entry<String, String>> namesapcesIter = namespaces.entrySet().iterator();
+ if(value == null){
+ throw new PropertyException(key, Constants.EMPTY_STRING);
+ }
+ xmlUnmarshaller.setAutoDetectMediaType((Boolean)value);
+ } else if (key.equals(UnmarshallerProperties.JSON_ATTRIBUTE_PREFIX)){
+ xmlUnmarshaller.setAttributePrefix((String)value);
+ } else if (UnmarshallerProperties.JSON_INCLUDE_ROOT.equals(key)) {
+ if(value == null){
+ throw new PropertyException(key, Constants.EMPTY_STRING);
+ }
+ xmlUnmarshaller.setIncludeRoot((Boolean)value);
+ } else if (UnmarshallerProperties.JSON_NAMESPACE_PREFIX_MAPPER.equals(key)){
+ if (value == null){
+ xmlUnmarshaller.setNamespaceResolver(null);
+ } else if (value instanceof Map){
+ Map<String, String> namespaces = (Map<String, String>)value;
+ NamespaceResolver nr = new NamespaceResolver();
+ Iterator<Entry<String, String>> namesapcesIter = namespaces.entrySet().iterator();
for (int i=0;i<namespaces.size(); i++){
Entry<String, String> nextEntry = namesapcesIter.next();
nr.put(nextEntry.getValue(), nextEntry.getKey());
- }
- xmlUnmarshaller.setNamespaceResolver(nr);
- } else if (value instanceof NamespacePrefixMapper){
- xmlUnmarshaller.setNamespaceResolver(new PrefixMapperNamespaceResolver((NamespacePrefixMapper)value, null));
- }
- } else if (UnmarshallerProperties.JSON_VALUE_WRAPPER.equals(key)){
- xmlUnmarshaller.setValueWrapper((String)value);
- } else if (UnmarshallerProperties.JSON_NAMESPACE_SEPARATOR.equals(key)){
- if(value == null){
- throw new PropertyException(key, Constants.EMPTY_STRING);
- }
- xmlUnmarshaller.setNamespaceSeparator((Character)value);
- } else if (UnmarshallerProperties.ID_RESOLVER.equals(key)) {
- setIDResolver((IDResolver) value);
- } else if (SUN_ID_RESOLVER.equals(key) || SUN_JSE_ID_RESOLVER.equals(key)) {
- if(value == null){
- setIDResolver(null);
- }else {
- setIDResolver(new IDResolverWrapper(value));
- }
- } else if (UnmarshallerProperties.OBJECT_GRAPH.equals(key)) {
- if(value instanceof ObjectGraphImpl) {
- xmlUnmarshaller.setUnmarshalAttributeGroup(((ObjectGraphImpl)value).getAttributeGroup());
- } else if(value instanceof String || value == null) {
- xmlUnmarshaller.setUnmarshalAttributeGroup(value);
- } else {
+ }
+ xmlUnmarshaller.setNamespaceResolver(nr);
+ } else if (value instanceof NamespacePrefixMapper){
+ xmlUnmarshaller.setNamespaceResolver(new PrefixMapperNamespaceResolver((NamespacePrefixMapper)value, null));
+ }
+ } else if (UnmarshallerProperties.JSON_VALUE_WRAPPER.equals(key)){
+ xmlUnmarshaller.setValueWrapper((String)value);
+ } else if (UnmarshallerProperties.JSON_NAMESPACE_SEPARATOR.equals(key)){
+ if(value == null){
+ throw new PropertyException(key, Constants.EMPTY_STRING);
+ }
+ xmlUnmarshaller.setNamespaceSeparator((Character)value);
+ } else if (UnmarshallerProperties.ID_RESOLVER.equals(key)) {
+ setIDResolver((IDResolver) value);
+ } else if (SUN_ID_RESOLVER.equals(key) || SUN_JSE_ID_RESOLVER.equals(key)) {
+ if(value == null){
+ setIDResolver(null);
+ }else {
+ setIDResolver(new IDResolverWrapper(value));
+ }
+ } else if (UnmarshallerProperties.OBJECT_GRAPH.equals(key)) {
+ if(value instanceof ObjectGraphImpl) {
+ xmlUnmarshaller.setUnmarshalAttributeGroup(((ObjectGraphImpl) value).getAttributeGroup());
+ } else if(value instanceof String || value == null) {
+ xmlUnmarshaller.setUnmarshalAttributeGroup(value);
+ } else {
throw org.eclipse.persistence.exceptions.JAXBException.invalidValueForObjectGraph(value);
- }
- } else if (UnmarshallerProperties.JSON_WRAPPER_AS_ARRAY_NAME.equals(key)) {
- xmlUnmarshaller.setWrapperAsCollectionName((Boolean) value);
- } else {
- throw new PropertyException(key, value);
- }
+ }
+ } else if (UnmarshallerProperties.JSON_WRAPPER_AS_ARRAY_NAME.equals(key)) {
+ xmlUnmarshaller.setWrapperAsCollectionName((Boolean) value);
+ } else if (UnmarshallerProperties.BEAN_VALIDATION_MODE.equals(key)){
+ if(value == null){
+ throw new PropertyException(key, Constants.EMPTY_STRING);
+ }
+ this.beanValidationMode = ((BeanValidationMode) value);
+ } else if (UnmarshallerProperties.BEAN_VALIDATION_FACTORY.equals(key)) {
+ if(value == null){
+ // Allow null value for preferred validation factory.
+ }
+ this.preferredValidatorFactory = ((ValidatorFactory)value);
+ } else if (UnmarshallerProperties.BEAN_VALIDATION_GROUPS.equals(key)) {
+ if(value == null){
+ // Allow null value for preferred validation factory.
+ }
+ this.beanValidationGroups = ((Class<?>[]) value);
+ } else {
+ throw new PropertyException(key, value);
+ }
}
/**
@@ -837,15 +888,15 @@ public class JAXBUnmarshaller implements Unmarshaller {
return xmlUnmarshaller.getAttributePrefix();
} else if (key.equals(UnmarshallerProperties.JSON_INCLUDE_ROOT)) {
return xmlUnmarshaller.isIncludeRoot();
- } else if (key.equals(UnmarshallerProperties.JSON_NAMESPACE_SEPARATOR)) {
- return xmlUnmarshaller.getNamespaceSeparator();
- } else if (key.equals(UnmarshallerProperties.JSON_NAMESPACE_PREFIX_MAPPER)) {
- if(xmlUnmarshaller.getNamespaceResolver() == null){
- return null;
- }
- if (xmlUnmarshaller.getNamespaceResolver() instanceof PrefixMapperNamespaceResolver) {
- PrefixMapperNamespaceResolver wrapper = (PrefixMapperNamespaceResolver) xmlUnmarshaller.getNamespaceResolver();
- return wrapper.getPrefixMapper();
+ } else if (key.equals(UnmarshallerProperties.JSON_NAMESPACE_SEPARATOR)) {
+ return xmlUnmarshaller.getNamespaceSeparator();
+ } else if (key.equals(UnmarshallerProperties.JSON_NAMESPACE_PREFIX_MAPPER)) {
+ if(xmlUnmarshaller.getNamespaceResolver() == null){
+ return null;
+ }
+ if (xmlUnmarshaller.getNamespaceResolver() instanceof PrefixMapperNamespaceResolver) {
+ PrefixMapperNamespaceResolver wrapper = (PrefixMapperNamespaceResolver) xmlUnmarshaller.getNamespaceResolver();
+ return wrapper.getPrefixMapper();
} else {
Map<String, String> nsMap = new HashMap<String, String>();
Map<String, String> prefixesToNS = xmlUnmarshaller.getNamespaceResolver().getPrefixesToNamespaces();
@@ -861,23 +912,29 @@ public class JAXBUnmarshaller implements Unmarshaller {
return xmlUnmarshaller.getValueWrapper();
} else if (UnmarshallerProperties.ID_RESOLVER.equals(key)) {
return xmlUnmarshaller.getIDResolver();
- } else if (SUN_ID_RESOLVER.equals(key) || SUN_JSE_ID_RESOLVER.equals(key)) {
- IDResolverWrapper wrapper = (IDResolverWrapper) xmlUnmarshaller.getIDResolver();
- if(wrapper == null){
- return null;
- }
- return wrapper.getResolver();
- } else if (UnmarshallerProperties.OBJECT_GRAPH.equals(key)) {
+ } else if (SUN_ID_RESOLVER.equals(key) || SUN_JSE_ID_RESOLVER.equals(key)) {
+ IDResolverWrapper wrapper = (IDResolverWrapper) xmlUnmarshaller.getIDResolver();
+ if(wrapper == null){
+ return null;
+ }
+ return wrapper.getResolver();
+ } else if (UnmarshallerProperties.OBJECT_GRAPH.equals(key)) {
Object graph = xmlUnmarshaller.getUnmarshalAttributeGroup();
if(graph instanceof CoreAttributeGroup) {
return new ObjectGraphImpl((CoreAttributeGroup)graph);
}
- return graph;
- } else if(UnmarshallerProperties.JSON_WRAPPER_AS_ARRAY_NAME.equals(key)) {
- return xmlUnmarshaller.isWrapperAsCollectionName();
- }
- throw new PropertyException(key);
- }
+ return graph;
+ } else if(UnmarshallerProperties.JSON_WRAPPER_AS_ARRAY_NAME.equals(key)) {
+ return xmlUnmarshaller.isWrapperAsCollectionName();
+ } else if (UnmarshallerProperties.BEAN_VALIDATION_MODE.equals(key)) {
+ return this.beanValidationMode;
+ } else if (UnmarshallerProperties.BEAN_VALIDATION_FACTORY.equals(key)) {
+ return this.preferredValidatorFactory;
+ } else if (UnmarshallerProperties.BEAN_VALIDATION_GROUPS.equals(key)) {
+ return this.beanValidationGroups;
+ }
+ throw new PropertyException(key);
+ }
public Unmarshaller.Listener getListener() {
return ((JAXBUnmarshalListener)xmlUnmarshaller.getUnmarshalListener()).getListener();
@@ -928,17 +985,22 @@ public class JAXBUnmarshaller implements Unmarshaller {
xmlUnmarshaller.setAttachmentUnmarshaller(null);
} else {
xmlUnmarshaller.setAttachmentUnmarshaller(new AttachmentUnmarshallerAdapter(unmarshaller));
- }
- }
-
- public void setUnmarshalCallbacks(java.util.HashMap callbacks) {
- ((JAXBUnmarshalListener)xmlUnmarshaller.getUnmarshalListener()).setClassBasedUnmarshalEvents(callbacks);
- }
-
- private Object createJAXBElementOrUnwrapIfRequired(Object value){
- if(value instanceof Root){
- JAXBElement jaxbElement = jaxbContext.createJAXBElementFromXMLRoot((Root)value, Object.class);
- jaxbElement.setNil(((Root) value).isNil());
+ }
+ }
+
+ public void setUnmarshalCallbacks(Map callbacks) {
+ ((JAXBUnmarshalListener)xmlUnmarshaller.getUnmarshalListener()).setClassBasedUnmarshalEvents(callbacks);
+ }
+
+ private Object validateAndTransformIfRequired(Object value) throws BeanValidationException {
+ if (beanValidator.shouldValidate(value, beanValidationMode, preferredValidatorFactory)) beanValidator.validate(value, beanValidationGroups);
+ return createJAXBElementOrUnwrapIfRequired(value);
+ }
+
+ private Object createJAXBElementOrUnwrapIfRequired(Object value) {
+ if(value instanceof Root){
+ JAXBElement jaxbElement = jaxbContext.createJAXBElementFromXMLRoot((Root)value, Object.class);
+ jaxbElement.setNil(((Root) value).isNil());
return jaxbElement;
} else if(value instanceof WrappedValue) {
return ((WrappedValue)value).getValue();
@@ -967,53 +1029,57 @@ public class JAXBUnmarshaller implements Unmarshaller {
Class generatedClass = jaxbContext.getCollectionClassesToGeneratedClasses().get(originalClass);
if(generatedClass != null){
classToUnmarshalTo = generatedClass;
- }
- }
- if(jaxbContext.getTypeToTypeMappingInfo() != null){
- TypeMappingInfo tmi = jaxbContext.getTypeToTypeMappingInfo().get(originalClass);
- if(tmi != null && jaxbContext.getTypeMappingInfoToGeneratedType() != null) {
- Class generatedClass = jaxbContext.getTypeMappingInfoToGeneratedType().get(tmi);
- if(generatedClass != null){
- classToUnmarshalTo = generatedClass;
- }
- }
- }
- return classToUnmarshalTo;
- }
+ }
+ }
+ if(jaxbContext.getTypeToTypeMappingInfo() != null){
+ TypeMappingInfo tmi = jaxbContext.getTypeToTypeMappingInfo().get(originalClass);
+ if(tmi != null && jaxbContext.getTypeMappingInfoToGeneratedType() != null) {
+ Class generatedClass = jaxbContext.getTypeMappingInfoToGeneratedType().get(tmi);
+ if(generatedClass != null){
+ classToUnmarshalTo = generatedClass;
+ }
+ }
+ }
+ return classToUnmarshalTo;
+ }
private JAXBException handleXMLMarshalException(XMLMarshalException xmlMarshalException) {
if(xmlMarshalException.getErrorCode() == XMLMarshalException.NULL_ARGUMENT) {
throw new IllegalArgumentException(xmlMarshalException);
- } else {
- return new UnmarshalException(xmlMarshalException);
- }
- }
-
-
- /**
- * Return this Unmarshaller's custom IDResolver.
- *
- * @see IDResolver
- * @since 2.3.3
- * @return the custom IDResolver, or null if one has not been specified.
+ } else {
+ return new UnmarshalException(xmlMarshalException);
+ }
+ }
+
+
+ /**
+ * Return this Unmarshaller's custom IDResolver.
+ *
+ * @see IDResolver
+ * @since 2.3.3
+ * @return the custom IDResolver, or null if one has not been specified.
*/
public IDResolver getIDResolver() {
return getXMLUnmarshaller().getIDResolver();
}
-
- /**
- * Set this Unmarshaller's custom IDResolver.
- *
- * @see IDResolver
- * @since 2.3.3
- */
+
+ /**
+ * Set this Unmarshaller's custom IDResolver.
+ *
+ * @see IDResolver
+ * @since 2.3.3
+ */
public void setIDResolver(IDResolver idResolver) {
- getXMLUnmarshaller().setIDResolver(idResolver);
- }
-
- private static class PrimitiveContentHandler<T> extends DefaultHandler {
-
- private Class<T> clazz;
+ getXMLUnmarshaller().setIDResolver(idResolver);
+ }
+
+ public Set<? extends ConstraintViolation<?>> getConstraintViolations() {
+ return beanValidator.getConstraintViolations();
+ }
+
+ private static class PrimitiveContentHandler<T> extends DefaultHandler {
+
+ private Class<T> clazz;
private JAXBElement<T> jaxbElement;
private Map<String, String> namespaces = new HashMap<String, String>(3);
private StringBuilder stringBuilder = new StringBuilder();
@@ -1039,26 +1105,26 @@ public class JAXBUnmarshaller implements Unmarshaller {
value = (T) xcm.convertObject(stringBuilder.toString(), clazz, Constants.BASE_64_BINARY_QNAME);
} else {
value = (T) xcm.convertObject(stringBuilder.toString(), clazz);
- }
- } else {
- int colonIndex = xsiType.indexOf(':');
-
- String typePrefix;
- String typeName;
- if(colonIndex == -1) {
+ }
+ } else {
+ int colonIndex = xsiType.indexOf(':');
+
+ String typePrefix;
+ String typeName;
+ if(colonIndex == -1) {
typePrefix = Constants.EMPTY_STRING;
typeName = xsiType;
} else {
typePrefix = xsiType.substring(0, colonIndex);
typeName = xsiType.substring(colonIndex + 1);
}
- String typeNamespace = namespaces.get(typePrefix);
- QName typeQName = new QName(typeNamespace, typeName);
- value = (T) xcm.convertObject(stringBuilder.toString(), clazz, typeQName);
-
- }
-
- QName qName;
+ String typeNamespace = namespaces.get(typePrefix);
+ QName typeQName = new QName(typeNamespace, typeName);
+ value = (T) xcm.convertObject(stringBuilder.toString(), clazz, typeQName);
+
+ }
+
+ QName qName;
if(namespaceURI != null && namespaceURI.length() == 0) {
qName = new QName(qualifiedName);
} else {