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

svn commit: r575459 - in /incubator/tuscany/java/sca/modules: core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/processor/ databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/ databinding-sdo/src/test/java/org/apac...

Author: rfeng
Date: Thu Sep 13 14:22:09 2007
New Revision: 575459

URL: http://svn.apache.org/viewvc?rev=575459&view=rev
Log:
Improve the SDO context introspection and wrapping support

Added:
    incubator/tuscany/java/sca/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/annotation/DataType.java   (with props)
Modified:
    incubator/tuscany/java/sca/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/processor/DataBindingJavaInterfaceProcessor.java
    incubator/tuscany/java/sca/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOContextHelper.java
    incubator/tuscany/java/sca/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOWrapperHandler.java
    incubator/tuscany/java/sca/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDOWrapperHandlerTestCase.java

Modified: incubator/tuscany/java/sca/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/processor/DataBindingJavaInterfaceProcessor.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/processor/DataBindingJavaInterfaceProcessor.java?rev=575459&r1=575458&r2=575459&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/processor/DataBindingJavaInterfaceProcessor.java (original)
+++ incubator/tuscany/java/sca/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/processor/DataBindingJavaInterfaceProcessor.java Thu Sep 13 14:22:09 2007
@@ -19,6 +19,7 @@
 
 package org.apache.tuscany.sca.core.databinding.processor;
 
+import java.lang.annotation.Annotation;
 import java.lang.reflect.Method;
 import java.util.HashMap;
 import java.util.LinkedList;
@@ -91,17 +92,30 @@
             }
 
             // FIXME: We need a better way to identify simple java types
+            int i = 0;
             for (org.apache.tuscany.sca.interfacedef.DataType<?> d : operation.getInputType().getLogical()) {
                 if (d.getDataBinding() == null) {
                     d.setDataBinding(dataBindingId);
                 }
-                dataBindingRegistry.introspectType(d, method.getAnnotations());
+                for (Annotation a : method.getParameterAnnotations()[i]) {
+                    if (a.annotationType() == org.apache.tuscany.sca.databinding.annotation.DataType.class) {
+                        String value = ((org.apache.tuscany.sca.databinding.annotation.DataType)a).value();
+                        d.setDataBinding(value);
+                    }
+                }
+                dataBindingRegistry.introspectType(d, method.getParameterAnnotations()[i]);
+                i++;
             }
             if (operation.getOutputType() != null) {
                 DataType<?> d = operation.getOutputType();
                 if (d.getDataBinding() == null) {
                     d.setDataBinding(dataBindingId);
                 }
+                org.apache.tuscany.sca.databinding.annotation.DataType dt =
+                    method.getAnnotation(org.apache.tuscany.sca.databinding.annotation.DataType.class);
+                if (dt != null) {
+                    d.setDataBinding(dt.value());
+                }
                 dataBindingRegistry.introspectType(d, method.getAnnotations());
             }
             for (org.apache.tuscany.sca.interfacedef.DataType<?> d : operation.getFaultTypes()) {
@@ -113,9 +127,9 @@
             }
 
             // JIRA: TUSCANY-842
-            if(operation.getDataBinding() == null) {
+            if (operation.getDataBinding() == null) {
                 assignOperationDataBinding(operation);
-            }  
+            }
 
             // FIXME: Do we want to heuristically check the wrapper style?
             // introspectWrapperStyle(operation);
@@ -130,16 +144,16 @@
      *  The method logic assumes the JavaBeans DataBinding is the default 
      */
     private void assignOperationDataBinding(Operation operation) {
-        
+
         String nonDefaultDataBindingName = null;
 
         // Can't use DataType<?> since operation.getInputType() returns: DataType<List<DataType>> 
-        List<DataType> opDataTypes = new LinkedList<DataType>();     
-        
+        List<DataType> opDataTypes = new LinkedList<DataType>();
+
         opDataTypes.addAll(operation.getInputType().getLogical());
         opDataTypes.add(operation.getOutputType());
         opDataTypes.addAll(operation.getFaultTypes());
-        
+
         for (DataType<?> d : opDataTypes) {
             if (d != null) {
                 String dataBinding = d.getDataBinding();
@@ -160,11 +174,10 @@
                 }
             }
         }
