tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From svkr...@apache.org
Subject svn commit: r502156 - in /incubator/tuscany/java/sca/kernel/spi/src: main/java/org/apache/tuscany/spi/databinding/extension/ main/java/org/apache/tuscany/spi/implementation/java/ test/java/org/apache/tuscany/spi/databinding/extension/
Date Thu, 01 Feb 2007 08:18:22 GMT
Author: svkrish
Date: Thu Feb  1 00:18:21 2007
New Revision: 502156

URL: http://svn.apache.org/viewvc?view=rev&rev=502156
Log:
Refactored JavaBeans2XML mappings to JavaBeansDataBinding, added support for picking up databinding
information specified as annotations for Java Component Implementation Properties

Removed:
    incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/extension/XML2JavaMapperException.java
    incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/extension/XMLType2JavaTransformer.java
    incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/extension/XMLTypeMapperExtension.java
    incubator/tuscany/java/sca/kernel/spi/src/test/java/org/apache/tuscany/spi/databinding/extension/XMLTypeMapperExtensionTestCase.java
Modified:
    incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/extension/SimpleTypeMapperExtension.java
    incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/AbstractPropertyProcessor.java

Modified: incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/extension/SimpleTypeMapperExtension.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/extension/SimpleTypeMapperExtension.java?view=diff&rev=502156&r1=502155&r2=502156
==============================================================================
--- incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/extension/SimpleTypeMapperExtension.java
(original)
+++ incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/extension/SimpleTypeMapperExtension.java
Thu Feb  1 00:18:21 2007
@@ -38,6 +38,11 @@
 
 public class SimpleTypeMapperExtension<T> extends XSDDataTypeConverter implements
         SimpleTypeMapper<T> {
+    
+    public static final int BASE64_ENCODING = 1;
+    public static final int HEXBIN_ENCODING = 2;
+    private int byteEncoding  = BASE64_ENCODING;
+    
     public static final String SET = "set";
 
     public static final Map<Class, String> JAVA2XML = new HashMap<Class, String>();
@@ -392,9 +397,16 @@
         } else if (obj instanceof XMLGregorianCalendar) {
             return ((XMLGregorianCalendar) obj).toXMLFormat();
         } else if (obj instanceof byte[]) {
-            if (simpleType.getQName().equals(XSD_BASE64)) {
+            if ( simpleType != null ) {
+                if ( simpleType.getQName().equals(XSD_BASE64) ) {
+                    byteEncoding = BASE64_ENCODING;
+                } else if ( simpleType.getQName().equals(XSD_HEXBIN) ) {
+                    byteEncoding = BASE64_ENCODING;
+                }
+            }
+            if (byteEncoding == BASE64_ENCODING) {
                 return printBase64Binary((byte[]) obj);
-            } else if (simpleType.getQName().equals(XSD_HEXBIN)) {
+            } else if (byteEncoding == HEXBIN_ENCODING) {
                 return printHexBinary((byte[]) obj);
             }
         } else if (obj instanceof QName) {
@@ -424,10 +436,16 @@
         if (simpleType.isSimpleType()) {
             return toSimpleJavaObject(simpleType, getText(xmlNode), context);
         } else {
-            XML2JavaMapperException xml2JavaEx =
-                    new XML2JavaMapperException("Complex XML Types not supported by SimpleTypeMapperExtension");
-            throw xml2JavaEx;
+            throw new IllegalArgumentException("Complex XML Types not supported by SimpleTypeMapperExtension");
         }
+    }
+
+    public int getByteEncoding() {
+        return byteEncoding;
+    }
+
+    public void setByteEncoding(int byteEncoding) {
+        this.byteEncoding = byteEncoding;
     }
 
 }

Modified: incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/AbstractPropertyProcessor.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/AbstractPropertyProcessor.java?view=diff&rev=502156&r1=502155&r2=502156
==============================================================================
--- incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/AbstractPropertyProcessor.java
(original)
+++ incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/AbstractPropertyProcessor.java
Thu Feb  1 00:18:21 2007
@@ -26,7 +26,9 @@
 import java.util.Collection;
 import java.util.Map;
 
+import org.apache.tuscany.api.annotation.DataType;
 import org.apache.tuscany.spi.component.CompositeComponent;
+import org.apache.tuscany.spi.databinding.DataBinding;
 import org.apache.tuscany.spi.deployer.DeploymentContext;
 
 /**
@@ -80,6 +82,11 @@
             property.setMany(true);
         }
         
+        //add databinding available as annotations, as extensions
+        DataType propertyDataBinding = method.getAnnotation(DataType.class);
+        if (propertyDataBinding != null) {
+            property.getExtensions().put(DataBinding.class.getName(), propertyDataBinding.name());
+        }
         initProperty(property, annotation, parent, context);
         properties.put(name, property);
     }
@@ -88,6 +95,7 @@
                            Field field,
                            PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>
type,
                            DeploymentContext context) throws ProcessingException {
+        
         A annotation = field.getAnnotation(annotationClass);
         if (annotation == null) {
             return;
@@ -110,6 +118,13 @@
         if (javaType.isArray() || Collection.class.isAssignableFrom(javaType)) {
             property.setMany(true);
         }        
+        
+        //add databinding available as annotations, as extensions
+        DataType propertyDataBinding = field.getAnnotation(DataType.class);
+        if (propertyDataBinding != null) {
+            property.getExtensions().put(DataBinding.class.getName(), propertyDataBinding.name());
+        }
+
         initProperty(property, annotation, parent, context);
         properties.put(name, property);
     }
@@ -126,27 +141,40 @@
         for (int i = 0; i < params.length; i++) {
             Class<?> param = params[i];
             Annotation[] paramAnnotations = annotations[i];
+            JavaMappedProperty<?> property = null;
+            DataType propertyDataBinding = null;
+            A monitorAnnot = null;
+            String name = null;
             for (Annotation annotation : paramAnnotations) {
                 if (annotation.annotationType().equals(annotationClass)) {
                     if (definition == null) {
                         definition = new ConstructorDefinition<T>(constructor);
                         type.setConstructorDefinition(definition);
                     }
-                    A monitorAnnot = annotationClass.cast(annotation);
-                    String name = getName(monitorAnnot);
+                    monitorAnnot = annotationClass.cast(annotation);
+                    name = getName(monitorAnnot);
                     if (name == null || name.length() == 0) {
                         name = param.getName();
                     }
                     
                     Class<?> baseType = getBaseType(param, constructor.getGenericParameterTypes()[i]);
-                    JavaMappedProperty<?> property = createProperty(name, baseType,
constructor);
+                    property = createProperty(name, baseType, constructor);
                     if (param.isArray() || Collection.class.isAssignableFrom(param)) {
                         property.setMany(true);
                     }
-                    initProperty(property, monitorAnnot, parent, context);
-                    properties.put(name, property);
-                    service.addName(definition.getInjectionNames(), i, name);
+                } else if (annotation.annotationType().equals(DataType.class)) {
+                    propertyDataBinding = DataType.class.cast(annotation);
+                }
+            }
+            //if there has been a databinding annotation along with a property annotation
then 
+            //add that information to the property
+            if (property != null && propertyDataBinding != null) {
+                if (propertyDataBinding != null) {
+                    property.getExtensions().put(DataBinding.class.getName(), propertyDataBinding.name());
                 }
+                initProperty(property, monitorAnnot, parent, context);
+                properties.put(name, property);
+                service.addName(definition.getInjectionNames(), i, name);
             }
         }
     }



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


Mime
View raw message