tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rf...@apache.org
Subject svn commit: r957343 - in /tuscany/sca-java-2.x/trunk/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java: impl/JavaClassIntrospectorImpl.java introspect/JavaIntrospectionHelper.java
Date Wed, 23 Jun 2010 21:07:58 GMT
Author: rfeng
Date: Wed Jun 23 21:07:57 2010
New Revision: 957343

URL: http://svn.apache.org/viewvc?rev=957343&view=rev
Log:
Allow package fields to be used for SCA reference/property

Modified:
    tuscany/sca-java-2.x/trunk/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/impl/JavaClassIntrospectorImpl.java
    tuscany/sca-java-2.x/trunk/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/JavaIntrospectionHelper.java

Modified: tuscany/sca-java-2.x/trunk/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/impl/JavaClassIntrospectorImpl.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/impl/JavaClassIntrospectorImpl.java?rev=957343&r1=957342&r2=957343&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/impl/JavaClassIntrospectorImpl.java
(original)
+++ tuscany/sca-java-2.x/trunk/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/impl/JavaClassIntrospectorImpl.java
Wed Jun 23 21:07:57 2010
@@ -84,17 +84,11 @@ public class JavaClassIntrospectorImpl {
                 }
             }
 
-            Set<Field> fields = JavaIntrospectionHelper.getAllPublicAndProtectedFields(clazz,
true);
+            Set<Field> fields = JavaIntrospectionHelper.getInjectableFields(clazz,
true);
             for (Field field : fields) {
                 visitor.visitField(field, type);
             }
 
-            // Check if any private fields have illegal annotations that should be raised
as errors
-            Set<Field> privateFields = JavaIntrospectionHelper.getPrivateFields(clazz);
-            for (Field field : privateFields) {
-                visitor.visitField(field, type);
-            }
-
             Set<Method> methods = JavaIntrospectionHelper.getAllUniquePublicProtectedMethods(clazz,
true);
             for (Method method : methods) {
                 visitor.visitMethod(method, type);

Modified: tuscany/sca-java-2.x/trunk/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/JavaIntrospectionHelper.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/JavaIntrospectionHelper.java?rev=957343&r1=957342&r2=957343&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/JavaIntrospectionHelper.java
(original)
+++ tuscany/sca-java-2.x/trunk/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/JavaIntrospectionHelper.java
Wed Jun 23 21:07:57 2010
@@ -50,7 +50,7 @@ import org.oasisopen.sca.ServiceReferenc
  */
 public final class JavaIntrospectionHelper {
     private static final Logger logger = Logger.getLogger(JavaIntrospectionHelper.class.getName());
-    private static final Class[] EMPTY_CLASS_ARRY = new Class[0];
+    private static final Class<?>[] EMPTY_CLASS_ARRY = new Class[0];
 
     /**
      * Hide the constructor
@@ -62,7 +62,7 @@ public final class JavaIntrospectionHelp
      * Returns a collection of public, and protected fields declared by a class
      * or one of its supertypes
      */
-    public static Set<Field> getAllPublicAndProtectedFields(Class clazz, boolean validating)
{
+    public static Set<Field> getAllPublicAndProtectedFields(Class<?> clazz, boolean
validating) {
         return getAllPublicAndProtectedFields(clazz, new HashSet<Field>(), validating);
     }
 
@@ -78,7 +78,7 @@ public final class JavaIntrospectionHelp
      * Recursively evaluates the type hierarchy to return all fields that are
      * public or protected
      */
-    private static Set<Field> getAllPublicAndProtectedFields(Class clazz, Set<Field>
fields, boolean validating) {
+    private static Set<Field> getAllPublicAndProtectedFields(Class<?> clazz,
Set<Field> fields, boolean validating) {
         if (clazz == null || clazz.isArray() || Object.class.equals(clazz)) {
             return fields;
         }
@@ -86,7 +86,8 @@ public final class JavaIntrospectionHelp
         Field[] declaredFields = clazz.getDeclaredFields();
         for (final Field field : declaredFields) {
             int modifiers = field.getModifiers();
-            if ((Modifier.isPublic(modifiers) || Modifier.isProtected(modifiers)) &&
!Modifier.isStatic(modifiers)) {
+            // The field should be non-final and non-static
+            if ((Modifier.isPublic(modifiers) || Modifier.isProtected(modifiers)) &&
!Modifier.isStatic(modifiers) && !Modifier.isFinal(modifiers)) {
                 // Allow privileged access to set accessibility. Requires ReflectPermission
                 // in security policy.
                 AccessController.doPrivileged(new PrivilegedAction<Object>() {
@@ -104,6 +105,46 @@ public final class JavaIntrospectionHelp
         }
         return fields;
     }
+    
+    /**
+     * Returns a collection of injectable fields (neither final or static) declared by a
class
+     * or one of its supertypes
+     */
+    public static Set<Field> getInjectableFields(Class<?> clazz, boolean validating)
{
+        return getInjectableFields(clazz, new HashSet<Field>(), validating);
+    }
+    
+    /**
+     * Recursively evaluates the type hierarchy to return all fields that are
+     * not static or final
+     */
+    private static Set<Field> getInjectableFields(Class<?> clazz, Set<Field>
fields, boolean validating) {
+        if (clazz == null || clazz.isArray() || Object.class.equals(clazz)) {
+            return fields;
+        }
+        fields = getInjectableFields(clazz.getSuperclass(), fields, validating);
+        Field[] declaredFields = clazz.getDeclaredFields();
+        for (final Field field : declaredFields) {
+            int modifiers = field.getModifiers();
+            // The field should be non-final and non-static
+            if (!Modifier.isStatic(modifiers) && !Modifier.isFinal(modifiers)) {
+                // Allow privileged access to set accessibility. Requires ReflectPermission
+                // in security policy.
+                AccessController.doPrivileged(new PrivilegedAction<Object>() {
+                    public Object run() {
+                        field.setAccessible(true); // ignore Java accessibility
+                        return null;
+                    }
+                });
+                fields.add(field);
+            } else {
+                if (validating) {
+                    checkInvalidAnnotations(field);
+                }
+            }
+        }
+        return fields;
+    }
 
     /**
      * Returns a collection of public and protected methods declared by a class
@@ -113,14 +154,14 @@ public final class JavaIntrospectionHelp
      * cached. It is assumed that this method will be used during a
      * configuration phase.
      */
-    public static Set<Method> getAllUniquePublicProtectedMethods(Class clazz, boolean
validating) {
+    public static Set<Method> getAllUniquePublicProtectedMethods(Class<?> clazz,
boolean validating) {
         return getAllUniqueMethods(clazz, new HashSet<Method>(), validating);
     }
 
     /**
      * Recursively evaluates the type hierarchy to return all unique methods
      */
-    private static Set<Method> getAllUniqueMethods(Class pClass, Set<Method>
methods, boolean validating) {
+    private static Set<Method> getAllUniqueMethods(Class<?> pClass, Set<Method>
methods, boolean validating) {
         if (pClass == null || pClass.isArray() || Object.class.equals(pClass)) {
             return methods;
         }



Mime
View raw message