diff options
author | slaws <slaws@13f79535-47bb-0310-9956-ffa450edef68> | 2011-09-14 13:16:39 +0000 |
---|---|---|
committer | slaws <slaws@13f79535-47bb-0310-9956-ffa450edef68> | 2011-09-14 13:16:39 +0000 |
commit | 9d7c57a0e1c12472126c0888ef238c00d93e9001 (patch) | |
tree | be6c90453a62a63174113e3615981e1346a2bc55 /sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache | |
parent | f0581d45620443a18a263018a49432f26c9027e2 (diff) |
TUSCANY-3937 - Further fixes on top of Michael's patch to get the properties itest working. Mainly, builder changes to ignore null types (generated for non-JAXB pojos), update Node2JAXB to report validation errors so things don't go wrong silently, ensure default XMLType doesn't get updated, correct properties test to match OASIS, put properties test in the build.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1170598 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache')
-rw-r--r-- | sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/Node2JAXB.java | 34 |
1 files changed, 32 insertions, 2 deletions
diff --git a/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/Node2JAXB.java b/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/Node2JAXB.java index 55ed55651d..c191f42c1d 100644 --- a/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/Node2JAXB.java +++ b/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/Node2JAXB.java @@ -20,6 +20,8 @@ package org.apache.tuscany.sca.databinding.jaxb; import javax.xml.bind.JAXBContext; import javax.xml.bind.Unmarshaller; +import javax.xml.bind.ValidationEvent; +import javax.xml.bind.util.ValidationEventCollector; import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.apache.tuscany.sca.databinding.PullTransformer; @@ -34,12 +36,14 @@ import org.w3c.dom.Node; */ public class Node2JAXB extends BaseTransformer<Node, Object> implements PullTransformer<Node, Object> { private JAXBContextHelper contextHelper; + private ValidationEventCollector validationEventCollector = new ValidationEventCollector(); public Node2JAXB(ExtensionPointRegistry registry) { contextHelper = JAXBContextHelper.getInstance(registry); } public Object transform(Node source, TransformationContext context) { + Object response = null; if (source == null) return null; try { @@ -48,12 +52,27 @@ public class Node2JAXB extends BaseTransformer<Node, Object> implements PullTran Object result; // TUSCANY-3791 synchronized(source){ + /* some debug code + System.setProperty("jaxb.debug", "true"); + unmarshaller.setListener(new DebugListener()); + */ + validationEventCollector.reset(); + unmarshaller.setEventHandler(validationEventCollector); result = unmarshaller.unmarshal(source, JAXBContextHelper.getJavaType(context.getTargetDataType())); } - return JAXBContextHelper.createReturnValue(jaxbContext, context.getTargetDataType(), result); + response = JAXBContextHelper.createReturnValue(jaxbContext, context.getTargetDataType(), result); } catch (Exception e) { throw new TransformationException(e); } + + if (validationEventCollector.hasEvents()){ + String validationErrors = ""; + for(ValidationEvent event : validationEventCollector.getEvents()){ + validationErrors += "Event: " + event.getMessage() + " "; + } + throw new TransformationException(validationErrors); + } + return response; } @Override @@ -75,5 +94,16 @@ public class Node2JAXB extends BaseTransformer<Node, Object> implements PullTran public String getTargetDataBinding() { return JAXBDataBinding.NAME; } - + + /* some debug code + class DebugListener extends Unmarshaller.Listener { + public void beforeUnmarshal(Object target, Object parent) { + + } + + public void afterUnmarshal(Object target, Object parent) { + + } + } + */ } |