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 2010/01/27 18:01:02 UTC

svn commit: r903738 - in /tuscany/sca-java-2.x/trunk: itest/scdl/src/test/java/org/apache/tuscany/sca/itest/scdl/ modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/databinding/ modules/implementation-java-runt...

Author: rfeng
Date: Wed Jan 27 17:01:01 2010
New Revision: 903738

URL: http://svn.apache.org/viewvc?rev=903738&view=rev
Log:
Refactor the databinding introspection to tuscany-implementation-java-runtime to avoid deployment time dependency 

Added:
    tuscany/sca-java-2.x/trunk/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/databinding/
    tuscany/sca-java-2.x/trunk/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/databinding/PropertyDataTypeProcessor.java   (with props)
    tuscany/sca-java-2.x/trunk/modules/implementation-java-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.implementation.java.introspect.JavaClassVisitor
Modified:
    tuscany/sca-java-2.x/trunk/itest/scdl/src/test/java/org/apache/tuscany/sca/itest/scdl/ValidateDependenciesTestCase.java
    tuscany/sca-java-2.x/trunk/modules/implementation-java/META-INF/MANIFEST.MF
    tuscany/sca-java-2.x/trunk/modules/implementation-java/pom.xml
    tuscany/sca-java-2.x/trunk/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/AbstractPropertyProcessor.java
    tuscany/sca-java-2.x/trunk/modules/implementation-java/src/main/resources/META-INF/services/org.apache.tuscany.sca.implementation.java.introspect.JavaClassVisitor

Modified: tuscany/sca-java-2.x/trunk/itest/scdl/src/test/java/org/apache/tuscany/sca/itest/scdl/ValidateDependenciesTestCase.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/itest/scdl/src/test/java/org/apache/tuscany/sca/itest/scdl/ValidateDependenciesTestCase.java?rev=903738&r1=903737&r2=903738&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/itest/scdl/src/test/java/org/apache/tuscany/sca/itest/scdl/ValidateDependenciesTestCase.java (original)
+++ tuscany/sca-java-2.x/trunk/itest/scdl/src/test/java/org/apache/tuscany/sca/itest/scdl/ValidateDependenciesTestCase.java Wed Jan 27 17:01:01 2010
@@ -44,16 +44,13 @@
  * tuscany-common-java-2.0-SNAPSHOT.jar
  * tuscany-common-xml-2.0-SNAPSHOT.jar
  * tuscany-contribution-2.0-SNAPSHOT.jar
- * tuscany-databinding-2.0-SNAPSHOT.jar
  * tuscany-deployment-2.0-SNAPSHOT.jar
  * tuscany-extensibility-2.0-SNAPSHOT.jar
  * tuscany-implementation-java-2.0-SNAPSHOT.jar
  * tuscany-interface-java-2.0-SNAPSHOT.jar
  * tuscany-monitor-2.0-SNAPSHOT.jar
  * tuscany-sca-api-2.0-SNAPSHOT.jar
- * tuscany-xsd-2.0-SNAPSHOT.jar
  * wstx-asl-3.2.4.jar
- * XmlSchema-1.4.2.jar
  * 
  * TODO: WS binding drags in all runtime
  */
@@ -66,6 +63,6 @@
         Assert.assertTrue(dependenciesDir.exists());
         
         File[] dependencyFiles = dependenciesDir.listFiles();
-        Assert.assertEquals(23, dependencyFiles.length);
+        Assert.assertEquals(20, dependencyFiles.length);
     }
 }