-        
+
         // We have a DB worthy of promoting to operation level.
         if (nonDefaultDataBindingName != null) {
             operation.setDataBinding(nonDefaultDataBindingName);
-        }        
+        }
     }
 }
-

Modified: incubator/tuscany/java/sca/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOContextHelper.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOContextHelper.java?rev=575459&r1=575458&r2=575459&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOContextHelper.java (original)
+++ incubator/tuscany/java/sca/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOContextHelper.java Thu Sep 13 14:22:09 2007
@@ -20,9 +20,11 @@
 package org.apache.tuscany.sca.databinding.sdo;
 
 import java.lang.reflect.Method;
+import java.util.List;
 
 import javax.xml.namespace.QName;
 
+import org.apache.tuscany.sca.databinding.DataBinding;
 import org.apache.tuscany.sca.databinding.TransformationContext;
 import org.apache.tuscany.sca.databinding.TransformationException;
 import org.apache.tuscany.sca.interfacedef.DataType;
@@ -45,16 +47,47 @@
             return getDefaultHelperContext();
         }
         HelperContext helperContext = SDOUtil.createHelperContext();
-        Class javaType = context.getTargetDataType().getPhysical();
-        boolean found = register(helperContext, javaType);
-        javaType = context.getSourceDataType().getPhysical();
-        found = found || register(helperContext, javaType);
+
+        boolean found = register(helperContext, context.getTargetDataType());
+        found = register(helperContext, context.getSourceDataType()) || found;
         if (found) {
             return helperContext;
         } else {
             return getDefaultHelperContext();
         }
 
