You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by sv...@apache.org on 2007/10/15 13:45:38 UTC

svn commit: r584750 - in /incubator/tuscany/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java: injection/JavaPropertyValueObjectFactory.java invocation/JavaComponentContextProvider.java

Author: svkrish
Date: Mon Oct 15 04:45:38 2007
New Revision: 584750

URL: http://svn.apache.org/viewvc?rev=584750&view=rev
Log:
fixing https://issues.apache.org/jira/browse/TUSCANY-1848

Modified:
    incubator/tuscany/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/JavaPropertyValueObjectFactory.java
    incubator/tuscany/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaComponentContextProvider.java

Modified: incubator/tuscany/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/JavaPropertyValueObjectFactory.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/JavaPropertyValueObjectFactory.java?rev=584750&r1=584749&r2=584750&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/JavaPropertyValueObjectFactory.java (original)
+++ incubator/tuscany/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/JavaPropertyValueObjectFactory.java Mon Oct 15 04:45:38 2007
@@ -18,6 +18,7 @@
  */
 package org.apache.tuscany.sca.implementation.java.injection;
 
+import java.lang.reflect.Array;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.StringTokenizer;
@@ -31,6 +32,8 @@
 import org.apache.tuscany.sca.databinding.SimpleTypeMapper;
 import org.apache.tuscany.sca.databinding.impl.SimpleTypeMapperImpl;
 import org.apache.tuscany.sca.databinding.xml.DOMDataBinding;
+import org.apache.tuscany.sca.implementation.java.impl.JavaElementImpl;
+import org.apache.tuscany.sca.implementation.java.introspect.impl.JavaIntrospectionHelper;
 import org.apache.tuscany.sca.interfacedef.DataType;
 import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl;
 import org.apache.tuscany.sca.interfacedef.util.TypeInfo;
@@ -46,6 +49,49 @@
     public JavaPropertyValueObjectFactory(Mediator mediator) {
         this.mediator = mediator;
     }
+    
+    public ObjectFactory createValueFactory(Property property, Object propertyValue, JavaElementImpl javaElement) {
+        isSimpleType = isSimpleType(property);
+        Document doc = (Document)propertyValue;
+        Class javaType = JavaIntrospectionHelper.getBaseType(javaElement.getType(), javaElement.getGenericType());
+        Element rootElement = doc.getDocumentElement();
+        if (property.isMany()) {
+            if (isSimpleType) {
+                String value = "";
+                if (rootElement.getChildNodes().getLength() > 0) {
+                    value = rootElement.getChildNodes().item(0).getTextContent();
+                }
+                List<String> values = getSimplePropertyValues(value, javaType);
+                if ( javaElement.getType().isArray() ) {
+                    return new ArrayObjectFactoryImpl(property, values, isSimpleType, javaType);
+                } else {
+                    return new ListObjectFactoryImpl(property, values, isSimpleType, javaType);
+                }
+            } else {
+                if ( javaElement.getType().isArray() ) {
+                    return new ArrayObjectFactoryImpl(property, getComplexPropertyValues(doc), isSimpleType, javaType);
+                } else {
+                    return new ListObjectFactoryImpl(property, getComplexPropertyValues(doc), isSimpleType, javaType);
+                }
+            }
+        } else {
+            if (isSimpleType) {
+                String value = "";
+                if (rootElement.getChildNodes().getLength() > 0) {
+                    value = rootElement.getChildNodes().item(0).getTextContent();
+                }
+                return new ObjectFactoryImpl(property, value, isSimpleType, javaType);
+            } else {
+                List<Node> nodes = getComplexPropertyValues(doc);
+                Object value = null;
+                if (!nodes.isEmpty()) {
+                    value = nodes.get(0);
+                }
+                return new ObjectFactoryImpl(property, value, isSimpleType, javaType);
+            }
+
+        }
+    }
 
     public ObjectFactory createValueFactory(Property property, Object propertyValue, Class javaType) {
         isSimpleType = isSimpleType(property);
@@ -79,7 +125,7 @@
             }
 
         }
-    }
+    } 
 
     private boolean isSimpleType(Property property) {
         if (property.getXSDType() != null) {
@@ -196,6 +242,31 @@
                 List instances = new ArrayList();
                 for (Node aValue : (List<Node>)propertyValue) {
                     instances.add(mediator.mediate(aValue, sourceDataType, targetDataType, null));
+                }
+                return instances;
+            }
+        }
+    }
+    
+    public class ArrayObjectFactoryImpl extends ObjectFactoryImplBase {
+        public ArrayObjectFactoryImpl(Property property, List<?> propertyValues, boolean isSimpleType, Class javaType) {
+            super(property, propertyValues, isSimpleType, javaType);
+        }
+
+        @SuppressWarnings("unchecked")
+        public Object getInstance() throws ObjectCreationException {
+            if (isSimpleType) {
+                int count = 0;
+                Object values = Array.newInstance(javaType, ((List<Object>)propertyValue).size());
+                for (String aValue : (List<String>)propertyValue) {
+                    Array.set(values, count++, simpleTypeMapper.toJavaObject(property.getXSDType(), aValue, null));
+                }
+                return values;
+            } else {
+                Object instances = Array.newInstance(javaType, ((List<Object>)propertyValue).size());
+                int count = 0;
+                for (Node aValue : (List<Node>)propertyValue) {
+                    Array.set(instances, count++, mediator.mediate(aValue, sourceDataType, targetDataType, null));
                 }
                 return instances;
             }

Modified: incubator/tuscany/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaComponentContextProvider.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaComponentContextProvider.java?rev=584750&r1=584749&r2=584750&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaComponentContextProvider.java (original)
+++ incubator/tuscany/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaComponentContextProvider.java Mon Oct 15 04:45:38 2007
@@ -115,9 +115,9 @@
         if (element != null && !(element.getAnchor() instanceof Constructor) && configuredProperty.getValue() != null) {
             instanceFactoryProvider.getInjectionSites().add(element);
 
-            Class propertyJavaType = JavaIntrospectionHelper.getBaseType(element.getType(), element.getGenericType());
+            //Class propertyJavaType = JavaIntrospectionHelper.getBaseType(element.getType(), element.getGenericType());
             ObjectFactory<?> propertyObjectFactory =
-                createPropertyValueFactory(configuredProperty, configuredProperty.getValue(), propertyJavaType);
+                createPropertyValueFactory(configuredProperty, configuredProperty.getValue(), element);
             instanceFactoryProvider.setObjectFactory(element, propertyObjectFactory);
         }
     }
@@ -341,9 +341,9 @@
         return new WireObjectFactory<B>(interfaze, wire, proxyFactory);
     }
 
-    private ObjectFactory<?> createPropertyValueFactory(ComponentProperty property, Object propertyValue, Class javaType) {
-        return propertyValueFactory.createValueFactory(property, propertyValue, javaType);
-    }
+    private ObjectFactory<?> createPropertyValueFactory(ComponentProperty property, Object propertyValue, JavaElementImpl javaElement) {
+        return propertyValueFactory.createValueFactory(property, propertyValue, javaElement);
+    } 
 
     /**
      * @return the component



---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org