Added: tuscany/sca-java-2.x/trunk/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/databinding/PropertyDataTypeProcessor.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/databinding/PropertyDataTypeProcessor.java?rev=903738&view=auto
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/databinding/PropertyDataTypeProcessor.java (added)
+++ tuscany/sca-java-2.x/trunk/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/databinding/PropertyDataTypeProcessor.java Wed Jan 27 17:01:01 2010
@@ -0,0 +1,83 @@
+/*
+ * 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.implementation.java.databinding;
+
+import org.apache.tuscany.sca.assembly.Property;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.core.UtilityExtensionPoint;
+import org.apache.tuscany.sca.databinding.Mediator;
+import org.apache.tuscany.sca.implementation.java.IntrospectionException;
+import org.apache.tuscany.sca.implementation.java.JavaElementImpl;
+import org.apache.tuscany.sca.implementation.java.JavaImplementation;
+import org.apache.tuscany.sca.implementation.java.introspect.BaseJavaClassVisitor;
+import org.apache.tuscany.sca.implementation.java.introspect.JavaIntrospectionHelper;
+import org.apache.tuscany.sca.interfacedef.DataType;
+import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl;
+import org.apache.tuscany.sca.interfacedef.util.JavaXMLMapper;
+import org.apache.tuscany.sca.interfacedef.util.XMLType;
+
+/**
+ * 
+ */
+public class PropertyDataTypeProcessor extends BaseJavaClassVisitor {
+    private Mediator mediator;
+
+    /**
+     * @param registry
+     */
+    public PropertyDataTypeProcessor(ExtensionPointRegistry registry) {
+        super(registry);
+        UtilityExtensionPoint utilityExtensionPoint = registry.getExtensionPoint(UtilityExtensionPoint.class);
+        this.mediator = utilityExtensionPoint.getUtility(Mediator.class);
+    }
+
+    /**
+     * Introspect the property 
+     * @param javaElement
+     * @return
+     */
+    private DataType<?> introspect(Property property, JavaElementImpl javaElement) {
+        XMLType xmlType = new XMLType(property.getXSDElement(), property.getXSDType());
+        DataType<XMLType> dt =
+            new DataTypeImpl<XMLType>(null, javaElement.getType(), javaElement.getGenericType(), xmlType);
+        mediator.getDataBindings().introspectType(dt, null);
+        return dt;
+    }
+
+    @Override
+    public <T> void visitEnd(Class<T> clazz, JavaImplementation type) throws IntrospectionException {
+        for (Property property : type.getProperties()) {
+            String name = property.getName();
+            JavaElementImpl element = type.getPropertyMembers().get(name);
+            DataType dt = introspect(property, element);
+            property.setDataType(dt);
+            if (dt.getLogical() instanceof XMLType) {
+                XMLType xmlType = (XMLType)dt.getLogical();
+                property.setXSDType(xmlType.getTypeName());
+                property.setXSDElement(xmlType.getElementName());
+            } else {
+                Class<?> baseType = JavaIntrospectionHelper.getBaseType(element.getType(), element.getGenericType());
+                property.setXSDType(JavaXMLMapper.getXMLType(baseType));
+            }
+        }
+        super.visitEnd(clazz, type);
+    }
+
+}

Propchange: tuscany/sca-java-2.x/trunk/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/databinding/PropertyDataTypeProcessor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: tuscany/sca-java-2.x/trunk/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/databinding/PropertyDataTypeProcessor.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: tuscany/sca-java-2.x/trunk/modules/implementation-java-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.implementation.java.introspect.JavaClassVisitor
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/implementation-java-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.implementation.java.introspect.JavaClassVisitor?rev=903738&view=auto
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/implementation-java-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.implementation.java.introspect.JavaClassVisitor (added)
+++ tuscany/sca-java-2.x/trunk/modules/implementation-java-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.implementation.java.introspect.JavaClassVisitor Wed Jan 27 17:01:01 2010
@@ -0,0 +1,20 @@
+# Licensed to the Apache Software Foundation 
+# 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 
+# "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.
+# 
+# NOTE: The ranking attribute is important for the JavaClassVistors 
+# Some visitors need to be called after the others 
+org.apache.tuscany.sca.implementation.java.databinding.PropertyDataTypeProcessor;ranking=750

Modified: tuscany/sca-java-2.x/trunk/modules/implementation-java/META-INF/MANIFEST.MF
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/implementation-java/META-INF/MANIFEST.MF?rev=903738&r1=903737&r2=903738&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/implementation-java/META-INF/MANIFEST.MF (original)
+++ tuscany/sca-java-2.x/trunk/modules/implementation-java/META-INF/MANIFEST.MF Wed Jan 27 17:01:01 2010
@@ -27,15 +27,11 @@
  org.apache.tuscany.sca.contribution.processor;version="2.0.0",
  org.apache.tuscany.sca.contribution.resolver;version="2.0.0",
  org.apache.tuscany.sca.core;version="2.0.0",
- org.apache.tuscany.sca.databinding;version="2.0.0",
- org.apache.tuscany.sca.databinding.impl;version="2.0.0",
- org.apache.tuscany.sca.databinding.util;version="2.0.0",
  org.apache.tuscany.sca.definitions;version="2.0.0";resolution:=optional,
  org.apache.tuscany.sca.extensibility;version="2.0.0",
  org.apache.tuscany.sca.implementation.java;version="2.0.0",
  org.apache.tuscany.sca.implementation.java.introspect;version="2.0.0",
  org.apache.tuscany.sca.interfacedef;version="2.0.0",
