openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From strub...@apache.org
Subject svn commit: r1797607 - in /openwebbeans/trunk/webbeans-impl/src: main/java/org/apache/webbeans/annotation/ main/java/org/apache/webbeans/component/ main/java/org/apache/webbeans/config/ main/java/org/apache/webbeans/portable/events/discovery/ test/java...
Date Sun, 04 Jun 2017 19:50:07 GMT
Author: struberg
Date: Sun Jun  4 19:50:07 2017
New Revision: 1797607

URL: http://svn.apache.org/viewvc?rev=1797607&view=rev
Log:
OWB-1186 add AnnotatedTypeConfigurator support in BeforeBeanDiscovery

Added:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/discovery/AnnotatedTypeConfiguratorHolder.java
  (with props)
Modified:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/annotation/ApplicationScopeLiteral.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/annotation/RequestedScopeLiteral.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/annotation/SessionScopeLiteral.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/AbstractOwbBean.java
    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/BeforeBeanDiscoveryImpl.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/portable/BeforeBeanDiscoveryTest.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/portable/addannotated/extension/AddAdditionalAnnotatedTypeExtension.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/portable/events/extensions/AddBeanExtension.java

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/annotation/ApplicationScopeLiteral.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/annotation/ApplicationScopeLiteral.java?rev=1797607&r1=1797606&r2=1797607&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/annotation/ApplicationScopeLiteral.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/annotation/ApplicationScopeLiteral.java
Sun Jun  4 19:50:07 2017
@@ -29,6 +29,7 @@ import javax.enterprise.util.AnnotationL
  */
 public class ApplicationScopeLiteral extends AnnotationLiteral<ApplicationScoped> implements
ApplicationScoped
 {
+    public static final ApplicationScopeLiteral INSTANCE = new ApplicationScopeLiteral();
 
     private static final long serialVersionUID = 8089948111744513390L;
 }

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/annotation/RequestedScopeLiteral.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/annotation/RequestedScopeLiteral.java?rev=1797607&r1=1797606&r2=1797607&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/annotation/RequestedScopeLiteral.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/annotation/RequestedScopeLiteral.java
Sun Jun  4 19:50:07 2017
@@ -28,6 +28,7 @@ import javax.enterprise.context.RequestS
  */
 public class RequestedScopeLiteral extends EmptyAnnotationLiteral<RequestScoped> implements
RequestScoped
 {
+    public static final RequestedScopeLiteral INSTANCE = new RequestedScopeLiteral();
 
     private static final long serialVersionUID = -7333612898060695008L;
 }

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/annotation/SessionScopeLiteral.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/annotation/SessionScopeLiteral.java?rev=1797607&r1=1797606&r2=1797607&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/annotation/SessionScopeLiteral.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/annotation/SessionScopeLiteral.java
Sun Jun  4 19:50:07 2017
@@ -28,6 +28,7 @@ import javax.enterprise.context.SessionS
  */
 public class SessionScopeLiteral extends EmptyAnnotationLiteral<SessionScoped> implements
SessionScoped
 {
+    public static final SessionScopeLiteral INSTANCE = new SessionScopeLiteral();
 
     private static final long serialVersionUID = -7469945140661485990L;
 }

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=1797607&r1=1797606&r2=1797607&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
Sun Jun  4 19:50:07 2017
@@ -205,19 +205,21 @@ public abstract class AbstractOwbBean<T>
         }
         if (passivatingId == null)
         {
-            passivatingId = providedId();
+            StringBuilder sb = new StringBuilder(webBeansType.toString()).append('#');
 
-            if (passivatingId == null)
+            String providedId = providedId();
+            if (providedId != null)
             {
-                StringBuilder sb = new StringBuilder(webBeansType.toString()).append('#');
-                sb.append(getReturnType()).append('#');
-                for (Annotation qualifier : getQualifiers())
-                {
-                    sb.append(qualifier.toString()).append(',');
-                }
+                sb.append(providedId).append('#');
+            }
 
-                passivatingId = sb.toString();
+            sb.append(getReturnType()).append('#');
+            for (Annotation qualifier : getQualifiers())
+            {
+                sb.append(qualifier.toString()).append(',');
             }
+
+            passivatingId = sb.toString();
         }
 
         return passivatingId;

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=1797607&r1=1797606&r2=1797607&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 Jun  4 19:50:07 2017
@@ -70,6 +70,7 @@ import org.apache.webbeans.portable.even
 import org.apache.webbeans.portable.events.discovery.AfterBeanDiscoveryImpl;
 import org.apache.webbeans.portable.events.discovery.AfterDeploymentValidationImpl;
 import org.apache.webbeans.portable.events.discovery.AfterTypeDiscoveryImpl;
