openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject svn commit: r1623522 - in /openwebbeans/trunk/webbeans-impl/src: main/java/org/apache/webbeans/component/ main/java/org/apache/webbeans/component/creation/ main/java/org/apache/webbeans/config/ main/java/org/apache/webbeans/container/ main/java/org/apa...
Date Mon, 08 Sep 2014 19:50:49 GMT
Author: rmannibucau
Date: Mon Sep  8 19:50:48 2014
New Revision: 1623522

URL: http://svn.apache.org/r1623522
Log:
lazy UnproxyableResolutionException for private constructor

Modified:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/ManagedBean.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ManagedBeanBuilder.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/DeploymentValidationService.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/BeanManagerImpl.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/InjectionExceptionUtil.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/definition/proxyable/ProxyableBeanTypeTest.java

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=1623522&r1=1623521&r2=1623522&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 Sep  8 19:50:48 2014
@@ -33,7 +33,7 @@ import org.apache.webbeans.context.creat
  * @version $Rev$ $Date$
  */
 public class ManagedBean<T> extends InjectionTargetBean<T> implements InterceptedMarker,
PassivationCapable
-{    
+{
     public ManagedBean(WebBeansContext webBeansContext,
                        WebBeansType webBeansType,
                        AnnotatedType<T> annotated,
@@ -43,6 +43,11 @@ public class ManagedBean<T> extends Inje
         super(webBeansContext, webBeansType, annotated, beanAttributes, beanClass);
     }
 
+    public boolean valid()
+    {
+        return true;
+    }
+
     public T create(CreationalContext<T> creationalContext)
     {
         if (!(creationalContext instanceof CreationalContextImpl))

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ManagedBeanBuilder.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ManagedBeanBuilder.java?rev=1623522&r1=1623521&r2=1623522&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ManagedBeanBuilder.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ManagedBeanBuilder.java
Mon Sep  8 19:50:48 2014
@@ -18,6 +18,8 @@
  */
 package org.apache.webbeans.component.creation;
 
+import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.UnproxyableResolutionException;
 import javax.enterprise.inject.spi.AnnotatedType;
 import javax.enterprise.inject.spi.BeanAttributes;
 
@@ -59,12 +61,42 @@ public class ManagedBeanBuilder<T, M ext
      */
     public M getBean()
     {
-        M bean = (M)new ManagedBean<T>(webBeansContext, WebBeansType.MANAGED, annotatedType,
beanAttributes, annotatedType.getJavaClass());
+        M bean = (M) new ManagedBean<T>(webBeansContext, WebBeansType.MANAGED, annotatedType,
beanAttributes, annotatedType.getJavaClass());
         bean.setEnabled(webBeansContext.getWebBeansUtil().isBeanEnabled(annotatedType, bean.getStereotypes()));
         webBeansContext.getWebBeansUtil().checkManagedBeanCondition(annotatedType);
         WebBeansUtil.checkGenericType(annotatedType.getJavaClass(), beanAttributes.getScope());
         webBeansContext.getWebBeansUtil().validateBeanInjection(bean);
-        webBeansContext.getDeploymentValidationService().validateProxyable(bean);
-        return bean;
+
+        final UnproxyableResolutionException lazyException = webBeansContext.getDeploymentValidationService().validateProxyable(bean);
+        if (lazyException == null)
+        {
+            return bean;
+        }
+        return (M) new UnproxyableBean<T>(webBeansContext, WebBeansType.MANAGED, beanAttributes,
annotatedType, annotatedType.getJavaClass(), lazyException);
+    }
+
+    private static class UnproxyableBean<T> extends ManagedBean<T>
+    {
+        private final UnproxyableResolutionException exception;
+
+        public UnproxyableBean(final WebBeansContext webBeansContext, final WebBeansType
webBeansType,
+                               final BeanAttributes<T> beanAttributes, final AnnotatedType<T>
at, final Class<T> beanClass,
+                               final UnproxyableResolutionException error)
+        {
+            super(webBeansContext, webBeansType, at, beanAttributes, beanClass);
+            this.exception = error;
+        }
+
+        @Override
+        public boolean valid()
+        {
+            throw exception;
+        }
+
+        @Override
+        public T create(final CreationalContext<T> creationalContext)
+        {
+            throw exception;
+        }
     }
 }

Modified: 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=1623522&r1=1623521&r2=1623522&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/DeploymentValidationService.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/DeploymentValidationService.java
Mon Sep  8 19:50:48 2014
@@ -18,6 +18,7 @@
  */
 package org.apache.webbeans.config;
 
+import static org.apache.webbeans.util.InjectionExceptionUtil.createUnproxyableResolutionException;
 import static org.apache.webbeans.util.InjectionExceptionUtil.throwUnproxyableResolutionException;
 
 import java.lang.reflect.Constructor;
@@ -27,6 +28,7 @@ import java.util.Set;
 
 import javax.enterprise.inject.Disposes;
 import javax.enterprise.inject.TransientReference;
+import javax.enterprise.inject.UnproxyableResolutionException;
 import javax.enterprise.inject.spi.Annotated;
 import javax.enterprise.inject.spi.Bean;
 import javax.enterprise.inject.spi.Decorator;
@@ -55,8 +57,9 @@ public class DeploymentValidationService
     /**
      * Checks the unproxyable condition.
      * @throws org.apache.webbeans.exception.WebBeansConfigurationException if bean is not
proxied by the container
+     * @return exception TCKs validate at runtime
      */
-    public void validateProxyable(OwbBean<?> bean)
+    public UnproxyableResolutionException validateProxyable(OwbBean<?> bean)
     {
         // Unproxyable test for NormalScoped beans
         if (webBeansContext.getBeanManagerImpl().isNormalScope(bean.getScope()))
@@ -99,7 +102,12 @@ public class DeploymentValidationService
                     }
                     else if (Modifier.isPrivate(cons.getModifiers()))
                     {
+                        final boolean containsViolation = violationMessage.containsViolation();
                         violationMessage.addLine(beanClass.getName(), " has a >private<
no-arg constructor! CDI doesn't allow to proxy that.");
+                        if (!containsViolation)
+                        { // lazy
+                            return createUnproxyableResolutionException(violationMessage);
+                        }
                     }
                 }
 
@@ -110,6 +118,7 @@ public class DeploymentValidationService
                 }
             }
         }