- org.apache.tuscany.sca.interfacedef.impl;version="2.0.0",
  org.apache.tuscany.sca.interfacedef.java;version="2.0.0",
  org.apache.tuscany.sca.interfacedef.java.impl;version="2.0.0";resolution:=optional,
  org.apache.tuscany.sca.interfacedef.util;version="2.0.0",

Modified: tuscany/sca-java-2.x/trunk/modules/implementation-java/pom.xml
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/implementation-java/pom.xml?rev=903738&r1=903737&r2=903738&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/implementation-java/pom.xml (original)
+++ tuscany/sca-java-2.x/trunk/modules/implementation-java/pom.xml Wed Jan 27 17:01:01 2010
@@ -40,13 +40,7 @@
             <artifactId>tuscany-interface-java</artifactId>
             <version>2.0-SNAPSHOT</version>
         </dependency>
-        
-        <dependency>
-            <groupId>org.apache.tuscany.sca</groupId>
-            <artifactId>tuscany-databinding</artifactId>
-            <version>2.0-SNAPSHOT</version>
-        </dependency>        
-
+ 
         <dependency>
             <groupId>org.apache.tuscany.sca</groupId>
             <artifactId>tuscany-sca-api</artifactId>

Modified: tuscany/sca-java-2.x/trunk/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/AbstractPropertyProcessor.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/AbstractPropertyProcessor.java?rev=903738&r1=903737&r2=903738&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/AbstractPropertyProcessor.java (original)
+++ tuscany/sca-java-2.x/trunk/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/AbstractPropertyProcessor.java Wed Jan 27 17:01:01 2010
@@ -29,18 +29,12 @@
 
 import org.apache.tuscany.sca.assembly.Property;
 import org.apache.tuscany.sca.core.ExtensionPointRegistry;
-import org.apache.tuscany.sca.core.UtilityExtensionPoint;
-import org.apache.tuscany.sca.databinding.Mediator;
 import org.apache.tuscany.sca.implementation.java.IntrospectionException;
 import org.apache.tuscany.sca.implementation.java.JavaElementImpl;
 import org.apache.tuscany.sca.implementation.java.JavaImplementation;
 import org.apache.tuscany.sca.implementation.java.JavaParameterImpl;
 import org.apache.tuscany.sca.implementation.java.introspect.BaseJavaClassVisitor;
 import org.apache.tuscany.sca.implementation.java.introspect.JavaIntrospectionHelper;
-import org.apache.tuscany.sca.interfacedef.DataType;
-import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl;
-import org.apache.tuscany.sca.interfacedef.util.JavaXMLMapper;
-import org.apache.tuscany.sca.interfacedef.util.XMLType;
 
 /**
  * Base class for ImplementationProcessors that handle annotations that add
@@ -50,26 +44,10 @@
  */
 public abstract class AbstractPropertyProcessor<A extends Annotation> extends BaseJavaClassVisitor {
     private final Class<A> annotationClass;
-    private Mediator mediator;
 
     protected AbstractPropertyProcessor(ExtensionPointRegistry registry, Class<A> annotationClass) {
         super(registry);
         this.annotationClass = annotationClass;
-        UtilityExtensionPoint utilityExtensionPoint = registry.getExtensionPoint(UtilityExtensionPoint.class);
-        this.mediator = utilityExtensionPoint.getUtility(Mediator.class);
-    }
-    
-    /**
-     * Introspect the property 
-     * @param javaElement
-     * @return
-     */
-    private DataType<?> introspect(Property property, JavaElementImpl javaElement) {
-        XMLType xmlType = new XMLType(property.getXSDElement(), property.getXSDType());
-        DataType<XMLType> dt =
-            new DataTypeImpl<XMLType>(null, javaElement.getType(), javaElement.getGenericType(), xmlType);
-        mediator.getDataBindings().introspectType(dt, null);
-        return dt;
     }
     
     private static boolean removeProperty(JavaElementImpl prop, JavaImplementation type) {
@@ -219,28 +197,12 @@
             properties.put(name, parameter);
         }
     }
-
-    protected abstract String getName(A annotation);
-    protected abstract boolean getRequired(A annotation);
-
-    protected abstract void initProperty(Property property, A annotation) throws IntrospectionException;
-
+    
     protected Property createProperty(String name, JavaElementImpl element) throws IntrospectionException {
 
         Property property = assemblyFactory.createProperty();
         property.setName(name);
         
-        DataType dt = introspect(property, element);
-        property.setDataType(dt);
-        if(dt.getLogical() instanceof XMLType) {
-            XMLType xmlType = (XMLType) dt.getLogical();
-            property.setXSDType(xmlType.getTypeName());
-            property.setXSDElement(xmlType.getElementName());
-        } else {
-            Class<?> baseType = JavaIntrospectionHelper.getBaseType(element.getType(), element.getGenericType());
-            property.setXSDType(JavaXMLMapper.getXMLType(baseType));
-        }
-
         Class<?> javaType = element.getType();
         if (javaType.isArray() || Collection.class.isAssignableFrom(javaType)) {
             property.setMany(true);
@@ -249,4 +211,10 @@
 
     }
 
+    protected abstract String getName(A annotation);
+    protected abstract boolean getRequired(A annotation);
+
+    protected abstract void initProperty(Property property, A annotation) throws IntrospectionException;
+
+
 }

