cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r667576 - in /cxf/branches/2.0.x-fixes: ./ common/common/src/main/java/org/apache/cxf/common/annotation/ common/common/src/main/java/org/apache/cxf/common/injection/ common/common/src/test/java/org/apache/cxf/common/annotation/
Date Fri, 13 Jun 2008 15:57:18 GMT
Author: dkulp
Date: Fri Jun 13 08:57:17 2008
New Revision: 667576

URL: http://svn.apache.org/viewvc?rev=667576&view=rev
Log:
Merged revisions 667575 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/trunk

........
  r667575 | dkulp | 2008-06-13 11:51:46 -0400 (Fri, 13 Jun 2008) | 3 lines
  
  [CXF-1645] Simplify the target method aquisition for proxies
  Also remove reflection from the AnnotationProcessor
........

Modified:
    cxf/branches/2.0.x-fixes/   (props changed)
    cxf/branches/2.0.x-fixes/common/common/src/main/java/org/apache/cxf/common/annotation/AnnotationProcessor.java
    cxf/branches/2.0.x-fixes/common/common/src/main/java/org/apache/cxf/common/injection/ResourceInjector.java
    cxf/branches/2.0.x-fixes/common/common/src/test/java/org/apache/cxf/common/annotation/AnnotationProcessorTest.java

Propchange: cxf/branches/2.0.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: cxf/branches/2.0.x-fixes/common/common/src/main/java/org/apache/cxf/common/annotation/AnnotationProcessor.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.0.x-fixes/common/common/src/main/java/org/apache/cxf/common/annotation/AnnotationProcessor.java?rev=667576&r1=667575&r2=667576&view=diff
==============================================================================
--- cxf/branches/2.0.x-fixes/common/common/src/main/java/org/apache/cxf/common/annotation/AnnotationProcessor.java
(original)
+++ cxf/branches/2.0.x-fixes/common/common/src/main/java/org/apache/cxf/common/annotation/AnnotationProcessor.java
Fri Jun 13 08:57:17 2008
@@ -20,12 +20,9 @@
 package org.apache.cxf.common.annotation;
 
 import java.lang.annotation.Annotation;
-import java.lang.reflect.AnnotatedElement;
 import java.lang.reflect.Field;
-import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.util.List;
-import java.util.logging.Level;
 import java.util.logging.Logger;
 
 import org.apache.cxf.common.i18n.Message;
@@ -42,23 +39,6 @@
     
     private static final Logger LOG = LogUtils.getL7dLogger(AnnotationProcessor.class); 
     
-    private static Method visitClassMethod; 
-    private static Method visitFieldMethod; 
-    private static Method visitMethodMethod; 
-    
-    static { 
-        try {
-            visitClassMethod = AnnotationVisitor.class.getMethod("visitClass", Class.class,
Annotation.class);
-            visitFieldMethod = AnnotationVisitor.class.getMethod("visitField", Field.class,
Annotation.class);
-            visitMethodMethod = AnnotationVisitor.class.getMethod("visitMethod", 
-                                                                  Method.class, Annotation.class);
-            
-        } catch (NoSuchMethodException e) {
-            // ignore
-        }
-        
-    } 
-    
     private final Object target; 
     private List<Class<? extends Annotation>> annotationTypes; 
     
@@ -100,14 +80,28 @@
         if (targetClass.getSuperclass() != null) {
             processMethods(visitor, targetClass.getSuperclass());
         }
-        visitAnnotatedElement(targetClass.getDeclaredMethods(), visitor, visitMethodMethod);

+        for (Method element : targetClass.getDeclaredMethods()) {
+            for (Class<? extends Annotation> clz : annotationTypes) {
+                Annotation ann = element.getAnnotation(clz); 
+                if (ann != null) {
+                    visitor.visitMethod(element, ann);
+                }
+            }
+        }
     }
     
     private void processFields(AnnotationVisitor visitor, Class<? extends Object> targetClass)
{ 
         if (targetClass.getSuperclass() != null) {
             processFields(visitor, targetClass.getSuperclass());
         }
-        visitAnnotatedElement(targetClass.getDeclaredFields(), visitor, visitFieldMethod);

+        for (Field element : targetClass.getDeclaredFields()) {
+            for (Class<? extends Annotation> clz : annotationTypes) {
+                Annotation ann = element.getAnnotation(clz); 
+                if (ann != null) {
+                    visitor.visitField(element, ann);
+                }
+            }
+        }
     } 
     
     
@@ -115,28 +109,11 @@
         if (targetClass.getSuperclass() != null) {
             processClass(visitor, targetClass.getSuperclass());
         }
