You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by db...@apache.org on 2007/03/13 01:33:13 UTC

svn commit: r517478 - /incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/interceptor/ReflectionInvocationContext.java

Author: dblevins
Date: Mon Mar 12 17:33:12 2007
New Revision: 517478

URL: http://svn.apache.org/viewvc?view=rev&rev=517478
Log:
Reorged code for better "stepping" while in a debugger

Modified:
    incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/interceptor/ReflectionInvocationContext.java

Modified: incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/interceptor/ReflectionInvocationContext.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/interceptor/ReflectionInvocationContext.java?view=diff&rev=517478&r1=517477&r2=517478
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/interceptor/ReflectionInvocationContext.java (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/interceptor/ReflectionInvocationContext.java Mon Mar 12 17:33:12 2007
@@ -90,34 +90,61 @@
         return contextData;
     }
 
-    public Object proceed() throws Exception {
-        if (!parametersSet) throw new IllegalStateException("Parameters have not been set");
-
+    private Invocation next() {
         if (interceptors.hasNext()) {
             Interceptor interceptor = interceptors.next();
             Object nextInstance = interceptor.getInstance();
             Method nextMethod = interceptor.getMethod();
 
-            try {
-                if (nextMethod.getParameterTypes().length == 0){
-                    Object value = nextMethod.invoke(nextInstance);
-                    return value;
-                } else {
-                    Object value = nextMethod.invoke(nextInstance, this);
-                    return value;
-                }
-            } catch (InvocationTargetException e) {
-                throw unwrapInvocationTargetException(e);
+            if (nextMethod.getParameterTypes().length == 0){
+                return new Invocation(nextInstance, nextMethod, new Object[]{});
+            } else {
+                return new Invocation(nextInstance, nextMethod, new Object[]{this});
             }
         } else if (method != null) {
-            try {
-                Object value = method.invoke(target, parameters);
-                return value;
-            } catch (InvocationTargetException e) {
-                throw unwrapInvocationTargetException(e);
-            }
+            return new Invocation(target, method, parameters);
+        } else {
+            return new NoOpInvocation();
+        }
+    }
+
+    public Object proceed() throws Exception {
+        if (!parametersSet) throw new IllegalStateException("Parameters have not been set");
+        // The bulk of the logic of this method has intentionally been moved
+        // out so stepping through a large stack in a debugger can be done quickly.
+        // Simply put one break point on 'next.invoke()' or one inside that method.
+        try {
+            Invocation next = next();
+            return next.invoke();
+        } catch (InvocationTargetException e) {
+            throw unwrapInvocationTargetException(e);
+        }
+    }
+
+    private static class Invocation {
+        private final Method method;
+        private final Object[] args;
+        private final Object target;
+
+        public Invocation(Object target, Method method, Object[] args) {
+            this.target = target;
+            this.method = method;
+            this.args = args;
+        }
+        public Object invoke() throws IllegalAccessException, InvocationTargetException {
+            Object value = method.invoke(target, args);
+            return value;
+        }
+    }
+
+    private static class NoOpInvocation extends Invocation {
+        public NoOpInvocation() {
+            super(null, null, null);
+        }
+
+        public Object invoke() throws IllegalAccessException, InvocationTargetException {
+            return null;
         }
-        return null;
     }
 
     // todo verify excpetion types