You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tuscany.apache.org by "Jiang Chen (JIRA)" <tu...@ws.apache.org> on 2007/09/27 22:59:50 UTC

[jira] Commented: (TUSCANY-925) Complex properties not supported

    [ https://issues.apache.org/jira/browse/TUSCANY-925?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12530838 ] 

Jiang Chen commented on TUSCANY-925:
------------------------------------

I assume this implementation is in the org\apache\tuscany\databinding\javabeans package.

I tried to inject to a complex pojo property. The complex property type happens to have an array member. The type of the array is yet another complex type. I was getting mapping errors and I think it may be a problem in XML2JavaBeanTransformer.

In both the setFieldValue and the setFieldValueUsingSetter methods, when the field type is Array, it probably should convert all the child elements of the field value to Java objects and add them to the field value array. The current implementation tries to convert the field value itself  (the parent of the array elements) yet using the component type of the array. 

The following fix seems to have fixed my problem. Didn't do other testing though.

    private void setFieldValue(Object javaInstance,
                               Field javaField,
                               T fieldValue,
                               Map<Field, List<Object>> arrayFields,
                               TransformationContext context) throws IllegalAccessException {
        Class<?> javaFieldType = (Class<?>) javaField.getType();

        if (javaFieldType.isArray()) {
            Class<?> componentType = javaFieldType.getComponentType();
            List<Object> fldValueArray = arrayFields.get(javaField);
            if (fldValueArray == null) {
                fldValueArray = new ArrayList<Object>();
                arrayFields.put(javaField, fldValueArray);
            }
            
            /*********************** Fix Starts *************************/
            // Old code commented out:
            // fldValueArray.add(createJavaObject(fieldValue, componentType, context));
            
            // New code added:
            List<T> childElements = getChildElements(fieldValue);
            
            for (int i = 0; i < childElements.size(); i++) 
            	 if (!isTextElement(childElements.get(i))) fldValueArray.add(createJavaObject(childElements.get(i), componentType, context));
            /*********************** Fix Ends *************************/            
        } else {
            javaField.setAccessible(true);
            javaField.set(javaInstance, createJavaObject(fieldValue, javaFieldType, context));
        }
    }

    private void setFieldValueUsingSetter(Class javaType,
                                          Object javaInstance,
                                          String fieldName,
                                          T fieldValue,
                                          Map<Method, List<Object>> arraySetters,
                                          TransformationContext context) throws IllegalAccessException,
                                                                        InvocationTargetException {
        char firstChar = Character.toUpperCase(fieldName.charAt(0));
        StringBuilder methodName = new StringBuilder(SET + fieldName);
        methodName.setCharAt(SET.length(), firstChar);
        boolean methodNotFound = true;

        for (int methodCount = 0; methodNotFound && methodCount < javaType.getMethods().length; ++methodCount) {
            Method aMethod = javaType.getMethods()[methodCount];
            if (aMethod.getName().equals(methodName.toString())
                    && aMethod.getParameterTypes().length == 1) {
                Class<?> paramType = aMethod.getParameterTypes()[0];

                if (paramType.isArray()) {
                    Class<?> componentType = paramType.getComponentType();
                    List<Object> setterValueArray = arraySetters.get(aMethod);
                    if (setterValueArray == null) {
                        setterValueArray = new ArrayList<Object>();
                        arraySetters.put(aMethod, setterValueArray);
                    }
                    
                    /*********************** Fix Starts *************************/
                    // Old code commented out:
                    // setterValueArray.add(createJavaObject(fieldValue, componentType, context));
                    
                    // New code added:
                    List<T> childElements = getChildElements(fieldValue);
                    
                    for (int i = 0; i < childElements.size(); i++)
                    	 if (!isTextElement(childElements.get(i))) setterValueArray.add(createJavaObject(childElements.get(i), componentType, context));
                    /*********************** Fix Ends *************************/     
                } else {
                    aMethod.invoke(javaInstance, new Object[] {createJavaObject(fieldValue,
                                                                                 paramType,
                                                                                 context)});
                }
                methodNotFound = false;
            }
        }

        if (methodNotFound) {
            XML2JavaMapperException xml2JavaEx =
                    new XML2JavaMapperException("No field or setter method to configure xml data");
            xml2JavaEx.setJavaFieldName(fieldName);
            xml2JavaEx.setJavaType(javaType);
            throw xml2JavaEx;
        }
    }

> Complex properties not supported
> --------------------------------
>
>                 Key: TUSCANY-925
>                 URL: https://issues.apache.org/jira/browse/TUSCANY-925
>             Project: Tuscany
>          Issue Type: Bug
>          Components: Java SCA Core Runtime
>    Affects Versions: Java-SCA-M2
>            Reporter: Brent Daniel
>            Assignee: Venkatakrishnan
>             Fix For: Java-SCA-Next
>
>
> This may be intented to be covered in TUSCANY-773, but it was not clear to me. Complex properties are currently not supported by the tuscany runtime. 
> Caused by: java.lang.IllegalArgumentException: Complex property is not supported.
> 	at org.apache.tuscany.core.property.SimplePropertyObjectFactory.getInstance(SimplePropertyObjectFactory.java:56)

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


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