openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject svn commit: r1434980 - in /openwebbeans/trunk/webbeans-impl/src: main/java/org/apache/webbeans/context/creational/ main/java/org/apache/webbeans/inject/ main/java/org/apache/webbeans/intercept/ main/java/org/apache/webbeans/portable/ test/java/org/apac...
Date Fri, 18 Jan 2013 00:14:24 GMT
Author: arne
Date: Fri Jan 18 00:14:23 2013
New Revision: 1434980

URL: http://svn.apache.org/viewvc?rev=1434980&view=rev
Log:
OWB-344: Implemented decorator stack creation

Modified:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/creational/CreationalContextImpl.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/AbstractInjectable.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/InjectableConstructor.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/InjectableField.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/InjectableMethod.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/DecoratorHandler.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/DefaultInterceptorHandler.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/InjectionTargetImpl.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/business/tests/NewProxyTest.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/resolution/InterceptorProxyChainTest.java

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/creational/CreationalContextImpl.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/creational/CreationalContextImpl.java?rev=1434980&r1=1434979&r2=1434980&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/creational/CreationalContextImpl.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/creational/CreationalContextImpl.java
Fri Jan 18 00:14:23 2013
@@ -50,6 +50,11 @@ public class CreationalContextImpl<T> im
     private static final long serialVersionUID = 1L;
 
     /**
+     * The delegate object to be injected into delegate injection points
+     */
+    private transient T delegate;
+
+    /**
      * Contextual bean dependent instances
      * key: contextual instance --> value: dependents
      *
@@ -149,7 +154,21 @@ public class CreationalContextImpl<T> im
         return null;
     }
     
-    
+    public T getDelegate()
+    {
+        return this.delegate;
+    }
+
+    /**
+     * @return the previously set delegate instance
+     */
+    public T putDelegate(T delegate)
+    {
+        T oldValue = this.delegate;
+        this.delegate = delegate;
+        return oldValue;
+    }
+
     /**
      * Save this incomplete instance.
      * 

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/AbstractInjectable.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/AbstractInjectable.java?rev=1434980&r1=1434979&r2=1434980&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/AbstractInjectable.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/AbstractInjectable.java
Fri Jan 18 00:14:23 2013
@@ -64,7 +64,7 @@ public abstract class AbstractInjectable
 
     private Producer<?> owner;
     
-    private CreationalContextImpl<?> context;
+    protected final CreationalContextImpl<?> creationalContext;
 
     /**
      * @deprecated TODO remove this public ThreadLocal!
@@ -74,7 +74,7 @@ public abstract class AbstractInjectable
     protected AbstractInjectable(Producer<?> owner, CreationalContextImpl<?>
creationalContext)
     {
         this.owner = owner;
-        this.context = creationalContext;
+        this.creationalContext = creationalContext;
     }
 
     /**
@@ -85,7 +85,7 @@ public abstract class AbstractInjectable
     public T inject(InjectionPoint injectionPoint)
     {
         T injected;
-        BeanManagerImpl beanManager = context.getWebBeansContext().getBeanManagerImpl();
+        BeanManagerImpl beanManager = creationalContext.getWebBeansContext().getBeanManagerImpl();
 
         //Injected contextual beam
         InjectionResolver instance = beanManager.getInjectionResolver();
@@ -117,7 +117,7 @@ public abstract class AbstractInjectable
                 {
                     if(injectedBean instanceof AbstractProducerBean)
                     {
-                        if((context.getBean() instanceof OwbBean) && ((OwbBean<?>)
context.getBean()).isPassivationCapable())
+                        if((creationalContext.getBean() instanceof OwbBean) && ((OwbBean<?>)
creationalContext.getBean()).isPassivationCapable())
                         {
                             dependentProducer = true;   
                         }
@@ -126,7 +126,7 @@ public abstract class AbstractInjectable
             }        
 
             //Gets injectable reference for injected bean
-            injected = (T) beanManager.getInjectableReference(injectionPoint, context);
+            injected = (T) beanManager.getInjectableReference(injectionPoint, creationalContext);
 
             /*X TODO see spec issue CDI-140 */
             if(dependentProducer)
@@ -143,7 +143,7 @@ public abstract class AbstractInjectable
             {
                 if(instanceUnderInjection.get() != null)
                 {
-                    context.addDependent(instanceUnderInjection.get(), injectedBean, injected);
+                    creationalContext.addDependent(instanceUnderInjection.get(), injectedBean,
injected);
                 }
             }
         } 