+import org.apache.webbeans.portable.events.discovery.AnnotatedTypeConfiguratorHolder;
 import org.apache.webbeans.portable.events.discovery.BeforeBeanDiscoveryImpl;
 import org.apache.webbeans.portable.events.generics.GProcessAnnotatedType;
 import org.apache.webbeans.portable.events.generics.GProcessManagedBean;
@@ -674,6 +675,14 @@ public class BeansDeployer
         BeanManagerImpl manager = webBeansContext.getBeanManagerImpl();
         BeforeBeanDiscoveryImpl event = new BeforeBeanDiscoveryImpl(webBeansContext);
         manager.fireLifecycleEvent(event);
+        for (AnnotatedTypeConfiguratorHolder holder : event.getAnnotatedTypeConfigurators())
+        {
+            manager.addAdditionalAnnotatedType(
+                holder.getExtension(),
+                holder.getAnnotatedTypeConfigurator().getAnnotated(),
+                holder.getId());
+        }
+
         event.setStarted();
     }
     

Added: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/discovery/AnnotatedTypeConfiguratorHolder.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/discovery/AnnotatedTypeConfiguratorHolder.java?rev=1797607&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/discovery/AnnotatedTypeConfiguratorHolder.java
(added)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/discovery/AnnotatedTypeConfiguratorHolder.java
Sun Jun  4 19:50:07 2017
@@ -0,0 +1,55 @@
+/*
+ * 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.portable.events.discovery;
+
+import javax.enterprise.inject.spi.Extension;
+import javax.enterprise.inject.spi.configurator.AnnotatedTypeConfigurator;
+
+/**
+ * Hold information for lifecycle Events which can modify or add multiple
+ * {@link AnnotatedTypeConfigurator}
+ */
+public class AnnotatedTypeConfiguratorHolder<T>
+{
+    private final Extension extension;
+    private final String id;
+    private final AnnotatedTypeConfigurator<T> annotatedTypeConfigurator;
+
+    public AnnotatedTypeConfiguratorHolder(Extension extension, String id, AnnotatedTypeConfigurator<T>
annotatedTypeConfigurator)
+    {
+        this.extension = extension;
+        this.id = id;
+        this.annotatedTypeConfigurator = annotatedTypeConfigurator;
+    }
+
+    public Extension getExtension()
+    {
+        return extension;
+    }
+
+    public String getId()
+    {
+        return id;
+    }
+
+    public AnnotatedTypeConfigurator<T> getAnnotatedTypeConfigurator()
+    {
+        return annotatedTypeConfigurator;
+    }
+}

Propchange: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/discovery/AnnotatedTypeConfiguratorHolder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/discovery/BeforeBeanDiscoveryImpl.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/discovery/BeforeBeanDiscoveryImpl.java?rev=1797607&r1=1797606&r2=1797607&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/discovery/BeforeBeanDiscoveryImpl.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/discovery/BeforeBeanDiscoveryImpl.java
Sun Jun  4 19:50:07 2017
@@ -19,6 +19,9 @@
 package org.apache.webbeans.portable.events.discovery;
 
 import java.lang.annotation.Annotation;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
 
 import javax.enterprise.inject.spi.AnnotatedType;
 import javax.enterprise.inject.spi.BeforeBeanDiscovery;