+        return null;
     }
 
     /**

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/BeanManagerImpl.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/BeanManagerImpl.java?rev=1623522&r1=1623521&r2=1623522&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/BeanManagerImpl.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/BeanManagerImpl.java
Mon Sep  8 19:50:48 2014
@@ -60,6 +60,7 @@ import org.apache.webbeans.component.Dec
 import org.apache.webbeans.component.EnterpriseBeanMarker;
 import org.apache.webbeans.component.InjectionTargetBean;
 import org.apache.webbeans.component.JmsBeanMarker;
+import org.apache.webbeans.component.ManagedBean;
 import org.apache.webbeans.component.NewBean;
 import org.apache.webbeans.component.OwbBean;
 import org.apache.webbeans.component.ProducerAwareInjectionTargetBean;
@@ -686,7 +687,10 @@ public class BeanManagerImpl implements 
             creationalContext = webBeansContext.getCreationalContextFactory().wrappedCreationalContext(creationalContext,
bean);
         }
 
-
+        if (ManagedBean.class.isInstance(bean))
+        {
+            ManagedBean.class.cast(bean).valid();
+        }
 
         //Check type if bean type is given
         if(beanType != null && beanType != Object.class)

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/InjectionExceptionUtil.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/InjectionExceptionUtil.java?rev=1623522&r1=1623521&r2=1623522&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/InjectionExceptionUtil.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/InjectionExceptionUtil.java
Mon Sep  8 19:50:48 2014
@@ -38,7 +38,12 @@ public class InjectionExceptionUtil
 
     public static void throwUnproxyableResolutionException(ViolationMessageBuilder violationMessage)
     {
-        throw new UnproxyableResolutionException(
+        throw createUnproxyableResolutionException(violationMessage);
+    }
+
+    public static UnproxyableResolutionException createUnproxyableResolutionException(ViolationMessageBuilder
violationMessage)
+    {
+        return new UnproxyableResolutionException(
                 newViolation("WebBeans with api type with normal scope must be proxyable.")
                         .addLine(violationMessage.toString())
                         .toString());

Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/definition/proxyable/ProxyableBeanTypeTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/definition/proxyable/ProxyableBeanTypeTest.java?rev=1623522&r1=1623521&r2=1623522&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/definition/proxyable/ProxyableBeanTypeTest.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/definition/proxyable/ProxyableBeanTypeTest.java
Mon Sep  8 19:50:48 2014
@@ -56,7 +56,7 @@ public class ProxyableBeanTypeTest exten
             Assert.assertNotNull(testInstance);
 
             Assert.assertEquals(42, testInstance.externalMethod());
-            Assert.assertEquals(4711, testInstance.staticMethod());
+            Assert.assertEquals(4711, BeanWithPrivateFinalMethod.staticMethod());
         }
         finally
         {



Mime
View raw message