diff options
author | bdaniel <bdaniel@13f79535-47bb-0310-9956-ffa450edef68> | 2010-08-19 07:33:11 +0000 |
---|---|---|
committer | bdaniel <bdaniel@13f79535-47bb-0310-9956-ffa450edef68> | 2010-08-19 07:33:11 +0000 |
commit | caa7f5579b7e4847793e8bbe26af92af78ff2d41 (patch) | |
tree | 113694f825d733b6ce4328f0691b900ad1416636 | |
parent | 768a1e33e56c579edbcab1d4ea73d06b85cdd06c (diff) |
JCA_9013 Validate property types are compatible with getProperty() arguments
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@987051 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | sca-java-2.x/trunk/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/JavaPropertyValueObjectFactory.java | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/sca-java-2.x/trunk/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/JavaPropertyValueObjectFactory.java b/sca-java-2.x/trunk/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/JavaPropertyValueObjectFactory.java index 606984659d..a190b761e2 100644 --- a/sca-java-2.x/trunk/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/JavaPropertyValueObjectFactory.java +++ b/sca-java-2.x/trunk/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/JavaPropertyValueObjectFactory.java @@ -100,10 +100,34 @@ public class JavaPropertyValueObjectFactory implements PropertyValueFactory { } public <B> B createPropertyValue(ComponentProperty property, Class<B> type) { + + validateTypes(property, type); + ObjectFactory<B> factory = this.createValueFactory(property, property.getValue(), type); return factory.getInstance(); } + private <B> void validateTypes(ComponentProperty property, Class<B> type) { + // JAXB seems to do some strange things with conversions, so + // we can't rely on the databinding conversion from Node->Java to catch + // incompatible types. + + DataType prop1 = property.getProperty().getDataType(); + + if ( (prop1 != null) && (type.isAssignableFrom(prop1.getPhysical())) ) { + return; + } else if ( simpleTypeMapper.getXMLType(type) != null ) { + if ( simpleTypeMapper.getXMLType(type).getQName().equals(property.getXSDType())) + return; + } else if ( isSimpleType(property) ) { + if ( type.isAssignableFrom(simpleTypeMapper.getJavaType(property.getXSDType()))) + return; + } + + throw new IllegalArgumentException("Property type " + prop1.getPhysical().getName() + " is not compatible with " + type.getName()); + + } + abstract class ObjectFactoryImplBase implements ObjectFactory { protected SimpleTypeMapper simpleTypeMapper = new SimpleTypeMapperImpl(); protected Property property; @@ -304,9 +328,12 @@ public class JavaPropertyValueObjectFactory implements PropertyValueFactory { * @return */ private static List<Node> getValues(Document document) { + List<Node> propValues = new ArrayList<Node>(); + if ( document == null ) + return propValues; // The root is the property element Element rootElement = document.getDocumentElement(); - List<Node> propValues = new ArrayList<Node>(); + NodeList nodes = rootElement.getChildNodes(); for (int count = 0; count < nodes.getLength(); ++count) { Node node = nodes.item(count); |