openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject svn commit: r1436599 - in /openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans: component/ config/ portable/
Date Mon, 21 Jan 2013 20:37:49 GMT
Author: arne
Date: Mon Jan 21 20:37:48 2013
New Revision: 1436599

URL: http://svn.apache.org/viewvc?rev=1436599&view=rev
Log:
OWB-344: Fixed passivation-capable checks

Added:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/DeploymentValidationService.java
Modified:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/AbstractOwbBean.java
    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/component/OwbBean.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/BeansDeployer.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/WebBeansContext.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/InjectionTargetImpl.java

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/AbstractOwbBean.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/AbstractOwbBean.java?rev=1436599&r1=1436598&r2=1436599&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/AbstractOwbBean.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/AbstractOwbBean.java
Mon Jan 21 20:37:48 2013
@@ -18,6 +18,7 @@
  */
 package org.apache.webbeans.component;
 
+import java.io.Serializable;
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Member;
 import java.lang.reflect.ParameterizedType;
@@ -32,7 +33,6 @@ import java.util.logging.Logger;
 import javax.enterprise.context.Dependent;
 import javax.enterprise.context.spi.CreationalContext;
 import javax.enterprise.inject.CreationException;
-import javax.enterprise.inject.Disposes;
 import javax.enterprise.inject.spi.InjectionPoint;
 import javax.enterprise.inject.spi.InjectionTarget;
 import javax.enterprise.inject.spi.Producer;
@@ -41,7 +41,6 @@ import org.apache.webbeans.config.OWBLog
 import org.apache.webbeans.config.WebBeansContext;
 import org.apache.webbeans.container.BeanManagerImpl;
 import org.apache.webbeans.context.creational.CreationalContextImpl;
-import org.apache.webbeans.exception.WebBeansConfigurationException;
 import org.apache.webbeans.logger.WebBeansLoggerFacade;
 
 /**
@@ -263,11 +262,27 @@ public abstract class AbstractOwbBean<T>
         return passivatingId;
     }
     
+    /**
+     * TODO this must be performed at bean-build time!
+     */
     public boolean isPassivationCapable()
     {
+        if (isPassivationCapable != null)
+        {
+            return isPassivationCapable.booleanValue();
+        }
+        if(Serializable.class.isAssignableFrom(getReturnType()))
+        {
+            isPassivationCapable = Boolean.TRUE;
+            return true;
+        }
+        isPassivationCapable = Boolean.FALSE;
         return false;
     }
 
+    /** cache previously calculated result */
+    private Boolean isPassivationCapable = null;
+
     public void setProducer(Producer<T> producer)
     {
         this.producer = producer;
@@ -457,29 +472,4 @@ public abstract class AbstractOwbBean<T>
     {
         return getScope().equals(Dependent.class);
     }
-    
-    public void validatePassivationDependencies()
-    {
-        if(isPassivationCapable())
-        {
-            Set<InjectionPoint> beanInjectionPoints = getInjectionPoints();
-            for(InjectionPoint injectionPoint : beanInjectionPoints)
-            {
-                if(!injectionPoint.isTransient())
-                {
-                    if(!getWebBeansContext().getWebBeansUtil().isPassivationCapableDependency(injectionPoint))
-                    {
-                        if(injectionPoint.getAnnotated().isAnnotationPresent(Disposes.class))
-                        {
-                            continue;
-                        }
-                        throw new WebBeansConfigurationException(
-                                "Passivation capable beans must satisfy passivation capable
dependencies. " +
-                                "Bean : " + toString() + " does not satisfy. Details about
the Injection-point: " +
-                                        injectionPoint.toString());
-                    }
-                }
-            }            
-        }
-    }
 }

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=1436599&r1=1436598&r2=1436599&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
Mon Jan 21 20:37:48 2013
@@ -86,5 +86,4 @@ public abstract class InjectionTargetBea
     {
         return annotatedType;
     }
-
 }

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=1436599&r1=1436598&r2=1436599&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
Mon Jan 21 20:37:48 2013
@@ -18,7 +18,6 @@
  */
 package org.apache.webbeans.component;
 
