You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by bd...@apache.org on 2010/08/19 09:33:11 UTC
svn commit: r987051 -
/tuscany/sca-java-2.x/trunk/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/JavaPropertyValueObjectFactory.java
Author: bdaniel
Date: Thu Aug 19 07:33:11 2010
New Revision: 987051
URL: http://svn.apache.org/viewvc?rev=987051&view=rev
Log:
JCA_9013 Validate property types are compatible with getProperty() arguments
Modified:
tuscany/sca-java-2.x/trunk/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/JavaPropertyValueObjectFactory.java
Modified: tuscany/sca-java-2.x/trunk/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/JavaPropertyValueObjectFactory.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/JavaPropertyValueObjectFactory.java?rev=987051&r1=987050&r2=987051&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/JavaPropertyValueObjectFactory.java (original)
+++ tuscany/sca-java-2.x/trunk/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/JavaPropertyValueObjectFactory.java Thu Aug 19 07:33:11 2010
@@ -100,10 +100,34 @@ public class JavaPropertyValueObjectFact
}
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 JavaPropertyValueObjectFact
* @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);