@@ -161,12 +161,12 @@ public abstract class AbstractInjectable
     
     protected Contextual<?> getBean()
     {
-        return context.getBean();
+        return creationalContext.getBean();
     }
 
     protected WebBeansContext getWebBeansContext()
     {
-        return context.getWebBeansContext();
+        return creationalContext.getWebBeansContext();
     }
         
     /**

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/InjectableConstructor.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/InjectableConstructor.java?rev=1434980&r1=1434979&r2=1434980&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/InjectableConstructor.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/InjectableConstructor.java
Fri Jan 18 00:14:23 2013
@@ -72,6 +72,11 @@ public class InjectableConstructor<T> ex
                 AnnotatedParameter<?> parameter = (AnnotatedParameter<?>)point.getAnnotated();
                 if(parameter.getPosition() == i)
                 {
+                    if (point.isDelegate())
+                    {
+                        list.add(creationalContext.getDelegate());
+                        break;
+                    }
                     list.add(inject(point));
                     break;
                 }

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/InjectableField.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/InjectableField.java?rev=1434980&r1=1434979&r2=1434980&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/InjectableField.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/InjectableField.java
Fri Jan 18 00:14:23 2013
@@ -55,7 +55,15 @@ public class InjectableField<T> extends 
                 getWebBeansContext().getSecurityService().doPrivilegedSetAccessible(field,
true);
             }
 
-            Object object = inject(injectedField);
+            Object object;
+            if (injectedField.isDelegate())
+            {
+                object = creationalContext.getDelegate();
+            }
+            else
+            {
+                object = inject(injectedField);
+            }
             
             field.set(instance, object);
 

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/InjectableMethod.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/InjectableMethod.java?rev=1434980&r1=1434979&r2=1434980&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/InjectableMethod.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/InjectableMethod.java
Fri Jan 18 00:14:23 2013
@@ -83,8 +83,14 @@ public class InjectableMethod<T> extends
             for(InjectionPoint point : injectedPoints)
             {                
                 AnnotatedParameter<?> parameter = (AnnotatedParameter<?>)point.getAnnotated();
-                if(parameter.getPosition() == i)
+                if (parameter.getPosition() == i)
                 {
+                    if (point.isDelegate())
+                    {
+                        list.add(creationalContext.getDelegate());
+                        break;
+                    }
+
                     boolean injectionPoint = false;
                     if(getBean() instanceof ProducerMethodBean)
                     {

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/DecoratorHandler.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/DecoratorHandler.java?rev=1434980&r1=1434979&r2=1434980&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/DecoratorHandler.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/DecoratorHandler.java
Fri Jan 18 00:14:23 2013
@@ -39,9 +39,9 @@ public class DecoratorHandler implements
     private int index;
     private Object target;
 
-    public DecoratorHandler(BeanInterceptorInfo interceptorInfo, List<Decorator<?>>
decorators, Map<Decorator<?>, ?> instances, int index, Object target) {
+    public DecoratorHandler(BeanInterceptorInfo interceptorInfo, Map<Decorator<?>,
?> instances, int index, Object target) {
         this.interceptorInfo = interceptorInfo;
-        this.decorators = decorators;
+        this.decorators = interceptorInfo.getDecorators();
         this.instances = instances;
         this.index = index;
         this.target = target;

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/DefaultInterceptorHandler.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/DefaultInterceptorHandler.java?rev=1434980&r1=1434979&r2=1434980&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/DefaultInterceptorHandler.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/DefaultInterceptorHandler.java
Fri Jan 18 00:14:23 2013
@@ -32,14 +32,17 @@ public class DefaultInterceptorHandler<T
 {
 
     private T target;
+    private T delegate;
     private Map<Method, List<Interceptor<?>>> interceptors;
     private Map<Interceptor<?>, ?> instances;
 
     public DefaultInterceptorHandler(T target,
+                                     T delegate,
                                      Map<Method, List<Interceptor<?>>>
interceptors,
                                      Map<Interceptor<?>, ?> instances)
     {
         this.target = target;
+        this.delegate = delegate;
         this.instances = instances;
         this.interceptors = interceptors;
     }
@@ -49,6 +52,11 @@ public class DefaultInterceptorHandler<T
         return target;
     }
 
+    public T getDelegate()
+    {
+        return delegate;
+    }
+
     public Map<Interceptor<?>, ?> getInstances()
     {
         return instances;
@@ -66,7 +74,7 @@ public class DefaultInterceptorHandler<T
             List<Interceptor<?>> methodInterceptors = interceptors.get(method);
 
             InterceptorInvocationContext<T> ctx
-                = new InterceptorInvocationContext<T>(target, InterceptionType.AROUND_INVOKE,
methodInterceptors, instances, method, parameters);
+                = new InterceptorInvocationContext<T>(delegate, InterceptionType.AROUND_INVOKE,
methodInterceptors, instances, method, parameters);
 
             return ctx.proceed();
         }

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/InjectionTargetImpl.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/InjectionTargetImpl.java?rev=1434980&r1=1434979&r2=1434980&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/InjectionTargetImpl.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/InjectionTargetImpl.java
Fri Jan 18 00:14:23 2013
@@ -40,6 +40,7 @@ import javax.enterprise.inject.spi.Annot
 import javax.enterprise.inject.spi.AnnotatedMethod;
 import javax.enterprise.inject.spi.AnnotatedParameter;
 import javax.enterprise.inject.spi.AnnotatedType;
+import javax.enterprise.inject.spi.Decorator;
 import javax.enterprise.inject.spi.InjectionPoint;
 import javax.enterprise.inject.spi.InjectionTarget;
 import javax.enterprise.inject.spi.InterceptionType;
@@ -50,12 +51,15 @@ import javax.interceptor.InvocationConte
 import org.apache.webbeans.config.OWBLogConst;
 import org.apache.webbeans.config.WebBeansContext;
 import org.apache.webbeans.context.creational.CreationalContextImpl;
+import org.apache.webbeans.decorator.DelegateHandler;
 import org.apache.webbeans.exception.WebBeansException;
 import org.apache.webbeans.inject.InjectableConstructor;
 import org.apache.webbeans.inject.InjectableField;
 import org.apache.webbeans.inject.InjectableMethod;
+import org.apache.webbeans.intercept.DecoratorHandler;
 import org.apache.webbeans.intercept.DefaultInterceptorHandler;
 import org.apache.webbeans.intercept.LifecycleInterceptorInvocationContext;
+import org.apache.webbeans.intercept.InterceptorResolutionService.BeanInterceptorInfo;
 import org.apache.webbeans.logger.WebBeansLoggerFacade;
 import org.apache.webbeans.proxy.InterceptorDecoratorProxyFactory;
 import org.apache.webbeans.proxy.InterceptorHandler;
@@ -64,9 +68,6 @@ import org.apache.webbeans.spi.ResourceI
 import org.apache.webbeans.util.Asserts;
 import org.apache.webbeans.util.ExceptionUtil;
 
-
-import static org.apache.webbeans.intercept.InterceptorResolutionService.BeanInterceptorInfo;
-
 public class InjectionTargetImpl<T> extends AbstractProducer<T> implements InjectionTarget<T>
 {
 
@@ -190,7 +191,22 @@ public class InjectionTargetImpl<T> exte
                 interceptorInstances.put(interceptorInfo.getSelfInterceptorBean(), instance);
             }
 
-            InterceptorHandler interceptorHandler = new DefaultInterceptorHandler<T>(instance,
methodInterceptors, interceptorInstances);
+            T delegate = instance;
+            if (interceptorInfo.getDecorators() != null)
+            {
+                List<Decorator<?>> decorators = interceptorInfo.getDecorators();
+                Map<Decorator<?>, Object> instances = new HashMap<Decorator<?>,
Object>();
+                for (int i = decorators.size(); i > 0; i--)
+                {
+                    Decorator<?> decorator = decorators.get(i - 1);
+                    CreationalContextImpl<T> creationalContextImpl = (CreationalContextImpl<T>)creationalContext;
+                    creationalContextImpl.putDelegate(delegate);
+                    Object decoratorInstance = decorator.create((CreationalContext) creationalContext);
+                    instances.put(decorator, decoratorInstance);
+                    delegate = pf.createProxyInstance(proxyClass, instance, new DecoratorHandler(interceptorInfo,
instances, i - 1, instance));
+                }
+            }
+            InterceptorHandler interceptorHandler = new DefaultInterceptorHandler<T>(instance,
delegate, methodInterceptors, interceptorInstances);
 
             T proxyInstance = pf.createProxyInstance(proxyClass, instance, interceptorHandler);
             instance = proxyInstance;

Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/business/tests/NewProxyTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/business/tests/NewProxyTest.java?rev=1434980&r1=1434979&r2=1434980&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/business/tests/NewProxyTest.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/business/tests/NewProxyTest.java
Fri Jan 18 00:14:23 2013
@@ -75,7 +75,7 @@ public class NewProxyTest extends Abstra
         Map instances = new HashMap();
         instances.put(interceptorBean, interceptor);
         InterceptorHandler interceptorHandler
-                = new DefaultInterceptorHandler<RuntimeExceptionBindingTypeBean>(target,
interceptors, instances);
+                = new DefaultInterceptorHandler<RuntimeExceptionBindingTypeBean>(target,
target, interceptors, instances);
         
         InterceptorDecoratorProxyFactory factory = new InterceptorDecoratorProxyFactory(getWebBeansContext());
         Class<RuntimeExceptionBindingTypeBean> proxyClass

Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/resolution/InterceptorProxyChainTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/resolution/InterceptorProxyChainTest.java?rev=1434980&r1=1434979&r2=1434980&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/resolution/InterceptorProxyChainTest.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/resolution/InterceptorProxyChainTest.java
Fri Jan 18 00:14:23 2013
@@ -140,7 +140,7 @@ public class InterceptorProxyChainTest e
             interceptorInstances.put(interceptorBean, interceptorInstance);
         }
         InterceptorHandler interceptorHandler
-                = new DefaultInterceptorHandler<ClassMultiInterceptedClass>(internalInstance,
methodInterceptors, interceptorInstances);
+                = new DefaultInterceptorHandler<ClassMultiInterceptedClass>(internalInstance,
internalInstance, methodInterceptors, interceptorInstances);
 
         ClassMultiInterceptedClass proxyInstance = pf.createProxyInstance(proxyClass, internalInstance,
interceptorHandler);
         Assert.assertNotNull(proxyInstance);



Mime
View raw message