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 | |
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 '')
3 files changed, 68 insertions, 17 deletions
diff --git a/sca-java-2.x/trunk/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/ComponentBuilderImpl.java b/sca-java-2.x/trunk/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/ComponentBuilderImpl.java index c32968fd87..c525fd7b28 100644 --- a/sca-java-2.x/trunk/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/ComponentBuilderImpl.java +++ b/sca-java-2.x/trunk/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/ComponentBuilderImpl.java @@ -80,6 +80,7 @@ import org.apache.tuscany.sca.interfacedef.InterfaceContract; import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper; import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl; import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceContract; +import org.apache.tuscany.sca.interfacedef.util.JavaXMLMapper; import org.apache.tuscany.sca.interfacedef.util.XMLType; import org.apache.tuscany.sca.monitor.Monitor; import org.apache.tuscany.sca.policy.ExtensionType; @@ -97,7 +98,7 @@ import org.xml.sax.InputSource; public class ComponentBuilderImpl { protected static final String SCA11_NS = "http://docs.oasis-open.org/ns/opencsa/sca/200912"; protected static final String BINDING_SCA = "binding.sca"; - protected static final QName BINDING_SCA_QNAME = new QName(SCA11_NS, BINDING_SCA); + protected static final QName BINDING_SCA_QNAME = new QName(SCA11_NS, BINDING_SCA); private CompositeComponentTypeBuilderImpl componentTypeBuilder; protected ComponentPolicyBuilderImpl policyBuilder; @@ -348,6 +349,16 @@ public class ComponentBuilderImpl { // configure the property value based on the @file attribute processPropertyFileAttribute(component, componentProperty, monitor); + // Check that a type or element are specified + if (componentProperty.getXSDElement() == null && componentProperty.getXSDType() == null) { + Monitor.error(monitor, + this, + Messages.ASSEMBLY_VALIDATION, + "NoTypeForComponentProperty", + component.getName(), + componentProperty.getName()); + } + // Check that a value is supplied if (componentProperty.isMustSupply() && !isPropertyValueSet(componentProperty)) { Monitor.error(monitor, @@ -560,6 +571,13 @@ public class ComponentBuilderImpl { if (property != null) { componentProperty.setProperty(property); + // copy the types up if not specified at the component level + if (componentProperty.getXSDElement() == null){ + componentProperty.setXSDElement(property.getXSDElement()); + } + if (componentProperty.getXSDType() == null){ + componentProperty.setXSDType(property.getXSDType()); + } } else { Monitor.error(monitor, this, @@ -640,19 +658,10 @@ public class ComponentBuilderImpl { if (componentProperty.getXSDElement() == null) { componentProperty.setXSDElement(componentTypeProperty.getXSDElement()); } - - // Check that a type or element are specified - if (componentProperty.getXSDElement() == null && componentProperty.getXSDType() == null) { - Monitor.error(monitor, - this, - Messages.ASSEMBLY_VALIDATION, - "NoTypeForComponentProperty", - component.getName(), - componentProperty.getName()); - } // check that the types specified in the component type and component property match if ( componentProperty.getXSDElement() != null && + componentTypeProperty.getXSDElement() != null && !componentProperty.getXSDElement().equals(componentTypeProperty.getXSDElement())){ Monitor.error(monitor, this, @@ -665,7 +674,8 @@ public class ComponentBuilderImpl { } if ( componentProperty.getXSDType() != null && - !componentProperty.getXSDType().equals(componentTypeProperty.getXSDType())){ + componentTypeProperty.getXSDType() != null && + !componentProperty.getXSDType().equals(componentTypeProperty.getXSDType())){ Monitor.error(monitor, this, Messages.ASSEMBLY_VALIDATION, @@ -840,6 +850,12 @@ public class ComponentBuilderImpl { if (node != null) { componentProperty.setValue(node); + if(componentProperty.getXSDElement() == null){ + componentProperty.setXSDElement(sourceProp.getXSDElement()); + } + if(componentProperty.getXSDType() == null){ + componentProperty.setXSDType(sourceProp.getXSDType()); + } } else { Monitor.warning(monitor, this, 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) { + + } + } + */ } diff --git a/sca-java-2.x/trunk/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/databinding/PropertyDataTypeProcessor.java b/sca-java-2.x/trunk/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/databinding/PropertyDataTypeProcessor.java index 16de5bbefb..675ab2498b 100644 --- a/sca-java-2.x/trunk/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/databinding/PropertyDataTypeProcessor.java +++ b/sca-java-2.x/trunk/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/databinding/PropertyDataTypeProcessor.java @@ -19,6 +19,8 @@ package org.apache.tuscany.sca.implementation.java.databinding; +import javax.xml.namespace.QName; + import org.apache.tuscany.sca.assembly.Property; import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.apache.tuscany.sca.core.UtilityExtensionPoint; @@ -65,13 +67,16 @@ public class PropertyDataTypeProcessor extends BaseJavaClassVisitor { JavaElementImpl element = type.getPropertyMembers().get(name); introspect(property, element); DataType dt = property.getDataType(); - if (dt.getLogical() instanceof XMLType) { - XMLType xmlType = (XMLType)dt.getLogical(); + Object logical = dt.getLogical(); + if (logical instanceof XMLType && + logical != XMLType.UNKNOWN) { + XMLType xmlType = (XMLType)logical; property.setXSDType(xmlType.getTypeName()); property.setXSDElement(xmlType.getElementName()); } else { Class<?> baseType = JavaIntrospectionHelper.getBaseType(element.getType(), element.getGenericType()); - property.setXSDType(JavaXMLMapper.getXMLType(baseType)); + QName typeName = JavaXMLMapper.getXMLType(baseType); + property.setXSDType(typeName); } } super.visitEnd(clazz, type); |