@@ -26,6 +29,7 @@ import javax.enterprise.inject.spi.Exten
 import javax.enterprise.inject.spi.configurator.AnnotatedTypeConfigurator;
 
 import org.apache.webbeans.config.WebBeansContext;
+import org.apache.webbeans.configurator.AnnotatedTypeConfiguratorImpl;
 import org.apache.webbeans.container.BeanManagerImpl;
 import org.apache.webbeans.container.ExternalScope;
 import org.apache.webbeans.deployment.StereoTypeModel;
@@ -43,6 +47,7 @@ public class BeforeBeanDiscoveryImpl ext
     private BeanManagerImpl beanManager = null;
     private final WebBeansContext webBeansContext;
     private Extension extension;
+    private Map<String, AnnotatedTypeConfiguratorHolder> annotatedTypeConfigurators
= new HashMap<>();
 
     public BeforeBeanDiscoveryImpl(WebBeansContext webBeansContext)
     {
@@ -119,9 +124,20 @@ public class BeforeBeanDiscoveryImpl ext
     public <T> AnnotatedTypeConfigurator<T> addAnnotatedType(Class<T> clazz,
String id)
     {
         checkState();
-        throw new UnsupportedOperationException("CDI 2.0 not yet imlemented");
+        String key = clazz.getName() + id;
+        AnnotatedTypeConfiguratorHolder configuratorHolder = annotatedTypeConfigurators.get(key);
+        if (configuratorHolder == null)
+        {
+            AnnotatedType<T> initialAnnotatedType = webBeansContext.getAnnotatedElementFactory().newAnnotatedType(clazz);
+            AnnotatedTypeConfigurator<T> configurator = new AnnotatedTypeConfiguratorImpl(webBeansContext,
initialAnnotatedType);
+            configuratorHolder = new AnnotatedTypeConfiguratorHolder(extension, id, configurator);
+            annotatedTypeConfigurators.put(key, configuratorHolder);
+        }
+
+        return configuratorHolder.getAnnotatedTypeConfigurator();
     }
 
+
     //X TODO OWB-1182 CDI 2.0
     @Override
     public <T extends Annotation> AnnotatedTypeConfigurator<T> configureInterceptorBinding(Class<T>
aClass)
@@ -163,4 +179,10 @@ public class BeforeBeanDiscoveryImpl ext
     {
         this.extension = extension;
     }
+
+    public Collection<AnnotatedTypeConfiguratorHolder> getAnnotatedTypeConfigurators()
+    {
+        return annotatedTypeConfigurators.values();
+    }
+
 }

Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/portable/BeforeBeanDiscoveryTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/portable/BeforeBeanDiscoveryTest.java?rev=1797607&r1=1797606&r2=1797607&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/portable/BeforeBeanDiscoveryTest.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/portable/BeforeBeanDiscoveryTest.java
Sun Jun  4 19:50:07 2017
@@ -29,7 +29,6 @@ import org.junit.Assert;
  */
 import org.apache.webbeans.test.AbstractUnitTest;
 import org.apache.webbeans.test.portable.addannotated.extension.AddAdditionalAnnotatedTypeExtension;
-import org.apache.webbeans.test.portable.events.extensions.AddBeanExtension.MyBean;
 import org.junit.Test;
 
 public class BeforeBeanDiscoveryTest extends AbstractUnitTest
@@ -46,7 +45,7 @@ public class BeforeBeanDiscoveryTest ext
 
         startContainer(beanClasses, beanXmls);
 
