openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gerdo...@apache.org
Subject svn commit: r932846 - in /openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans: component/ context/creational/ decorator/ inject/ intercept/ portable/creation/
Date Sun, 11 Apr 2010 07:35:03 GMT
Author: gerdogdu
Date: Sun Apr 11 07:35:03 2010
New Revision: 932846

URL: http://svn.apache.org/viewvc?rev=932846&view=rev
Log:
[OWB-348] Adding Interceptor and Decorator Support for EJB Beans

Modified:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/AbstractInjectionTargetBean.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/creational/DependentCreationalContext.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/creational/EjbInterceptorContext.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/decorator/DelegateHandler.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/OWBInjector.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorHandler.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InvocationContextImpl.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/creation/InjectionTargetProducer.java

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/AbstractInjectionTargetBean.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/AbstractInjectionTargetBean.java?rev=932846&r1=932845&r2=932846&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/AbstractInjectionTargetBean.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/AbstractInjectionTargetBean.java
Sun Apr 11 07:35:03 2010
@@ -133,7 +133,7 @@ public abstract class AbstractInjectionT
         //For dependent instance checks
         T dependentProxy = null;
         boolean isDependentProxy = false;
-        if(getScope() == Dependent.class)
+        if(getScope() == Dependent.class && !(this instanceof EnterpriseBeanMarker))
         {
             T result = (T)JavassistProxyFactory.createDependentScopedBeanProxy(this, instance,
creationalContext);
             //Means that Dependent Bean has interceptor/decorator

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/creational/DependentCreationalContext.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/creational/DependentCreationalContext.java?rev=932846&r1=932845&r2=932846&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/creational/DependentCreationalContext.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/creational/DependentCreationalContext.java
Sun Apr 11 07:35:03 2010
@@ -17,7 +17,6 @@
 package org.apache.webbeans.context.creational;
 
 import java.io.IOException;
-import java.io.InvalidClassException;
 import java.io.NotSerializableException;
 import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
@@ -31,7 +30,7 @@ import org.apache.webbeans.util.WebBeans
 
 class DependentCreationalContext<S> implements Serializable
 {
-    private static final long serialVersionUID = 7107949019995422165L;
+    private static final long serialVersionUID = 1L;
 
     private CreationalContext<S> creationalContext;
     
@@ -126,10 +125,10 @@ class DependentCreationalContext<S> impl
     private synchronized void writeObject(ObjectOutputStream s)
     throws IOException
     {
-        s.writeLong(serialVersionUID);
-        
-        s.writeObject(creationalContext);
+        //Default write
+        s.defaultWriteObject();
 
+        //Write for contextual
         String id = null;
         if (contextual != null)
         {
@@ -154,14 +153,10 @@ class DependentCreationalContext<S> impl
     private synchronized void readObject(ObjectInputStream s)
     throws IOException, ClassNotFoundException
     {
-        long svId = s.readLong();
-        if (svId != serialVersionUID)
-        {
-            throw new InvalidClassException(this.getClass().getSimpleName());
-        }
+        //Default read
+        s.defaultReadObject();
         
-        creationalContext = (CreationalContext<S>) s.readObject();
-
+        //Read for contextual
         String id = (String) s.readObject();
         if (id != null)
         {

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/creational/EjbInterceptorContext.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/creational/EjbInterceptorContext.java?rev=932846&r1=932845&r2=932846&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/creational/EjbInterceptorContext.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/creational/EjbInterceptorContext.java
Sun Apr 11 07:35:03 2010
@@ -18,10 +18,14 @@
  */
 package org.apache.webbeans.context.creational;
 
+import java.io.Serializable;
+
 import org.apache.webbeans.inject.OWBInjector;
 
-public class EjbInterceptorContext
+public class EjbInterceptorContext implements Serializable
 {
+    private static final long serialVersionUID = 1L;
+
     private Object interceptorInstance;
     
     private OWBInjector injectorInstance;

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=932846&r1=932845&r2=932846&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 11 07:35:03 2010
@@ -17,6 +17,8 @@ import java.lang.reflect.InvocationTarge
 import java.lang.reflect.Method;
 import java.util.List;
 
+import org.apache.webbeans.component.EnterpriseBeanMarker;
+import org.apache.webbeans.component.OwbBean;
 import org.apache.webbeans.config.OWBLogConst;
 import org.apache.webbeans.exception.WebBeansException;
 import org.apache.webbeans.logger.WebBeansLogger;
@@ -31,7 +33,14 @@ public class DelegateHandler implements 
     private transient int position = 0;
 
     private transient Object actualBean = null;
+    
+    private transient OwbBean<?> bean = null;
 
+    public DelegateHandler(OwbBean<?> bean)
+    {
+        this.bean = bean;
+    }
+    
     @Override
     public Object invoke(Object instance, Method method, Method proceed, Object[] arguments)
throws Exception
     {
@@ -93,7 +102,13 @@ public class DelegateHandler implements 
             method.setAccessible(true);
         }
 
-        Object result = method.invoke(actualBean, arguments);
+        Object result = null;
+        
+        if(!(bean instanceof EnterpriseBeanMarker))
+        {
+            result = method.invoke(actualBean, arguments);
+        }
+        
         return result;
 
     }

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/OWBInjector.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/OWBInjector.java?rev=932846&r1=932845&r2=932846&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/OWBInjector.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/OWBInjector.java
Sun Apr 11 07:35:03 2010
@@ -42,8 +42,10 @@ import org.apache.webbeans.util.ClassUti
  * @version $Rev$ $Date$
  *
  */
-public final class OWBInjector
+public final class OWBInjector implements Serializable
 {
+    private static final long serialVersionUID = 1L;
+    
     private CreationalContextImpl<?> ownerCreationalContext = null;
     
     public OWBInjector()

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorHandler.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorHandler.java?rev=932846&r1=932845&r2=932846&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorHandler.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorHandler.java
Sun Apr 11 07:35:03 2010
@@ -175,21 +175,27 @@ public abstract class InterceptorHandler
      */
     public Object invoke(Object instance, Method method, Method proceed, Object[] arguments,
CreationalContextImpl<?> ownerCreationalContext) throws Exception
     {
+        //Result of invocation
         Object result = null;
         
         try
         {
-            if (bean instanceof InjectionTargetBean<?>)
+            //Calling method name on Proxy
+            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);
+            }
+            
+            else if (bean instanceof InjectionTargetBean<?>)
             {
                 InjectionTargetBean<?> injectionTarget = (InjectionTargetBean<?>)
this.bean;
 
-                // toString is supported but no other object method names!!!
-                if ((!ClassUtil.isObjectMethod(method.getName()) || method.getName().equals("toString"))

-                    && InterceptorUtil.isWebBeansBusinessMethod(method))
+                //Check method is business method
+                if (InterceptorUtil.isWebBeansBusinessMethod(method))
                 {
-
                     List<Object> decorators = null;
-
                     if (injectionTarget.getDecoratorStack().size() > 0 && this.decorators
== null)
                     {
                         Class<?> proxyClass = JavassistProxyFactory.getInterceptorProxyClasses().get(bean);
@@ -200,7 +206,7 @@ public abstract class InterceptorHandler
                             JavassistProxyFactory.getInterceptorProxyClasses().put(bean,
proxyClass);
                         }
                         Object delegate = proxyClass.newInstance();
-                        this.delegateHandler = new DelegateHandler();
+                        this.delegateHandler = new DelegateHandler(this.bean);
                         ((ProxyObject)delegate).setHandler(this.delegateHandler);
 
                         // Gets component decorator stack

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InvocationContextImpl.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InvocationContextImpl.java?rev=932846&r1=932845&r2=932846&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InvocationContextImpl.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InvocationContextImpl.java
Sun Apr 11 07:35:03 2010
@@ -24,6 +24,7 @@ import javax.enterprise.context.spi.Cont
 import javax.enterprise.context.spi.CreationalContext;
 import javax.interceptor.InvocationContext;
 
+import org.apache.webbeans.component.EnterpriseBeanMarker;
 import org.apache.webbeans.component.OwbBean;
 import org.apache.webbeans.container.BeanManagerImpl;
 import org.apache.webbeans.context.creational.CreationalContextImpl;
@@ -58,6 +59,8 @@ public class InvocationContextImpl imple
     /**Bean creational context*/
     private CreationalContext<?> creationalContext;
     
+    private OwbBean<?> owbBean;
+    
     /**
      * Initializes the context.
      * 
@@ -69,6 +72,7 @@ public class InvocationContextImpl imple
      */
     public InvocationContextImpl(OwbBean<?> bean, Object instance, Method method, Object[]
parameters, List<InterceptorData> datas, InterceptorType type)
     {
+        this.owbBean = bean;
         this.method = method;
         this.parameters = parameters;
         this.interceptorDatas = datas;
@@ -215,17 +219,20 @@ public class InvocationContextImpl imple
         }
         else
         {
-            boolean accessible = this.method.isAccessible();
-            if(!accessible)
-            {                
-                this.method.setAccessible(true);
-            }
-            
-            result = this.method.invoke(target, parameters);
-            
-            if(!accessible)
+            if(!(this.owbBean instanceof EnterpriseBeanMarker))
             {
-                this.method.setAccessible(false);   
+                boolean accessible = this.method.isAccessible();
+                if(!accessible)
+                {                
+                    this.method.setAccessible(true);
+                }
+                
+                result = this.method.invoke(target, parameters);
+                
+                if(!accessible)
+                {
+                    this.method.setAccessible(false);   
+                }                
             }
         }
 
@@ -270,12 +277,14 @@ public class InvocationContextImpl imple
             //In bean class
             if (t == null)
             {
-                t = target;                
-                result = method.invoke(t, new Object[] {});
-                
-                //Continue to call others
-                proceedCommonAnnots(datas, type);                
-                
+                if(!(this.owbBean instanceof EnterpriseBeanMarker))
+                {
+                    t = target;                
+                    result = method.invoke(t, new Object[] {});
+                    
+                    //Continue to call others
+                    proceedCommonAnnots(datas, type);                                   

+                }                
             }
             //In interceptor class
             else

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/creation/InjectionTargetProducer.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/creation/InjectionTargetProducer.java?rev=932846&r1=932845&r2=932846&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/creation/InjectionTargetProducer.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/creation/InjectionTargetProducer.java
Sun Apr 11 07:35:03 2010
@@ -16,6 +16,7 @@ package org.apache.webbeans.portable.cre
 import javax.enterprise.context.spi.CreationalContext;
 import javax.enterprise.inject.spi.InjectionTarget;
 
+import org.apache.webbeans.component.EnterpriseBeanMarker;
 import org.apache.webbeans.component.InjectionTargetBean;
 import org.apache.webbeans.context.creational.CreationalContextFactory;
 import org.apache.webbeans.context.creational.CreationalContextImpl;
@@ -52,11 +53,14 @@ public class InjectionTargetProducer<T> 
         
         InjectionTargetBean<T> bean = getBean(InjectionTargetBean.class);
         
-        bean.injectResources(instance, ctx);
-        bean.injectSuperFields(instance, ctx);
-        bean.injectSuperMethods(instance, ctx);
-        bean.injectFields(instance, ctx);
-        bean.injectMethods(instance, ctx);
+        if(!(bean instanceof EnterpriseBeanMarker))
+        {
+            bean.injectResources(instance, ctx);
+            bean.injectSuperFields(instance, ctx);
+            bean.injectSuperMethods(instance, ctx);
+            bean.injectFields(instance, ctx);
+            bean.injectMethods(instance, ctx);            
+        }        
     }
     
     /**
@@ -65,8 +69,11 @@ public class InjectionTargetProducer<T> 
     @Override
     public void postConstruct(T instance)
     {
-        InjectionTargetBean<T> bean = getBean(InjectionTargetBean.class);        
-        bean.postConstruct(instance,this.creationalContext);
+        InjectionTargetBean<T> bean = getBean(InjectionTargetBean.class);    
+        if(!(bean instanceof EnterpriseBeanMarker))
+        {
+            bean.postConstruct(instance,this.creationalContext);   
+        }
     }
 
     /**
@@ -76,7 +83,10 @@ public class InjectionTargetProducer<T> 
     public void preDestroy(T instance)
     {
         InjectionTargetBean<T> bean = getBean(InjectionTargetBean.class);        
-        bean.preDestroy(instance,this.creationalContext);
+        if(!(bean instanceof EnterpriseBeanMarker))
+        {
+            bean.preDestroy(instance,this.creationalContext);   
+        }
     }
 
 }
\ No newline at end of file



Mime
View raw message