-import java.io.Serializable;
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Constructor;
 import java.lang.reflect.Type;
@@ -84,30 +83,4 @@ public class ManagedBean<T> extends Inje
     {
         this.constructor = constructor;
     }
-
-    /**
-     * TODO this must be performed at bean-build time!
-     */
-    public boolean isPassivationCapable()
-    {
-        if (isPassivationCapable != null)
-        {
-            return isPassivationCapable.booleanValue();
-        }
-        if(Serializable.class.isAssignableFrom(getReturnType()))
-        {
-            //X TODO add proper serialisation checks for all decorators and interceptors!
-
-
-            isPassivationCapable = Boolean.TRUE;
-            return true;
-        }
-
-        isPassivationCapable = Boolean.FALSE;
-        return false;
-    }
-
-    /** cache previously calculated result */
-    private Boolean isPassivationCapable = null;
-
 }

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/OwbBean.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/OwbBean.java?rev=1436599&r1=1436598&r2=1436599&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/OwbBean.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/OwbBean.java
Mon Jan 21 20:37:48 2013
@@ -38,6 +38,11 @@ import org.apache.webbeans.config.WebBea
 public interface OwbBean<T> extends Bean<T>
 {
     /**
+     * @return the producer for this bean;
+     */
+    public Producer<T> getProducer();
+
+    /**
      * Sets the producer for this bean
      *
      * @param producer
@@ -126,11 +131,5 @@ public interface OwbBean<T> extends Bean
      */
     public boolean isDependent();
     
-    /**
-     * If bean is passivation capable, it validate all of its dependencies.
-     * @throws org.apache.webbeans.exception.WebBeansConfigurationException if not satisfy
passivation dependencies
-     */
-    public void validatePassivationDependencies();
-
     public WebBeansContext getWebBeansContext();
 }

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/BeansDeployer.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/BeansDeployer.java?rev=1436599&r1=1436598&r2=1436599&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/BeansDeployer.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/BeansDeployer.java
Mon Jan 21 20:37:48 2013
@@ -735,7 +735,7 @@ public class BeansDeployer
         
         if(validate)
         {
-            ((OwbBean<?>)beanObj).validatePassivationDependencies();
+            webBeansContext.getDeploymentValidationService().validatePassivationCapable((OwbBean<?>)beanObj);
         }
     }
 