Modified: tuscany/sca-java-2.x/trunk/modules/implementation-java/src/main/resources/META-INF/services/org.apache.tuscany.sca.implementation.java.introspect.JavaClassVisitor
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/implementation-java/src/main/resources/META-INF/services/org.apache.tuscany.sca.implementation.java.introspect.JavaClassVisitor?rev=903738&r1=903737&r2=903738&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/implementation-java/src/main/resources/META-INF/services/org.apache.tuscany.sca.implementation.java.introspect.JavaClassVisitor (original)
+++ tuscany/sca-java-2.x/trunk/modules/implementation-java/src/main/resources/META-INF/services/org.apache.tuscany.sca.implementation.java.introspect.JavaClassVisitor Wed Jan 27 17:01:01 2010
@@ -17,17 +17,17 @@
 # 
 # NOTE: The ranking attribute is important for the JavaClassVistors 
 # Some visitors need to be called after the others 
-org.apache.tuscany.sca.implementation.java.introspect.impl.ConstructorProcessor;ranking=200
-org.apache.tuscany.sca.implementation.java.introspect.impl.AllowsPassByReferenceProcessor;ranking=190
-org.apache.tuscany.sca.implementation.java.introspect.impl.ComponentNameProcessor;ranking=180
-org.apache.tuscany.sca.implementation.java.introspect.impl.ContextProcessor;ranking=170
-org.apache.tuscany.sca.implementation.java.introspect.impl.DestroyProcessor;ranking=160
-org.apache.tuscany.sca.implementation.java.introspect.impl.EagerInitProcessor;ranking=150
-org.apache.tuscany.sca.implementation.java.introspect.impl.InitProcessor;ranking=140
-org.apache.tuscany.sca.implementation.java.introspect.impl.PropertyProcessor;ranking=130
-org.apache.tuscany.sca.implementation.java.introspect.impl.ReferenceProcessor;ranking=120
-org.apache.tuscany.sca.implementation.java.introspect.impl.ResourceProcessor;ranking=110
-org.apache.tuscany.sca.implementation.java.introspect.impl.ScopeProcessor;ranking=100
-org.apache.tuscany.sca.implementation.java.introspect.impl.ServiceProcessor;ranking=90
-org.apache.tuscany.sca.implementation.java.introspect.impl.HeuristicPojoProcessor;ranking=80
-org.apache.tuscany.sca.implementation.java.introspect.impl.PolicyProcessor;ranking=70
+org.apache.tuscany.sca.implementation.java.introspect.impl.ConstructorProcessor;ranking=2000
+org.apache.tuscany.sca.implementation.java.introspect.impl.AllowsPassByReferenceProcessor;ranking=1900
+org.apache.tuscany.sca.implementation.java.introspect.impl.ComponentNameProcessor;ranking=1800
+org.apache.tuscany.sca.implementation.java.introspect.impl.ContextProcessor;ranking=1700
+org.apache.tuscany.sca.implementation.java.introspect.impl.DestroyProcessor;ranking=1600
+org.apache.tuscany.sca.implementation.java.introspect.impl.EagerInitProcessor;ranking=1500
+org.apache.tuscany.sca.implementation.java.introspect.impl.InitProcessor;ranking=1400
+org.apache.tuscany.sca.implementation.java.introspect.impl.PropertyProcessor;ranking=1300
+org.apache.tuscany.sca.implementation.java.introspect.impl.ReferenceProcessor;ranking=1200
+org.apache.tuscany.sca.implementation.java.introspect.impl.ResourceProcessor;ranking=1100
+org.apache.tuscany.sca.implementation.java.introspect.impl.ScopeProcessor;ranking=1000
+org.apache.tuscany.sca.implementation.java.introspect.impl.ServiceProcessor;ranking=900
+org.apache.tuscany.sca.implementation.java.introspect.impl.HeuristicPojoProcessor;ranking=800
+org.apache.tuscany.sca.implementation.java.introspect.impl.PolicyProcessor;ranking=700