cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ff...@apache.org
Subject svn commit: r539386 - in /incubator/cxf/trunk/common/common/src: main/java/org/apache/cxf/common/annotation/ main/java/org/apache/cxf/common/injection/ test/java/org/apache/cxf/common/injection/
Date Fri, 18 May 2007 11:12:47 GMT
Author: ffang
Date: Fri May 18 04:12:46 2007
New Revision: 539386

URL: http://svn.apache.org/viewvc?view=rev&rev=539386
Log:
[CXF-654] Inherited @Resource annotated fields/methods declared not injected

Modified:
    incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/common/annotation/AnnotationProcessor.java
    incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/common/injection/ResourceInjector.java
    incubator/cxf/trunk/common/common/src/test/java/org/apache/cxf/common/injection/ResourceInjectorTest.java

Modified: incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/common/annotation/AnnotationProcessor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/common/annotation/AnnotationProcessor.java?view=diff&rev=539386&r1=539385&r2=539386
==============================================================================
--- incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/common/annotation/AnnotationProcessor.java
(original)
+++ incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/common/annotation/AnnotationProcessor.java
Fri May 18 04:12:46 2007
@@ -84,25 +84,34 @@
         
         annotationTypes = visitor.getTargetAnnotations();
         visitor.setTarget(target);
-        processClass(visitor);
-        processFields(visitor); 
-        processMethods(visitor);
+        //recursively check annotation in super class
+        processClass(visitor, target.getClass());
+        processFields(visitor, target.getClass()); 
+        processMethods(visitor, target.getClass());
     } 
     
     
-    private void processMethods(AnnotationVisitor visitor) {
-        
-        visitAnnotatedElement(target.getClass().getMethods(), visitor, visitMethodMethod);

+    private void processMethods(AnnotationVisitor visitor, Class<? extends Object>
targetClass) {
+
+        if (targetClass.getSuperclass() != null) {
+            processMethods(visitor, targetClass.getSuperclass());
+        }
+        visitAnnotatedElement(targetClass.getDeclaredMethods(), visitor, visitMethodMethod);

     }
     
-    private void processFields(AnnotationVisitor visitor) { 
-        
-        visitAnnotatedElement(target.getClass().getDeclaredFields(), visitor, visitFieldMethod);

+    private void processFields(AnnotationVisitor visitor, Class<? extends Object> targetClass)
{ 
+        if (targetClass.getSuperclass() != null) {
+            processFields(visitor, targetClass.getSuperclass());
+        }
+        visitAnnotatedElement(targetClass.getDeclaredFields(), visitor, visitFieldMethod);

     } 
     
     
-    private void processClass(AnnotationVisitor visitor) {
-        Class<?>[] classes = {target.getClass()}; 
+    private void processClass(AnnotationVisitor visitor, Class<? extends Object> targetClass)
{
+        if (targetClass.getSuperclass() != null) {
+            processClass(visitor, targetClass.getSuperclass());
+        }
+        Class<?>[] classes = {targetClass}; 
         visitAnnotatedElement(classes, visitor, visitClassMethod);
     }
     

Modified: incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/common/injection/ResourceInjector.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/common/injection/ResourceInjector.java?view=diff&rev=539386&r1=539385&r2=539386
==============================================================================
--- incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/common/injection/ResourceInjector.java
(original)
+++ incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/common/injection/ResourceInjector.java
Fri May 18 04:12:46 2007
@@ -234,6 +234,7 @@
 
     private void invokeSetter(Method method, Object resource) { 
         try {
+            method.setAccessible(true);
             method.invoke(getTarget(), resource);
         } catch (IllegalAccessException e) { 
             LOG.log(Level.SEVERE, "INJECTION_SETTER_NOT_VISIBLE", method);

Modified: incubator/cxf/trunk/common/common/src/test/java/org/apache/cxf/common/injection/ResourceInjectorTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/common/common/src/test/java/org/apache/cxf/common/injection/ResourceInjectorTest.java?view=diff&rev=539386&r1=539385&r2=539386
==============================================================================
--- incubator/cxf/trunk/common/common/src/test/java/org/apache/cxf/common/injection/ResourceInjectorTest.java
(original)
+++ incubator/cxf/trunk/common/common/src/test/java/org/apache/cxf/common/injection/ResourceInjectorTest.java
Fri May 18 04:12:46 2007
@@ -38,8 +38,8 @@
 
 public class ResourceInjectorTest extends Assert {
     private static final String RESOURCE_ONE = "resource one";
-    private static final String RESOURCE_TWO = "resource one";
-
+    private static final String RESOURCE_TWO = "resource two";
+    
     private ResourceInjector injector; 
         
     public void setUpResourceManager(String pfx) { 
@@ -63,6 +63,18 @@
         setUpResourceManager(FieldTarget.class.getCanonicalName() + "/");
         doInjectTest(new FieldTarget()); 
     }
+    
+    @Test
+    public void testFieldInSuperClassInjection() { 
+        setUpResourceManager("org.apache.cxf.common.injection.FieldTarget/");
+        doInjectTest(new SubFieldTarget()); 
+    }
+    
+    @Test
+    public void testSetterInSuperClassInjection() {
+        setUpResourceManager("org.apache.cxf.common.injection.SetterTarget/");
+        doInjectTest(new SubSetterTarget()); 
+    }
 
     @Test
     public void testSetterInjection() {
@@ -116,7 +128,8 @@
 interface Target {
     String getResource1(); 
     String getResource2(); 
-} 
+}
+
 
 class FieldTarget implements Target {
 
@@ -140,6 +153,13 @@
 
 }
 
+class SubFieldTarget extends FieldTarget {
+}
+
+class SubSetterTarget extends SetterTarget {
+    
+}
+
 class SetterTarget implements Target { 
 
     private String resource1;
@@ -163,7 +183,7 @@
     }
     
     @Resource(name = "resource2")
-    public final void setResource2(final String argResource2) {
+    private void setResource2(final String argResource2) {
         this.resource2 = argResource2;
     }
 
@@ -201,6 +221,7 @@
     // dummy method to access the private methods to avoid compile warnings
     public void dummyMethod() {
         preDestroyMethodPrivate();
+        setResource2("");
     }
 }
 



Mime
View raw message