-        Class<?>[] classes = {targetClass}; 
-        visitAnnotatedElement(classes, visitor, visitClassMethod);
-    }
-    
-    private <U extends AnnotatedElement> void visitAnnotatedElement(U[] elements, 
-                                                                    AnnotationVisitor visitor,
-                                                                    Method visitorMethod)
{
-        
-        for (U element : elements) {
-            for (Class<? extends Annotation> clz : annotationTypes) {
-                Annotation ann = element.getAnnotation(clz); 
-                if (ann != null) {
-                    try {                        
-                        visitorMethod.invoke(visitor, element, ann);
-                    } catch (IllegalAccessException e) {
-                        // ignore, we're invoking methods of a public interface
-                    } catch (InvocationTargetException e) {
-                        Throwable cause = e.getCause() == null ? e : e.getCause();
-                        LogUtils.log(LOG, Level.SEVERE, "VISITOR_RAISED_EXCEPTION", cause,
visitor, element);
-                    }
-                }
+        for (Class<? extends Annotation> clz : annotationTypes) {
+            Annotation ann = targetClass.getAnnotation(clz); 
+            if (ann != null) {
+                visitor.visitClass(targetClass, ann);
             }
         }
-    }
+    }    
 }

Modified: cxf/branches/2.0.x-fixes/common/common/src/main/java/org/apache/cxf/common/injection/ResourceInjector.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.0.x-fixes/common/common/src/main/java/org/apache/cxf/common/injection/ResourceInjector.java?rev=667576&r1=667575&r2=667576&view=diff
==============================================================================
--- cxf/branches/2.0.x-fixes/common/common/src/main/java/org/apache/cxf/common/injection/ResourceInjector.java
(original)
+++ cxf/branches/2.0.x-fixes/common/common/src/main/java/org/apache/cxf/common/injection/ResourceInjector.java
Fri Jun 13 08:57:17 2008
@@ -244,10 +244,8 @@
             if (method.getDeclaringClass().isAssignableFrom(getTarget().getClass())) {
                 method.invoke(getTarget(), resource);
             } else { // deal with the proxy setter method
-                Method targetMethod = findMethod(getTarget().getClass(), 
-                                                 method.getName(),
-                                                 resource);                
-
+                Method targetMethod = getTarget().getClass().getMethod(method.getName(),
+                                                                       method.getParameterTypes());

                 targetMethod.invoke(getTarget(), resource);
             }
         } catch (IllegalAccessException e) { 
@@ -261,23 +259,6 @@
         } 
     } 
 
-
-    private Method findMethod(Class<? extends Object> class1, String name, Object resource)
-        throws SecurityException, NoSuchMethodException {
-        try {
-            return class1.getMethod(name, new Class[]{resource.getClass()});
-        } catch (NoSuchMethodException e) {
-            for (Method m : class1.getMethods()) {
-                if (m.getName().equals(name)
-                    && m.getParameterTypes().length == 1
-                    && m.getParameterTypes()[0].isInstance(resource)) {
-                    return m;
-                }
-            }
-            throw e;
-        }
-    }
-
     private String getResourceName(Resource res, Method method) { 
         assert method != null; 
         assert res != null; 

Modified: cxf/branches/2.0.x-fixes/common/common/src/test/java/org/apache/cxf/common/annotation/AnnotationProcessorTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.0.x-fixes/common/common/src/test/java/org/apache/cxf/common/annotation/AnnotationProcessorTest.java?rev=667576&r1=667575&r2=667576&view=diff
==============================================================================
--- cxf/branches/2.0.x-fixes/common/common/src/test/java/org/apache/cxf/common/annotation/AnnotationProcessorTest.java
(original)
+++ cxf/branches/2.0.x-fixes/common/common/src/test/java/org/apache/cxf/common/annotation/AnnotationProcessorTest.java
Fri Jun 13 08:57:17 2008
@@ -85,6 +85,7 @@
         Method expectedMethod3 = AnnotatedGreeterImpl.class.getDeclaredMethod("greetMe",
String.class); 
         Method expectedMethod4 = 
             AnnotatedGreeterImpl.class.getDeclaredMethod("setContext", WebServiceContext.class);

+        Method expectedMethod5 = AnnotatedGreeterImpl.class.getDeclaredMethod("greetMeOneWay",
String.class);
 
         expectedAnnotations.add(WebMethod.class);
         expectedAnnotations.add(Resource.class); 
@@ -100,6 +101,8 @@
                            (Annotation)EasyMock.isA(WebMethod.class));
         visitor.visitMethod(EasyMock.eq(expectedMethod4), 
                            (Annotation)EasyMock.isA(Resource.class));
+        visitor.visitMethod(EasyMock.eq(expectedMethod5), 
+                            (Annotation)EasyMock.isA(WebMethod.class));
         runProcessor(visitor);
     }
 



Mime
View raw message