openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject svn commit: r1647202 - in /openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans: config/BeansDeployer.java portable/events/discovery/AfterBeanDiscoveryImpl.java
Date Sun, 21 Dec 2014 20:12:49 GMT
Author: rmannibucau
Date: Sun Dec 21 20:12:49 2014
New Revision: 1647202

URL: http://svn.apache.org/r1647202
Log:
AfterBeanDiscovery started state + prevent producers for at created manually

Modified:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/BeansDeployer.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/discovery/AfterBeanDiscoveryImpl.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=1647202&r1=1647201&r2=1647202&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
Sun Dec 21 20:12:49 2014
@@ -36,6 +36,7 @@ import org.apache.webbeans.component.cre
 import org.apache.webbeans.component.creation.ObserverMethodsBuilder;
 import org.apache.webbeans.component.creation.ProducerFieldBeansBuilder;
 import org.apache.webbeans.component.creation.ProducerMethodBeansBuilder;
+import org.apache.webbeans.container.AnnotatedTypeWrapper;
 import org.apache.webbeans.container.BeanManagerImpl;
 import org.apache.webbeans.container.InjectableBeanManager;
 import org.apache.webbeans.container.InjectionResolver;
@@ -579,10 +580,13 @@ public class BeansDeployer
     {
         BeanManagerImpl manager = webBeansContext.getBeanManagerImpl();
         manager.setAfterBeanDiscoveryFired(true);
-        manager.fireLifecycleEvent(new AfterBeanDiscoveryImpl(webBeansContext));
+        final AfterBeanDiscoveryImpl event = new AfterBeanDiscoveryImpl(webBeansContext);
+        manager.fireLifecycleEvent(event);
 
         webBeansContext.getWebBeansUtil().inspectErrorStack(
                 "There are errors that are added by AfterBeanDiscovery event observers. Look
at logs for further details");
+
+        event.setStarted();
     }
     
     /**
@@ -1447,6 +1451,7 @@ public class BeansDeployer
 
                 final Set<ObserverMethod<?>> observerMethods;
                 final AnnotatedType<T> beanAnnotatedType = bean.getAnnotatedType();
+                final boolean ignoreProducer = AnnotatedTypeWrapper.class.isInstance(beanAnnotatedType);
                 if(bean.isEnabled())
                 {
                     observerMethods = new ObserverMethodsBuilder<T>(webBeansContext,
beanAnnotatedType).defineObserverMethods(bean);
@@ -1457,8 +1462,10 @@ public class BeansDeployer
                 }
 
                 final WebBeansContext wbc = bean.getWebBeansContext();
-                Set<ProducerFieldBean<?>> producerFields = new ProducerFieldBeansBuilder(wbc,
beanAnnotatedType).defineProducerFields(bean);
-                Set<ProducerMethodBean<?>> producerMethods = new ProducerMethodBeansBuilder(wbc,
beanAnnotatedType).defineProducerMethods(bean, producerFields);
+                Set<ProducerFieldBean<?>> producerFields =
+                        ignoreProducer ? Collections.emptySet() : new ProducerFieldBeansBuilder(wbc,
beanAnnotatedType).defineProducerFields(bean);
+                Set<ProducerMethodBean<?>> producerMethods =
+                        ignoreProducer ? Collections.emptySet() : new ProducerMethodBeansBuilder(wbc,
beanAnnotatedType).defineProducerMethods(bean, producerFields);
 
                 ManagedBean<T> managedBean = (ManagedBean<T>)bean;
                 Map<ProducerMethodBean<?>,AnnotatedMethod<?>> annotatedMethods
=

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/discovery/AfterBeanDiscoveryImpl.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/discovery/AfterBeanDiscoveryImpl.java?rev=1647202&r1=1647201&r2=1647202&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/discovery/AfterBeanDiscoveryImpl.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/discovery/AfterBeanDiscoveryImpl.java
Sun Dec 21 20:12:49 2014
@@ -57,6 +57,7 @@ public class AfterBeanDiscoveryImpl impl
     private static final Logger logger = WebBeansLoggerFacade.getLogger(AfterBeanDiscoveryImpl.class);
     private final WebBeansContext webBeansContext;
     private Object extension;
+    private boolean started;
 
     public AfterBeanDiscoveryImpl(WebBeansContext webBeansContext)
     {
@@ -64,12 +65,22 @@ public class AfterBeanDiscoveryImpl impl
         beanManager = this.webBeansContext.getBeanManagerImpl();
     }
 
+    public void setStarted()
+    {
+        started = true;
+    }
+
     /**
      * {@inheritDoc}
      */
     @Override
     public void addBean(Bean<?> bean)
     {
+        if (started)
+        {
+            throw new IllegalStateException("Don't call AfterBeanDiscovery.addBean(bean)
after the event is fired");
+        }
+
         AnnotatedType<?> annotatedType = webBeansContext.getAnnotatedElementFactory().newAnnotatedType(bean.getBeanClass());
 
         //Fire Event
@@ -171,6 +182,10 @@ public class AfterBeanDiscoveryImpl impl
     @Override
     public void addContext(Context context)
     {
+        if (started)
+        {
+            throw new IllegalStateException("Don't call AfterBeanDiscovery.addContext(...)
after the event is fired");
+        }
         beanManager.addContext(context);
 
     }
@@ -181,6 +196,10 @@ public class AfterBeanDiscoveryImpl impl
     @Override
     public void addDefinitionError(Throwable t)
     {
+        if (started)
+        {
+            throw new IllegalStateException("Don't call AfterBeanDiscovery.addBean(bean)
after the event is fired");
+        }
         beanManager.getErrorStack().pushError(t);
     }
 
@@ -190,6 +209,10 @@ public class AfterBeanDiscoveryImpl impl
     @Override
     public void addObserverMethod(ObserverMethod<?> observerMethod)
     {
+        if (started)
+        {
+            throw new IllegalStateException("Don't call AfterBeanDiscovery.addObserverMethod(...)
after the event is fired");
+        }
         ProcessObserverMethod<?, ?> event = new GProcessObservableMethod(null,observerMethod);
         beanManager.fireEvent(event, true, AnnotationUtil.EMPTY_ANNOTATION_ARRAY);
         beanManager.getNotificationManager().addObserver(observerMethod, observerMethod.getObservedType());
@@ -200,6 +223,10 @@ public class AfterBeanDiscoveryImpl impl
      */
     public <T> AnnotatedType<T> getAnnotatedType(Class<T> type, String
id)
     {
+        if (started)
+        {
+            throw new IllegalStateException("Don't call AfterBeanDiscovery.getAnnotatedType(...)
after the event is fired");
+        }
         return (AnnotatedType<T>) beanManager.getAdditionalAnnotatedType(type, id);
     }
 
@@ -208,6 +235,10 @@ public class AfterBeanDiscoveryImpl impl
      */
     public <T> Iterable<AnnotatedType<T>> getAnnotatedTypes(Class<T>
type)
     {
+        if (started)
+        {
+            throw new IllegalStateException("Don't call AfterBeanDiscovery.getAnnotatedTypes(...)
after the event is fired");
+        }
         return beanManager.getAnnotatedTypes(type);
     }
 



Mime
View raw message