-        Bean<?> bean = getBeanManager().getBeans(MyBean.class, new AnnotationLiteral<Default>()
+        Bean<?> bean = getBeanManager().getBeans(AddAdditionalAnnotatedTypeExtension.MyBean.class,
new AnnotationLiteral<Default>()
         {
         }).iterator().next();
 
@@ -54,6 +53,14 @@ public class BeforeBeanDiscoveryTest ext
         // type during before bean discovery in the extension
         Assert.assertNotNull(bean);
 
+        AddAdditionalAnnotatedTypeExtension.MyConfigBean1 myConfigBean1 = getInstance(AddAdditionalAnnotatedTypeExtension.MyConfigBean1.class);
+        Assert.assertNotNull(myConfigBean1);
+        Assert.assertEquals("1", myConfigBean1.getId());
+
+        AddAdditionalAnnotatedTypeExtension.MyConfigBean2 myConfigBean2 = getInstance(AddAdditionalAnnotatedTypeExtension.MyConfigBean2.class);
+        Assert.assertNotNull(myConfigBean2);
+        Assert.assertEquals("2", myConfigBean2.getId());
+
         shutDownContainer();
     }
 
@@ -63,13 +70,13 @@ public class BeforeBeanDiscoveryTest ext
         Collection<String> beanXmls = new ArrayList<String>();
 
         Collection<Class<?>> beanClasses = new ArrayList<Class<?>>();
-        beanClasses.add(MyBean.class);
+        beanClasses.add(AddAdditionalAnnotatedTypeExtension.MyBean.class);
 
         addExtension(new AddAdditionalAnnotatedTypeExtension());
 
         startContainer(beanClasses, beanXmls);
 
-        Bean<?> bean = getBeanManager().getBeans(MyBean.class, new AnnotationLiteral<Default>()
+        Bean<?> bean = getBeanManager().getBeans(AddAdditionalAnnotatedTypeExtension.MyBean.class,
new AnnotationLiteral<Default>()
         {
         }).iterator().next();
 

Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/portable/addannotated/extension/AddAdditionalAnnotatedTypeExtension.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/portable/addannotated/extension/AddAdditionalAnnotatedTypeExtension.java?rev=1797607&r1=1797606&r2=1797607&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/portable/addannotated/extension/AddAdditionalAnnotatedTypeExtension.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/portable/addannotated/extension/AddAdditionalAnnotatedTypeExtension.java
Sun Jun  4 19:50:07 2017
@@ -23,14 +23,43 @@ import javax.enterprise.inject.spi.BeanM
 import javax.enterprise.inject.spi.BeforeBeanDiscovery;
 import javax.enterprise.inject.spi.Extension;
 
-import org.apache.webbeans.test.portable.events.extensions.AddBeanExtension.MyBean;
+import org.apache.webbeans.annotation.ApplicationScopeLiteral;
+import org.apache.webbeans.annotation.RequestedScopeLiteral;
+
 
 public class AddAdditionalAnnotatedTypeExtension implements Extension
 {
+    public static class MyBean
+    {
+
+    }
+
+    public static class MyConfigBean1
+    {
+        public String getId()
+        {
+            return "1";
+        }
+    }
+
+    public static class MyConfigBean2
+    {
+        public String getId()
+        {
+            return "2";
+        }
+    }
+
 
     public void beforeBeanDiscovery(@Observes BeforeBeanDiscovery bbd, BeanManager bm)
     {
         bbd.addAnnotatedType(bm.createAnnotatedType(MyBean.class));
+
+        bbd.addAnnotatedType(MyConfigBean1.class, "hi1")
+            .add(RequestedScopeLiteral.INSTANCE);
+
+        bbd.addAnnotatedType(MyConfigBean2.class, "hi1")
+            .add(ApplicationScopeLiteral.INSTANCE);
     }
 
 }

Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/portable/events/extensions/AddBeanExtension.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/portable/events/extensions/AddBeanExtension.java?rev=1797607&r1=1797606&r2=1797607&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/portable/events/extensions/AddBeanExtension.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/portable/events/extensions/AddBeanExtension.java
Sun Jun  4 19:50:07 2017
@@ -38,7 +38,7 @@ public class AddBeanExtension implements
     {
         
     }
-    
+
     public static class MyBeanExtension implements Extension
     {
         public static Bean<MyBean> myBean;



Mime
View raw message