+    }
+
+    /**
+     * @param helperContext
+     * @param dataType
+     * @return
+     */
+    private static boolean register(HelperContext helperContext, DataType dataType) {
+        if (dataType == null) {
+            return false;
+        }
+        String db = dataType.getDataBinding();
+        boolean found = false;
+        if (DataBinding.IDL_INPUT.equals(db) || DataBinding.IDL_OUTPUT.equals(db)
+            || DataBinding.IDL_FAULT.equals(db)
+            || SDODataBinding.NAME.equals(db)) {
+            Class javaType = dataType.getPhysical();
+            found = register(helperContext, javaType);
+            if (dataType.getLogical() instanceof DataType) {
+                DataType logical = (DataType)dataType.getLogical();
+                found = register(helperContext, logical.getPhysical()) || found;
+            }
+            if (dataType.getLogical() instanceof List) {
+                List types = (List)dataType.getLogical();
+                for (Object type : types) {
+                    if (type instanceof DataType) {
+                        found = register(helperContext, ((DataType)type)) || found;
+                    }
+                }
+            }
+        }
+        return found;
     }
 
     /**

Modified: incubator/tuscany/java/sca/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOWrapperHandler.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOWrapperHandler.java?rev=575459&r1=575458&r2=575459&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOWrapperHandler.java (original)
+++ incubator/tuscany/java/sca/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOWrapperHandler.java Thu Sep 13 14:22:09 2007
@@ -28,6 +28,7 @@
 import org.apache.tuscany.sca.databinding.TransformationContext;
 import org.apache.tuscany.sca.databinding.WrapperHandler;
 import org.apache.tuscany.sca.interfacedef.util.ElementInfo;
+import org.apache.tuscany.sca.interfacedef.util.TypeInfo;
 
 import commonj.sdo.DataObject;
 import commonj.sdo.Property;
@@ -36,7 +37,7 @@
 import commonj.sdo.helper.DataFactory;
 import commonj.sdo.helper.HelperContext;
 import commonj.sdo.helper.XMLDocument;
-import commonj.sdo.helper.XMLHelper;
+import commonj.sdo.helper.XSDHelper;
 
 /**
  * SDO Wrapper Handler
@@ -47,12 +48,25 @@
      * @see org.apache.tuscany.sca.databinding.WrapperHandler#create(ElementInfo, TransformationContext)
      */
     public Object create(ElementInfo element, TransformationContext context) {
+        DataObject wrapper = null;
         HelperContext helperContext = SDOContextHelper.getHelperContext(context);
-        QName typeName = element.getType().getQName();
         DataFactory dataFactory = helperContext.getDataFactory();
-        DataObject root = dataFactory.create(typeName.getNamespaceURI(), typeName.getLocalPart());
-        XMLHelper xmlHelper = helperContext.getXMLHelper();
-        return xmlHelper.createDocument(root, element.getQName().getNamespaceURI(), element.getQName().getLocalPart());
+        XSDHelper xsdHelper = helperContext.getXSDHelper();
+        Property prop =
+            xsdHelper.getGlobalProperty(element.getQName().getNamespaceURI(), element.getQName().getLocalPart(), true);
+        if (prop != null) {
+            wrapper = dataFactory.create(prop.getType());
+        } else {
+            TypeInfo type = element.getType();
+            QName typeName = type != null ? type.getQName() : null;
+            if (typeName != null) {
+                wrapper = dataFactory.create(typeName.getNamespaceURI(), typeName.getLocalPart());
+            }
+        }
+        return wrapper;
+//        XMLHelper xmlHelper = helperContext.getXMLHelper();
+//        return xmlHelper.createDocument(wrapper, element.getQName().getNamespaceURI(), element.getQName()
+//            .getLocalPart());
     }
 
     /**
@@ -95,5 +109,4 @@
         }
         return elements;
     }
-
 }

Modified: incubator/tuscany/java/sca/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDOWrapperHandlerTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDOWrapperHandlerTestCase.java?rev=575459&r1=575458&r2=575459&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDOWrapperHandlerTestCase.java (original)
+++ incubator/tuscany/java/sca/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDOWrapperHandlerTestCase.java Thu Sep 13 14:22:09 2007
@@ -20,14 +20,19 @@
 
 import java.util.List;
 
+import javax.xml.namespace.QName;
+
 import junit.framework.TestCase;
 
+import org.apache.tuscany.sca.interfacedef.util.ElementInfo;
 import org.apache.tuscany.sdo.api.SDOUtil;
 
+import commonj.sdo.DataObject;
 import commonj.sdo.helper.HelperContext;
 import commonj.sdo.helper.XMLDocument;
 import commonj.sdo.helper.XMLHelper;
 import commonj.sdo.helper.XSDHelper;
+import commonj.sdo.impl.HelperProvider;
 
 /**
  * @version $Rev$ $Date$
@@ -56,6 +61,15 @@
         XMLDocument document = xmlHelper.load(getClass().getResourceAsStream("/wrapper.xml"));
         List children = handler.getChildren(document);
         assertEquals(5, children.size());
+    }
+    
+    public void testCreate() {
+        HelperContext context = HelperProvider.getDefaultContext();
+        XSDHelper xsdHelper = context.getXSDHelper();
+        xsdHelper.define(getClass().getResourceAsStream("/wrapper.xsd"), null);
+        ElementInfo element = new ElementInfo(new QName("http://www.example.com/wrapper", "op"), null);
+        DataObject wrapper = (DataObject) handler.create(element, null);
+        assertNotNull(wrapper);
     }
 
 }

Added: incubator/tuscany/java/sca/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/annotation/DataType.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/annotation/DataType.java?rev=575459&view=auto
==============================================================================
--- incubator/tuscany/java/sca/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/annotation/DataType.java (added)
+++ incubator/tuscany/java/sca/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/annotation/DataType.java Thu Sep 13 14:22:09 2007
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.databinding.annotation;
+
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.PARAMETER;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+/**
+ * Used to demarcate expected data types for parameters and return type
+ *
+ * @version $Rev$ $Date$
+ */
+@Target( {METHOD, PARAMETER})
+@Retention(RUNTIME)
+public @interface DataType {
+
+    /**
+     * Returns the unique name of the data binding
+     * @return the unique name of the data binding
+     */
+    String value();
+
+    /**
+     * Additional attributes to further describe the data type
+     * @return
+     */
+    String[] attributes() default {};
+
+}

Propchange: incubator/tuscany/java/sca/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/annotation/DataType.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/annotation/DataType.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date



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