openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From strub...@apache.org
Subject svn commit: r1434949 - in /openwebbeans/trunk/webbeans-impl/src: main/java/org/apache/webbeans/component/ main/java/org/apache/webbeans/intercept/ test/java/org/apache/webbeans/newtests/decorators/common/ test/java/org/apache/webbeans/newtests/decorato...
Date Thu, 17 Jan 2013 23:06:46 GMT
Author: struberg
Date: Thu Jan 17 23:06:45 2013
New Revision: 1434949

URL: http://svn.apache.org/viewvc?rev=1434949&view=rev
Log:
OWB-344 prepare for new DecoratorBean and Decorator resolution

Added:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/DecoratorBean.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/decorators/common/Breeded.java
Modified:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/InjectionTargetBean.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/ManagedBean.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorHandlerPleaseRemove.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorResolutionService.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/WebBeansInterceptorConfig.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/decorators/common/Animal.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/decorators/common/Cow.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/decorators/tests/GenericDecoratorTest.java

Added: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/DecoratorBean.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/DecoratorBean.java?rev=1434949&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/DecoratorBean.java
(added)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/DecoratorBean.java
Thu Jan 17 23:06:45 2013
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.webbeans.component;
+
+import javax.enterprise.inject.spi.AnnotatedType;
+import javax.enterprise.inject.spi.Decorator;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+import java.util.Set;
+
+import org.apache.webbeans.config.WebBeansContext;
+
+/**
+ * Decorator Bean implementation.
+ */
+public class DecoratorBean<T> extends InjectionTargetBean<T> implements Decorator<T>
+{
+    public DecoratorBean(WebBeansContext webBeansContext, WebBeansType webBeansType, AnnotatedType<T>
annotatedType, Set<Type> types,
+                         Set<Annotation> qualifiers, Class<? extends Annotation>
scope, Class<T> beanClass, Set<Class<? extends Annotation>> stereotypes)
+    {
+        super(webBeansContext, webBeansType, annotatedType, types, qualifiers, scope, beanClass,
stereotypes);
+    }
+
+    @Override
+    public Set<Type> getDecoratedTypes()
+    {
+        return null;  //X TODO
+    }
+
+    @Override
+    public Type getDelegateType()
+    {
+        return null;  //X TODO
+    }
+
+    @Override
+    public Set<Annotation> getDelegateQualifiers()
+    {
+        return null;  //X TODO
+    }
+}

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/InjectionTargetBean.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/InjectionTargetBean.java?rev=1434949&r1=1434948&r2=1434949&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/InjectionTargetBean.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/InjectionTargetBean.java
Thu Jan 17 23:06:45 2013
@@ -63,7 +63,7 @@ public abstract class InjectionTargetBea
 
     /**
      * Decorators
-     * @deprecated will be replaced by InterceptorResolution logic
+     * @deprecated will be replaced by InterceptorResolution logic and moved to InjectionTargetImpl
      */
     protected List<Decorator<?>> decorators = new ArrayList<Decorator<?>>();
     

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/ManagedBean.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/ManagedBean.java?rev=1434949&r1=1434948&r2=1434949&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/ManagedBean.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/ManagedBean.java
Thu Jan 17 23:06:45 2013
@@ -85,7 +85,10 @@ public class ManagedBean<T> extends Inje
     {
         this.constructor = constructor;
     }
-    
+
+    /**
+     * TODO this must be performed at bean-build time!
+     */
     public boolean isPassivationCapable()
     {
         if (isPassivationCapable != null)

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorHandlerPleaseRemove.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorHandlerPleaseRemove.java?rev=1434949&r1=1434948&r2=1434949&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorHandlerPleaseRemove.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorHandlerPleaseRemove.java
Thu Jan 17 23:06:45 2013
@@ -58,10 +58,10 @@ import org.apache.webbeans.util.ClassUti
  * class via methods <code>defineManagedBean(class)</code> and Those methods
further call
  * <code>defineInterceptor(interceptor class)</code> and <code>defineDecorator(decorator
class)</code>
  * methods. Those methods finally call
- * {@link org.apache.webbeans.util.WebBeansUtil#defineInterceptor(org.apache.webbeans.component.creation.ManagedBeanCreatorImpl,
- *        javax.enterprise.inject.spi.ProcessInjectionTarget)} and
- * {@link org.apache.webbeans.util.WebBeansUtil#defineDecorator(org.apache.webbeans.component.creation.ManagedBeanCreatorImpl,
- *        javax.enterprise.inject.spi.ProcessInjectionTarget)}
+ * OLD: org.apache.webbeans.util.WebBeansUtil#defineInterceptor(org.apache.webbeans.component.creation.ManagedBeanBuilder,
+ *        javax.enterprise.inject.spi.ProcessInjectionTarget) and
+ * OLD: org.apache.webbeans.util.WebBeansUtil#defineDecorator(org.apache.webbeans.component.creation.ManagedBeanBuilder,
+ *        javax.enterprise.inject.spi.ProcessInjectionTarget)
  * methods for actual configuration.
  * <p>
  * Let's look at the "WebBeansUtil's" methods; 
