openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From strub...@apache.org
Subject svn commit: r1622812 - in /openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans: config/BeansDeployer.java container/BeanManagerImpl.java container/InjectableBeanManager.java
Date Fri, 05 Sep 2014 22:20:41 GMT
Author: struberg
Date: Fri Sep  5 22:20:41 2014
New Revision: 1622812

URL: http://svn.apache.org/r1622812
Log:
OWB-995 some BeanManager methods must trigger an Exception if called before AfterBeanDiscovery,
etc

txs to Reinhard sandtner for the patch! applied.


Modified:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/BeansDeployer.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/BeanManagerImpl.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/InjectableBeanManager.java

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=1622812&r1=1622811&r2=1622812&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
Fri Sep  5 22:20:41 2014
@@ -471,6 +471,7 @@ public class BeansDeployer
     private void fireAfterBeanDiscoveryEvent()
     {
         BeanManagerImpl manager = webBeansContext.getBeanManagerImpl();
+        manager.setAfterBeanDiscoveryFired(true);
         manager.fireLifecycleEvent(new AfterBeanDiscoveryImpl(webBeansContext));
 
         webBeansContext.getWebBeansUtil().inspectErrorStack(
@@ -501,6 +502,7 @@ public class BeansDeployer
     private void fireAfterDeploymentValidationEvent()
     {
         BeanManagerImpl manager = webBeansContext.getBeanManagerImpl();
+        manager.setAfterDeploymentValidationFired(true);
         manager.fireLifecycleEvent(new AfterDeploymentValidationImpl(manager));
 
         webBeansContext.getWebBeansUtil().inspectErrorStack(

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=1622812&r1=1622811&r2=1622812&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
Fri Sep  5 22:20:41 2014
@@ -188,6 +188,17 @@ public class BeanManagerImpl implements 
      */
     private boolean inUse = false;
 
+    /**
+     * This flag will get set to {@code true} after the
+     * {@link javax.enterprise.inject.spi.AfterBeanDiscovery} gets fired
+     */
+    private boolean afterBeanDiscoveryFired = false;
+
+    /**
+     * This flag will get set to {@code true} after the
+     * {@link javax.enterprise.inject.spi.AfterDeploymentValidation} gets fired
+     */
+    private boolean afterDeploymentValidationFired = false;
 
     /**
      * we cache results of calls to {@link #isNormalScope(Class)} because
@@ -1289,4 +1300,24 @@ public class BeanManagerImpl implements 
     {
         return inUse;
     }
+
+    public boolean isAfterBeanDiscoveryFired()
+    {
+        return afterBeanDiscoveryFired;
+    }
+
+    public void setAfterBeanDiscoveryFired(boolean afterBeanDiscoveryFired)
+    {
+        this.afterBeanDiscoveryFired = afterBeanDiscoveryFired;
+    }
+
+    public boolean isAfterDeploymentValidationFired()
+    {
+        return afterDeploymentValidationFired;
+    }
+
+    public void setAfterDeploymentValidationFired(boolean afterDeploymentValidationFired)
+    {
+        this.afterDeploymentValidationFired = afterDeploymentValidationFired;
+    }
 }

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/InjectableBeanManager.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/InjectableBeanManager.java?rev=1622812&r1=1622811&r2=1622812&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/InjectableBeanManager.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/InjectableBeanManager.java
Fri Sep  5 22:20:41 2014
@@ -110,12 +110,16 @@ public class InjectableBeanManager imple
     @Override
     public Set<Bean<?>> getBeans(String name)
     {
+        checkAfterBeanDiscoveryProcessed("It's not allowed to call getBeans(String) before
AfterBeanDiscovery");
+
         return bm.getBeans(name);
     }
 
     @Override
     public Set<Bean<?>> getBeans(Type beanType, Annotation... qualifiers)
     {
+        checkAfterBeanDiscoveryProcessed("It's not allowed to call getBeans(Type, Annotation...)
before AfterBeanDiscovery");
+
         return bm.getBeans(beanType, qualifiers);
     }
 
@@ -134,6 +138,8 @@ public class InjectableBeanManager imple
     @Override
     public Object getInjectableReference(InjectionPoint injectionPoint, CreationalContext<?>
ctx)
     {
+        checkAfterDeploymentValidationFired("It's not allowed to call getInjectableReference(InjectionPoin,
CreationalContext) before AfterDeploymentValidation");
+
         return bm.getInjectableReference(injectionPoint, ctx);
     }
 
@@ -146,12 +152,16 @@ public class InjectableBeanManager imple
     @Override
     public Bean<?> getPassivationCapableBean(String id)
     {
+        checkAfterBeanDiscoveryProcessed("It's not allowed to call getPassivationCapableBean(String)
before AfterBeanDiscovery");
+
         return bm.getPassivationCapableBean(id);
     }
 
     @Override
     public Object getReference(Bean<?> bean, Type beanType, CreationalContext<?>
ctx)
     {
+        checkAfterDeploymentValidationFired("It's not allowed to call getReference(Bean,
Type, CreationalContext) before AfterDeploymentValidation");
+
         return bm.getReference(bean, beanType, ctx);
     }
 
@@ -200,30 +210,40 @@ public class InjectableBeanManager imple
     @Override
     public <X> Bean<? extends X> resolve(Set<Bean<? extends X>> beans)
     {
+        checkAfterBeanDiscoveryProcessed("It's not allowed to call resolve(Set<Bean>)
before AfterBeanDiscovery");
+
         return bm.resolve(beans);
     }
 
     @Override
     public List<Decorator<?>> resolveDecorators(Set<Type> types, Annotation...
qualifiers)
     {
+        checkAfterBeanDiscoveryProcessed("It's not allowed to call resolveDecorators(Set<Type>,
Annotation...) before AfterBeanDiscovery");
+
         return bm.resolveDecorators(types, qualifiers);
     }
 
     @Override
     public List<Interceptor<?>> resolveInterceptors(InterceptionType type, Annotation...
interceptorBindings)
     {
+        checkAfterBeanDiscoveryProcessed("It's not allowed to call resolveInterceptors(InterceptionType,
Annotation...) before AfterBeanDiscovery");
+
         return bm.resolveInterceptors(type, interceptorBindings);
     }
 
     @Override
     public <T> Set<ObserverMethod<? super T>> resolveObserverMethods(T
event, Annotation... qualifiers)
     {
+        checkAfterBeanDiscoveryProcessed("It's not allowed to call resolveObserverMethods(Object,
Annotation...) before AfterBeanDiscovery");
+
         return bm.resolveObserverMethods(event, qualifiers);
     }
 
     @Override
     public void validate(InjectionPoint injectionPoint)
     {
+        checkAfterBeanDiscoveryProcessed("It's not allowed to call validate(InjectionPoint)
before AfterBeanDiscovery");
+
         bm.validate(injectionPoint);
     }
 
@@ -370,7 +390,29 @@ public class InjectableBeanManager imple
         
         return true;
     }
-    
-    
+
+
+    /**
+     * @throws IllegalStateException if {@link javax.enterprise.inject.spi.AfterBeanDiscovery}
+     */
+    private void checkAfterBeanDiscoveryProcessed(String message)
+    {
+        if (!bm.isAfterBeanDiscoveryFired())
+        {
+            throw new IllegalStateException(message);
+        }
+    }
+
+    /**
+     * @throws IllegalStateException if {@link javax.enterprise.inject.spi.AfterDeploymentValidation}
+     */
+    private void checkAfterDeploymentValidationFired(String message)
+    {
+        if (!bm.isAfterDeploymentValidationFired())
+        {
+            throw new IllegalStateException(message);
+        }
+    }
+
 
 }



Mime
View raw message