openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gerdo...@apache.org
Subject svn commit: r937872 - in /openwebbeans/trunk: webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/interceptor/OpenWebBeansEjbInterceptor.java webbeans-impl/src/main/java/org/apache/webbeans/decorator/DelegateHandler.java
Date Sun, 25 Apr 2010 20:50:25 GMT
Author: gerdogdu
Date: Sun Apr 25 20:50:24 2010
New Revision: 937872

URL: http://svn.apache.org/viewvc?rev=937872&view=rev
Log:
Updating EJB interceptor/decorator handling for the case no interceptor/decorator exist for
EJB.

Modified:
    openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/interceptor/OpenWebBeansEjbInterceptor.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/decorator/DelegateHandler.java

Modified: openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/interceptor/OpenWebBeansEjbInterceptor.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/interceptor/OpenWebBeansEjbInterceptor.java?rev=937872&r1=937871&r2=937872&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/interceptor/OpenWebBeansEjbInterceptor.java
(original)
+++ openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/interceptor/OpenWebBeansEjbInterceptor.java
Sun Apr 25 20:50:24 2010
@@ -103,6 +103,12 @@ public class OpenWebBeansEjbInterceptor
         
     }
     
+    private static class CallReturnValue
+    {
+        public boolean INTERCEPTOR_OR_DECORATOR_CALL = false;
+        public Object RETURN_VALUE = null;
+    }
+    
     /**
      * Sets thread local.
      * @param ejbBean bean
@@ -121,6 +127,9 @@ public class OpenWebBeansEjbInterceptor
     {
         threadLocal.set(null);
         threadLocalCreationalContext.set(null);
+        
+        threadLocal.remove();
+        threadLocalCreationalContext.remove();
     }
     
     /**
@@ -132,7 +141,7 @@ public class OpenWebBeansEjbInterceptor
     @AroundInvoke
     public Object callToOwbInterceptors(InvocationContext ejbContext) throws Exception
     {
-        Object rv = null;
+        CallReturnValue rv = null;
         boolean requestCreated = false;
         boolean applicationCreated = false;
         boolean requestAlreadyActive = false;
@@ -182,7 +191,14 @@ public class OpenWebBeansEjbInterceptor
             }
         }
         
-        return rv;
+        //If bean has no interceptor or decorator
+        //Call ejb bean instance
+        if(!rv.INTERCEPTOR_OR_DECORATOR_CALL)
+        {
+            return ejbContext.proceed();
+        }
+        
+        return rv.RETURN_VALUE;
     }
     
     /**
@@ -342,7 +358,7 @@ public class OpenWebBeansEjbInterceptor
      * @return result of operation
      * @throws Exception for any exception
      */    
-    private Object callInterceptorsForNonContextuals(Method method, Object instance, Object[]
arguments, InvocationContext ejbContext) throws Exception
+    private CallReturnValue callInterceptorsForNonContextuals(Method method, Object instance,
Object[] arguments, InvocationContext ejbContext) throws Exception
     {
         BeanManagerImpl manager = BeanManagerImpl.getManager();
         
@@ -366,17 +382,19 @@ public class OpenWebBeansEjbInterceptor
             }
         }        
         
+        CallReturnValue rv = new CallReturnValue();
+        rv.INTERCEPTOR_OR_DECORATOR_CALL = false;
         if(ejbBean == null)
         {
             logger.warn("Unable to find EJB bean with class : " + instance.getClass());
+            return rv;
         }
         else
         {
             CreationalContext<?> cc = manager.createCreationalContext(null);
             return runInterceptorStack(ejbBean.getInterceptorStack(), method, instance, arguments,
ejbBean, cc, ejbContext);
         }
-        
-        return null;
+
     }
     
     /**
@@ -387,14 +405,15 @@ public class OpenWebBeansEjbInterceptor
      * @return result of operation
      * @throws Exception for any exception
      */