Added: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/DeploymentValidationService.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/DeploymentValidationService.java?rev=1436599&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/DeploymentValidationService.java
(added)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/DeploymentValidationService.java
Mon Jan 21 20:37:48 2013
@@ -0,0 +1,118 @@
+/*
+ * 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.config;
+
+import java.util.Set;
+
+import javax.enterprise.inject.Disposes;
+import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.inject.spi.Decorator;
+import javax.enterprise.inject.spi.InjectionPoint;
+import javax.enterprise.inject.spi.Interceptor;
+import javax.enterprise.inject.spi.PassivationCapable;
+
+import org.apache.webbeans.component.OwbBean;
+import org.apache.webbeans.component.ProducerMethodBean;
+import org.apache.webbeans.exception.WebBeansConfigurationException;
+import org.apache.webbeans.intercept.InterceptorResolutionService.BeanInterceptorInfo;
+import org.apache.webbeans.portable.InjectionTargetImpl;
+
+public class DeploymentValidationService
+{
+
+    private WebBeansContext webBeansContext;
+
+    public DeploymentValidationService(WebBeansContext webBeansContext)
+    {
+        this.webBeansContext = webBeansContext;
+    }
+
+    /**
+     * If bean is passivation capable, it validate all of its dependencies.
+     * @throws org.apache.webbeans.exception.WebBeansConfigurationException if not satisfy
passivation dependencies
+     */
+    public <T> void validatePassivationCapable(OwbBean<T> bean)
+    {
+        if (isPassivationCapable(bean))
+        {
+            if (!(bean instanceof ProducerMethodBean))
+            {
+                validatePassivationCapableDependencies(bean, bean.getInjectionPoints());
+            }
+            if (bean.getProducer() instanceof InjectionTargetImpl)
+            {
+                InjectionTargetImpl<T> injectionTarget = (InjectionTargetImpl<T>)bean.getProducer();
+                BeanInterceptorInfo interceptorInfo = injectionTarget.getInterceptorInfo();
+                if (interceptorInfo != null)
+                {
+                    for (Interceptor<?> ejbInterceptor: interceptorInfo.getEjbInterceptors())
+                    {
+                        validatePassivationCapableDependency(bean, ejbInterceptor);
+                    }
+                    for (Interceptor<?> cdiInterceptor: interceptorInfo.getCdiInterceptors())
+                    {
+                        validatePassivationCapableDependency(bean, cdiInterceptor);
+                    }
+                    for (Decorator<?> decorators: interceptorInfo.getDecorators())
+                    {
+                        validatePassivationCapableDependency(bean, decorators);
+                    }
+                }
+            }
+        }
+    }
+    
+    private <T> void validatePassivationCapableDependency(Bean<T> bean, Bean<?>
dependentBean)
+    {
+        if (!isPassivationCapable(dependentBean))
+        {
+            String type = dependentBean instanceof Interceptor? "Interceptor ": "Decorator
"; 
+            throw new WebBeansConfigurationException(
+                    "Passivation capable beans must satisfy passivation capable dependencies.
" +
+                    "Bean : " + bean.toString() + " does not satisfy. " + type + dependentBean.toString()
+ " is not passivation capable");
+        }
+        validatePassivationCapableDependencies(bean, dependentBean.getInjectionPoints());
+    }
+
+    private <T> void validatePassivationCapableDependencies(Bean<T> bean, Set<InjectionPoint>
injectionPoints)
+    {
+        for (InjectionPoint injectionPoint: injectionPoints)
+        {
+            if(!injectionPoint.isTransient())
+            {
+                if(!webBeansContext.getWebBeansUtil().isPassivationCapableDependency(injectionPoint))
+                {
+                    if(injectionPoint.getAnnotated().isAnnotationPresent(Disposes.class))
+                    {
+                        continue;
+                    }
+                    throw new WebBeansConfigurationException(
+                            "Passivation capable beans must satisfy passivation capable dependencies.
" +
+                            "Bean : " + bean.toString() + " does not satisfy. Details about
the Injection-point: " +
+                                    injectionPoint.toString());
+                }
+            }
+        }
+    }
+    
+    private boolean isPassivationCapable(Bean<?> bean)
+    {
+        return bean instanceof OwbBean? ((OwbBean<?>)bean).isPassivationCapable():
bean instanceof PassivationCapable;
+    }
+}

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/WebBeansContext.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/WebBeansContext.java?rev=1436599&r1=1436598&r2=1436599&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/WebBeansContext.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/WebBeansContext.java
Mon Jan 21 20:37:48 2013
@@ -91,6 +91,7 @@ public class WebBeansContext
     private final SecurityService securityService;
     private final LoaderService loaderService;
     private final InterceptorResolutionService interceptorResolutionService = new InterceptorResolutionService(this);
+    private final DeploymentValidationService deploymentValidationService = new DeploymentValidationService(this);
     private ScannerService scannerService;
 
     public WebBeansContext()
@@ -435,5 +436,8 @@ public class WebBeansContext
         return loaderService;
     }
 
-
+    public DeploymentValidationService getDeploymentValidationService()
+    {
+        return deploymentValidationService;
+    }
 }

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=1436599&r1=1436598&r2=1436599&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
Mon Jan 21 20:37:48 2013
@@ -136,6 +136,11 @@ public class InjectionTargetImpl<T> exte
         this.preDestroyMethods = preDestroyMethods;
     }
 
+    public BeanInterceptorInfo getInterceptorInfo()
+    {
+        return interceptorInfo;
+    }
+
     public void setInterceptorInfo(BeanInterceptorInfo interceptorInfo, Class<? extends
T> proxyClass, Map<Method, List<Interceptor<?>>> methodInterceptors,
                                    List<Interceptor<?>> postConstructInterceptors,
List<Interceptor<?>> preDestroyInterceptors)
     {



Mime
View raw message