openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject svn commit: r1467359 - in /openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans: config/BeansDeployer.java container/BeanManagerImpl.java portable/AnnotatedElementFactory.java portable/events/discovery/AfterBeanDiscoveryImpl.java
Date Fri, 12 Apr 2013 17:17:49 GMT
Author: arne
Date: Fri Apr 12 17:17:48 2013
New Revision: 1467359

URL: http://svn.apache.org/r1467359
Log:
OWB-826: first shot

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/portable/AnnotatedElementFactory.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=1467359&r1=1467358&r2=1467359&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 Apr 12 17:17:48 2013
@@ -85,6 +85,7 @@ import java.lang.reflect.Constructor;
 import java.net.URL;
 import java.security.PrivilegedActionException;
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
@@ -524,7 +525,7 @@ public class BeansDeployer
         if (classIndex != null)
         {
             AnnotatedElementFactory annotatedElementFactory = webBeansContext.getAnnotatedElementFactory();
-            List<AnnotatedType<?>> additionalAnnotatedTypes = webBeansContext.getBeanManagerImpl()
+            Collection<AnnotatedType<?>> additionalAnnotatedTypes = webBeansContext.getBeanManagerImpl()
                                                                              .getAdditionalAnnotatedTypes();
 
             for(Class<?> implClass : classIndex)
@@ -568,7 +569,7 @@ public class BeansDeployer
     {
         BeanManagerImpl beanManager = webBeansContext.getBeanManagerImpl();
 
-        List<AnnotatedType<?>> annotatedTypes = beanManager.getAdditionalAnnotatedTypes();
+        Collection<AnnotatedType<?>> annotatedTypes = beanManager.getAdditionalAnnotatedTypes();
         
         for(AnnotatedType<?> type : annotatedTypes)
         {

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=1467359&r1=1467358&r2=1467359&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 Apr 12 17:17:48 2013
@@ -22,6 +22,7 @@ import java.io.InputStream;
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Type;
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -160,7 +161,7 @@ public class BeanManagerImpl implements 
      */
     private List<ExternalScope> additionalScopes =  new ArrayList<ExternalScope>();
 
-    private List<AnnotatedType<?>> additionalAnnotatedTypes = new ArrayList<AnnotatedType<?>>();
+    private Map<String, AnnotatedType<?>> additionalAnnotatedTypes = new HashMap<String,
AnnotatedType<?>>();
 
 
     private ErrorStack errorStack = new ErrorStack();
@@ -210,6 +211,11 @@ public class BeanManagerImpl implements 
         annotatedElementFactory = webBeansContext.getAnnotatedElementFactory();
     }
 
+    public WebBeansContext getWebBeansContext()
+    {
+        return webBeansContext;
+    }
+
     public <T> void putProducerForJavaEeComponent(Class<T> javaEeComponentClass,
Producer<T> wrapper)
     {
         Asserts.assertNotNull(javaEeComponentClass);
@@ -985,7 +991,13 @@ public class BeanManagerImpl implements 
     public void addAdditionalAnnotatedType(AnnotatedType<?> annotatedType)
     {
         webBeansContext.getAnnotatedElementFactory().setAnnotatedType(annotatedType);
-        additionalAnnotatedTypes.add(annotatedType);
+        additionalAnnotatedTypes.put(null, annotatedType);
+    }
+
+    public void addAdditionalAnnotatedType(AnnotatedType<?> annotatedType, String id)
+    {
+        webBeansContext.getAnnotatedElementFactory().setAnnotatedType(annotatedType);
+        additionalAnnotatedTypes.put(id, annotatedType);
     }
 
     public List<Class<? extends Annotation>> getAdditionalQualifiers()
@@ -1007,12 +1019,23 @@ public class BeanManagerImpl implements 
         return additionalScopes;
     }
 
-    public List<AnnotatedType<?>> getAdditionalAnnotatedTypes()
+    public Collection<AnnotatedType<?>> getAdditionalAnnotatedTypes()
     {
-        return additionalAnnotatedTypes;
+        return additionalAnnotatedTypes.values();
     }
 
-
+    public <T> AnnotatedType<T> getAdditionalAnnotatedType(Class<T> type,
String id)
+    {
+        AnnotatedType<?> annotatedType = additionalAnnotatedTypes.get(id);
+        if (annotatedType.getJavaClass().equals(type))
+        {
+            return (AnnotatedType<T>) annotatedType;
+        }
+        else
+        {
+            return null;
+        }
+    }
 
     public void clear()
     {

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/AnnotatedElementFactory.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/AnnotatedElementFactory.java?rev=1467359&r1=1467358&r2=1467359&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/AnnotatedElementFactory.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/AnnotatedElementFactory.java
Fri Apr 12 17:17:48 2013
@@ -43,13 +43,15 @@ import org.apache.webbeans.util.Asserts;
  */
 public final class AnnotatedElementFactory
 {
+    
+    private static final String OWB_DEFAULT_KEY = "OWB_DEFAULT_KEY";
 
     // Logger instance
     private final static Logger logger = WebBeansLoggerFacade.getLogger(AnnotatedElementFactory.class);
 
     //Cache of the AnnotatedType
-    private ConcurrentMap<Class<?>, AnnotatedType<?>> annotatedTypeCache
=
-        new ConcurrentHashMap<Class<?>, AnnotatedType<?>>();
+    private ConcurrentMap<Class<?>, ConcurrentMap<String, AnnotatedType<?>>>
annotatedTypeCache =
+        new ConcurrentHashMap<Class<?>, ConcurrentMap<String, AnnotatedType<?>>>();
     
     //Cache of AnnotatedConstructor
     private ConcurrentMap<Constructor<?>, AnnotatedConstructor<?>> annotatedConstructorCache
=
@@ -81,10 +83,21 @@ public final class AnnotatedElementFacto
      */
     public <X> AnnotatedType<X> getAnnotatedType(Class<X> annotatedClass)
     {
-        return (AnnotatedType<X>) annotatedTypeCache.get(annotatedClass);
+        return getAnnotatedTypeCache(annotatedClass).get(OWB_DEFAULT_KEY);
     }
 
     /**
+     * Get all already registered AnnotatedTypes of the specified type. This will NOT create
a new one!
+     * @param annotatedClass
+     * @param <X>
+     * @return AnnotatedType
+     */
+    public <X> Iterable<AnnotatedType<X>> getAnnotatedTypes(Class<X>
annotatedClass)
+    {
+        return getAnnotatedTypeCache(annotatedClass).values();
+    }
+    
+    /**
      * This method will get used to manually add AnnoatedTypes to our storage.
      * Those AnnotatedTypes are coming from Extensions and get registered e.g. via
      * {@link javax.enterprise.inject.spi.BeforeBeanDiscovery#addAnnotatedType(AnnotatedType)}
@@ -96,9 +109,14 @@ public final class AnnotatedElementFacto
      */
     public <X> AnnotatedType<X> setAnnotatedType(AnnotatedType<X> annotatedType)
     {
-        return (AnnotatedType<X>) annotatedTypeCache.put(annotatedType.getJavaClass(),
annotatedType);
+        return setAnnotatedType(annotatedType, OWB_DEFAULT_KEY);
     }
 
+    public <X> AnnotatedType<X> setAnnotatedType(AnnotatedType<X> annotatedType,
String id)
+    {
+        ConcurrentMap<String, AnnotatedType<X>> annotatedTypes = getAnnotatedTypeCache(annotatedType.getJavaClass());
+        return (AnnotatedType<X>) annotatedTypes.put(id, annotatedType);
+    }
 
     /**
      * Creates and configures new annotated type.
@@ -107,11 +125,11 @@ public final class AnnotatedElementFacto
      * @param annotatedClass annotated class
      * @return new annotated type
      */
-    @SuppressWarnings("unchecked")
     public <X> AnnotatedType<X> newAnnotatedType(Class<X> annotatedClass)
     {
         Asserts.assertNotNull(annotatedClass, "annotatedClass is null");
-        AnnotatedType<X> annotatedType = (AnnotatedType<X>)annotatedTypeCache.get(annotatedClass);
+        ConcurrentMap<String, AnnotatedType<X>> annotatedTypes = getAnnotatedTypeCache(annotatedClass);
+        AnnotatedType<X> annotatedType = (AnnotatedType<X>)annotatedTypes.get(OWB_DEFAULT_KEY);
         if(annotatedType == null)
         {
             try
@@ -123,7 +141,7 @@ public final class AnnotatedElementFacto
                 }
                 annotatedType = new AnnotatedTypeImpl<X>(webBeansContext, annotatedClass,
(AnnotatedTypeImpl<? super X>) supertype);
 
-                AnnotatedType<X> oldType = (AnnotatedType<X>)annotatedTypeCache.putIfAbsent(annotatedClass,
annotatedType);
+                AnnotatedType<X> oldType = (AnnotatedType<X>)annotatedTypes.putIfAbsent(OWB_DEFAULT_KEY,
annotatedType);
                 if(oldType != null)
                 {
                     annotatedType = oldType;
@@ -264,4 +282,19 @@ public final class AnnotatedElementFacto
         annotatedFieldCache.clear();
         annotatedMethodCache.clear();
     }
+    
+    private <T> ConcurrentMap<String, AnnotatedType<T>> getAnnotatedTypeCache(Class<T>
type)
+    {
+        ConcurrentMap<String, AnnotatedType<?>> annotatedTypes = annotatedTypeCache.get(type);
+        if (annotatedTypes == null)
+        {
+            annotatedTypes = new ConcurrentHashMap<String, AnnotatedType<?>>();
+            ConcurrentMap<String, AnnotatedType<?>> oldAnnotatedTypes = annotatedTypeCache.putIfAbsent(type,
annotatedTypes);
+            if (oldAnnotatedTypes != null)
+            {
+                annotatedTypes = oldAnnotatedTypes;
+            }
+        }
+        return (ConcurrentMap<String, AnnotatedType<T>>)(ConcurrentMap<?,
?>)annotatedTypes;
+    }
 }

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=1467359&r1=1467358&r2=1467359&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
Fri Apr 12 17:17:48 2013
@@ -64,7 +64,6 @@ public class AfterBeanDiscoveryImpl impl
     /**
      * {@inheritDoc}
      */
-    @SuppressWarnings("unchecked")
     public void addBean(Bean<?> bean)
     {
         AnnotatedType<?> annotatedType = webBeansContext.getAnnotatedElementFactory().newAnnotatedType(bean.getBeanClass());
@@ -76,9 +75,7 @@ public class AfterBeanDiscoveryImpl impl
         if(bean instanceof Interceptor)
         {
             //Required for custom interceptors
-            ManagedBean managedBean =
-                webBeansContext.getWebBeansUtil().defineManagedBeanWithoutFireEvents(
-                    (AnnotatedType<?>) annotatedType);
+            webBeansContext.getWebBeansUtil().defineManagedBeanWithoutFireEvents((AnnotatedType<?>)
annotatedType);
             
             Interceptor<?> interceptor =  (Interceptor<?>)bean;
             if(interceptor.getScope() != Dependent.class)
@@ -113,7 +110,7 @@ public class AfterBeanDiscoveryImpl impl
         else if(bean instanceof Decorator)
         {
             //Required for custom decorators
-            ManagedBean managedBean =
+            ManagedBean<?> managedBean =
                 webBeansContext.getWebBeansUtil().defineManagedBeanWithoutFireEvents(
                     (AnnotatedType<?>) annotatedType);
             if(managedBean.getScope() != Dependent.class)
@@ -141,7 +138,7 @@ public class AfterBeanDiscoveryImpl impl
             }
 
 
-            webBeansContext.getDecoratorsManager().addDecorator((Decorator) bean);
+            webBeansContext.getDecoratorsManager().addDecorator((Decorator<?>) bean);
             webBeansContext.getDecoratorsManager().addCustomDecoratorClass(bean.getBeanClass());
         }
         else
@@ -177,4 +174,20 @@ public class AfterBeanDiscoveryImpl impl
         beanManager.getNotificationManager().addObserver(observerMethod, observerMethod.getObservedType());
     }
 
+    /**
+     * {@inheritDoc}
+     */
+    public <T> AnnotatedType<T> getAnnotatedType(Class<T> type, String
id)
+    {
+        return (AnnotatedType<T>) beanManager.getAdditionalAnnotatedType(type, id);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public <T> Iterable<AnnotatedType<T>> getAnnotatedTypes(Class<T>
type)
+    {
+        return beanManager.getWebBeansContext().getAnnotatedElementFactory().getAnnotatedTypes(type);
+    }
+
 }



Mime
View raw message