@@ -164,7 +164,6 @@ public abstract class InterceptorHandler
     {
         this.bean = bean;
         webBeansContext = bean.getWebBeansContext();
-//        new Exception().fillInStackTrace().printStackTrace();
     }
 
     /**

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorResolutionService.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorResolutionService.java?rev=1434949&r1=1434948&r2=1434949&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorResolutionService.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorResolutionService.java
Thu Jan 17 23:06:45 2013
@@ -37,6 +37,7 @@ import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
+import java.util.LinkedHashMap;
 import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Map;
@@ -290,23 +291,28 @@ public class InterceptorResolutionServic
             return;
         }
 
-        List<Decorator<?>> appliedDecorators = new ArrayList<Decorator<?>>();
+        LinkedHashMap<Decorator<?>, Method> appliedDecorators = new LinkedHashMap<Decorator<?>,
Method>();
 
         for (Decorator decorator : decorators)
         {
-            if (isDecoratorInterceptsMethod(decorator, annotatedMethod))
+            Method decoratingMethod = getDecoratingMethod(decorator, annotatedMethod);
+            if (decoratingMethod != null)
             {
-                appliedDecorators.add(decorator);
+                appliedDecorators.put(decorator, decoratingMethod);
             }
         }
 
         if (appliedDecorators.size() > 0)
         {
-            methodInterceptorInfo.setMethodDecorators(new ArrayList<Decorator<?>>(appliedDecorators));
+            methodInterceptorInfo.setMethodDecorators(appliedDecorators);
         }
     }
 
-    private boolean isDecoratorInterceptsMethod(Decorator decorator, AnnotatedMethod annotatedMethod)
+    /**
+     * @return the Method from the decorator which decorates the annotatedMethod, <code>null</code>
+     *         if the given Decorator does <i>not</i> decorate the annotatedMethod
+     */
+    private Method getDecoratingMethod(Decorator decorator, AnnotatedMethod annotatedMethod)
     {
         String annotatedMethodName = annotatedMethod.getJavaMember().getName();
 
@@ -346,7 +352,7 @@ public class InterceptorResolutionServic
                             if (paramsMatch)
                             {
                                 // yikes our method is decorated by this very decorator type.
-                                return true;
+                                return decoratorMethod;
                             }
                         }
                     }
@@ -354,8 +360,7 @@ public class InterceptorResolutionServic
             }
         }
 
-        return false;
-
+        return null;
     }
 
     private void calculateCdiMethodInterceptors(BusinessMethodInterceptorInfo methodInterceptorInfo,
@@ -563,7 +568,7 @@ public class InterceptorResolutionServic
     {
         private Interceptor<?>[] ejbInterceptors = null;
         private Interceptor<?>[] cdiInterceptors = null;
-        private Decorator<?>[]   methodDecorators = null;
+        private LinkedHashMap<Decorator<?>, Method> methodDecorators = null;
 
         /**
          * lifecycle methods can serve multiple intercepton types :/
@@ -603,8 +608,11 @@ public class InterceptorResolutionServic
         /**
          * The (sorted) Decorator Beans for a specific method or <code>null</code>
          * if no Decorator exists for this method.
+         * This Map is sorted!
+         * Key: the Decorator Bean
+         * Value: the decorating method from the decorator instance
          */
-        public Decorator<?>[] getMethodDecorators()
+        public LinkedHashMap<Decorator<?>, Method> getMethodDecorators()
         {
             return methodDecorators;
         }
@@ -621,7 +629,7 @@ public class InterceptorResolutionServic
             }
         }
 
-        public void setMethodDecorators(List<Decorator<?>> methodDecorators)
+        public void setMethodDecorators(LinkedHashMap<Decorator<?>, Method> methodDecorators)
         {
             if (methodDecorators == null || methodDecorators.isEmpty())
             {
@@ -629,7 +637,7 @@ public class InterceptorResolutionServic
             }
             else
             {
-                this.methodDecorators = methodDecorators.toArray(new Decorator[methodDecorators.size()]);
+                this.methodDecorators = methodDecorators;
             }
         }
 

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/WebBeansInterceptorConfig.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/WebBeansInterceptorConfig.java?rev=1434949&r1=1434948&r2=1434949&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/WebBeansInterceptorConfig.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/WebBeansInterceptorConfig.java
Thu Jan 17 23:06:45 2013
@@ -30,6 +30,7 @@ import org.apache.webbeans.proxy.Interce
 import org.apache.webbeans.util.AnnotationUtil;
 import javax.enterprise.context.Dependent;
 import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.inject.spi.Decorator;
 import javax.enterprise.inject.spi.InterceptionType;
 import javax.enterprise.inject.spi.Interceptor;
 import javax.interceptor.AroundInvoke;
@@ -39,6 +40,7 @@ import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
+import java.util.LinkedHashMap;
 import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Map;