-    private Object callInterceptorsAndDecorators(Method method, Object instance, Object[]
arguments, InvocationContext ejbContext) throws Exception
+    private CallReturnValue callInterceptorsAndDecorators(Method method, Object instance,
Object[] arguments, InvocationContext ejbContext) throws Exception
     {
+        CallReturnValue rv = new CallReturnValue();
         InjectionTargetBean<?> injectionTarget = (InjectionTargetBean<?>) threadLocal.get();
         
         String methodName = method.getName();
         if(ClassUtil.isObjectMethod(methodName) && !methodName.equals("toString"))
         {
-            logger.warn("Calling method on proxy is restricted except Object.toString(),
but current method is Object." + methodName);
+            logger.trace("Calling method on proxy is restricted except Object.toString(),
but current method is Object." + methodName);
         }
                 
         if (InterceptorUtil.isWebBeansBusinessMethod(method) && 
@@ -413,7 +432,7 @@ public class OpenWebBeansEjbInterceptor
                     JavassistProxyFactory.getInterceptorProxyClasses().put(injectionTarget,
proxyClass);
                 }
                 Object delegate = proxyClass.newInstance();
-                delegateHandler = new DelegateHandler(threadLocal.get());
+                delegateHandler = new DelegateHandler(threadLocal.get(),ejbContext);
                 ((ProxyObject)delegate).setHandler(delegateHandler);
 
                 // Gets component decorator stack
@@ -453,8 +472,11 @@ public class OpenWebBeansEjbInterceptor
                 // Call Around Invokes
                 if (WebBeansUtil.isContainsInterceptorMethod(this.interceptedMethodMap.get(method),
InterceptorType.AROUND_INVOKE))
                 {
-                     return InterceptorUtil.callAroundInvokes(threadLocal.get(), instance,
(CreationalContextImpl<?>)threadLocalCreationalContext.get(), method, 
+                     rv.INTERCEPTOR_OR_DECORATOR_CALL = true;
+                     rv.RETURN_VALUE = InterceptorUtil.callAroundInvokes(threadLocal.get(),
instance, (CreationalContextImpl<?>)threadLocalCreationalContext.get(), method, 
                             arguments, InterceptorUtil.getInterceptorMethods(this.interceptedMethodMap.get(method),
InterceptorType.AROUND_INVOKE), ejbContext);
+                     
+                     return rv;
                 }
                 
             }
@@ -463,16 +485,21 @@ public class OpenWebBeansEjbInterceptor
             // manage the stack
             if (decorators != null)
             {
-                return delegateHandler.invoke(instance, method, null, arguments);
+                rv.INTERCEPTOR_OR_DECORATOR_CALL = true;
+                rv.RETURN_VALUE = delegateHandler.invoke(instance, method, null, arguments);

+                return rv;
             }
         }    
         
-        return null;
+        rv.INTERCEPTOR_OR_DECORATOR_CALL = false;
+        
+        return rv;
     }
     
-    private Object runInterceptorStack(List<InterceptorData> interceptorStack, Method
method, Object instance, 
+    private CallReturnValue runInterceptorStack(List<InterceptorData> interceptorStack,
Method method, Object instance, 
                                         Object[] arguments, BaseEjbBean<?> bean, CreationalContext<?>
creationalContext, InvocationContext ejbContext) throws Exception
     {
+        CallReturnValue rv = new CallReturnValue();
         if (interceptorStack.size() > 0)
         {
             if(this.nonCtxInterceptedMethodMap.get(method) == null)
@@ -488,15 +515,19 @@ public class OpenWebBeansEjbInterceptor
             // Call Around Invokes
             if (WebBeansUtil.isContainsInterceptorMethod(this.nonCtxInterceptedMethodMap.get(method),
InterceptorType.AROUND_INVOKE))
             {
-                 return InterceptorUtil.callAroundInvokes(bean, instance, (CreationalContextImpl<?>)creationalContext,
method, 
+                 rv.INTERCEPTOR_OR_DECORATOR_CALL = true;
+                 rv.RETURN_VALUE = InterceptorUtil.callAroundInvokes(bean, instance, (CreationalContextImpl<?>)creationalContext,
method, 
                         arguments, InterceptorUtil.getInterceptorMethods(this.nonCtxInterceptedMethodMap.get(method),
InterceptorType.AROUND_INVOKE),
                         ejbContext);
+                 
+                 return rv;
             }
             
         }
         
+        rv.INTERCEPTOR_OR_DECORATOR_CALL = false;
         
-        return null;
+        return rv;
         
     }
     

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/decorator/DelegateHandler.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/decorator/DelegateHandler.java?rev=937872&r1=937871&r2=937872&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/decorator/DelegateHandler.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/decorator/DelegateHandler.java
Sun Apr 25 20:50:24 2010
@@ -17,6 +17,8 @@ import java.lang.reflect.InvocationTarge
 import java.lang.reflect.Method;
 import java.util.List;
 
+import javax.interceptor.InvocationContext;
+
 import org.apache.webbeans.component.EnterpriseBeanMarker;
 import org.apache.webbeans.component.OwbBean;
 import org.apache.webbeans.config.OWBLogConst;
@@ -36,12 +38,20 @@ public class DelegateHandler implements 
     private transient Object actualBean = null;
     
     private transient OwbBean<?> bean = null;
+    
+    private transient InvocationContext ejbContext;
 
     public DelegateHandler(OwbBean<?> bean)
     {
         this.bean = bean;
     }
     
+    public DelegateHandler(OwbBean<?> bean, InvocationContext ejbContext)
+    {
+        this.bean = bean;
+        this.ejbContext = ejbContext;
+    }    
+    
     @Override
     public Object invoke(Object instance, Method method, Method proceed, Object[] arguments)
throws Exception
     {
@@ -109,6 +119,13 @@ public class DelegateHandler implements 
         {
             result = method.invoke(actualBean, arguments);
         }
+        else
+        {
+            if(ejbContext != null)
+            {
+                result = ejbContext.proceed();
+            }
+        }
         
         return result;
 



Mime
View raw message