@@ -47,15 +49,12 @@ import java.util.logging.Level;
 import java.util.logging.Logger;
 
 import static org.apache.webbeans.intercept.InterceptorResolutionService.BeanInterceptorInfo;
+import static org.apache.webbeans.intercept.InterceptorResolutionService.BusinessMethodInterceptorInfo;
 
 
 /**
  * Configures the Web Beans related interceptors.
  *
- * @author <a href="mailto:gurkanerdogdu@yahoo.com">Gurkan Erdogdu</a>
- * @version $Rev$ $Date$
- * @see org.apache.webbeans.intercept.webbeans.WebBeansInterceptorBeanPleaseRemove
- *
  * TODO most of the stuff in this class can most probably get removed. All important logic
is contained in {@link InterceptorResolutionService}
  */
 public final class WebBeansInterceptorConfig
@@ -82,12 +81,14 @@ public final class WebBeansInterceptorCo
             BeanInterceptorInfo interceptorInfo = webBeansContext.getInterceptorResolutionService().
                     calculateInterceptorInfo(bean.getTypes(), bean.getQualifiers(), bean.getAnnotatedType());
 
+            //X TODO decorator stack
+
             Map<Method, List<Interceptor<?>>> methodInterceptors = new
HashMap<Method, List<Interceptor<?>>>();
             List<Method> nonBusinessMethods = new ArrayList<Method>();
-            for (Map.Entry<Method, InterceptorResolutionService.BusinessMethodInterceptorInfo>
miEntry : interceptorInfo.getBusinessMethodsInfo().entrySet())
+            for (Map.Entry<Method, BusinessMethodInterceptorInfo> miEntry : interceptorInfo.getBusinessMethodsInfo().entrySet())
             {
                 Method interceptedMethod = miEntry.getKey();
-                InterceptorResolutionService.BusinessMethodInterceptorInfo mii = miEntry.getValue();
+                BusinessMethodInterceptorInfo mii = miEntry.getValue();
                 List<Interceptor<?>> activeInterceptors = new ArrayList<Interceptor<?>>();
 
                 if (mii.getEjbInterceptors() != null)
@@ -112,6 +113,13 @@ public final class WebBeansInterceptorCo
                         activeInterceptors.add(interceptorInfo.getSelfInterceptorBean());
                     }
                 }
+                
+                if (mii.getMethodDecorators() != null)
+                {
+                    LinkedHashMap<Decorator<?>, Method> methodDecorators= mii.getMethodDecorators();
+                    //X TODO fill an own DecoratorDelegateInterceptor and add it to the activeInterceptors.
+                    //X TODO or find some alternative handling
+                }
 
                 if (activeInterceptors.size() > 0)
                 {

Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/decorators/common/Animal.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/decorators/common/Animal.java?rev=1434949&r1=1434948&r2=1434949&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/decorators/common/Animal.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/decorators/common/Animal.java
Thu Jan 17 23:06:45 2013
@@ -20,5 +20,17 @@ package org.apache.webbeans.newtests.dec
 
 public class Animal
 {
+    private String name;
+
+    public void setName(String name)
+    {
+        this.name = name;
+    }
+
+    public String getName()
+    {
+        return name;
+    }
+
 
 }

Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/decorators/common/Breeded.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/decorators/common/Breeded.java?rev=1434949&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/decorators/common/Breeded.java
(added)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/decorators/common/Breeded.java
Thu Jan 17 23:06:45 2013
@@ -0,0 +1,27 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.webbeans.newtests.decorators.common;
+
+/**
+ * Breeded animals
+ */
+public interface Breeded
+{
+    int getAge();
+}

Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/decorators/common/Cow.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/decorators/common/Cow.java?rev=1434949&r1=1434948&r2=1434949&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/decorators/common/Cow.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/decorators/common/Cow.java
Thu Jan 17 23:06:45 2013
@@ -18,7 +18,23 @@
 */
 package org.apache.webbeans.newtests.decorators.common;
 
-public class Cow extends Animal
+public class Cow extends Animal implements Breeded
 {
+    private String color;
 
+    @Override
+    public int getAge()
+    {
+        return 7;
+    }
+
+    public String getColor()
+    {
+        return color;
+    }
+
+    public void setColor(String color)
+    {
+        this.color = color;
+    }
 }

Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/decorators/tests/GenericDecoratorTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/decorators/tests/GenericDecoratorTest.java?rev=1434949&r1=1434948&r2=1434949&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/decorators/tests/GenericDecoratorTest.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/decorators/tests/GenericDecoratorTest.java
Thu Jan 17 23:06:45 2013
@@ -83,7 +83,7 @@ public class GenericDecoratorTest extend
 
         startContainer(classes, xmls);
 
-        DecoratedBean decoratedBean = (DecoratedBean) getInstance(DecoratedBean.class);
+        DecoratedBean decoratedBean = getInstance(DecoratedBean.class);
         Assert.assertTrue(decoratedBean.isDecoratorCalled());
     }
 



Mime
View raw message