openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From strub...@apache.org
Subject svn commit: r1078546 - in /openwebbeans/trunk: webbeans-impl/src/main/java/org/apache/webbeans/config/ webbeans-impl/src/main/java/org/apache/webbeans/corespi/scanner/ webbeans-impl/src/main/java/org/apache/webbeans/util/ webbeans-osgi/src/main/java/or...
Date Sun, 06 Mar 2011 18:49:29 GMT
Author: struberg
Date: Sun Mar  6 18:49:28 2011
New Revision: 1078546

URL: http://svn.apache.org/viewvc?rev=1078546&view=rev
Log:
OWB-538 extend ScannerService to collect all annotations of a class

This information gets used for determining if a bean can be lazily initialised

Modified:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/DefinitionUtil.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/corespi/scanner/AbstractMetaDataDiscovery.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/ClassUtil.java
    openwebbeans/trunk/webbeans-osgi/src/main/java/org/apache/webbeans/osgi/scanner/OsgiMetaDataScannerService.java
    openwebbeans/trunk/webbeans-spi/src/main/java/org/apache/webbeans/spi/ScannerService.java

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/DefinitionUtil.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/DefinitionUtil.java?rev=1078546&r1=1078545&r2=1078546&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/DefinitionUtil.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/DefinitionUtil.java
Sun Mar  6 18:49:28 2011
@@ -32,13 +32,9 @@ import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
 
-import javax.annotation.PostConstruct;
-import javax.annotation.PreDestroy;
 import javax.enterprise.context.Dependent;
 import javax.enterprise.context.NormalScope;
 import javax.enterprise.event.Observes;
-import javax.enterprise.inject.Alternative;
-import javax.enterprise.inject.Stereotype;
 import javax.enterprise.inject.Typed;
 import javax.enterprise.inject.Disposes;
 import javax.enterprise.inject.Produces;
@@ -366,11 +362,9 @@ public final class DefinitionUtil
                 {
                     throw new WebBeansConfigurationException(exceptionMessage);
                 }
-                else
-                {
-                    found = true;
-                    component.setImplScopeType(annotation);
-                }
+
+                found = true;
+                component.setImplScopeType(annotation);
             }
             else
             {
@@ -380,11 +374,9 @@ public final class DefinitionUtil
                     {
                         throw new WebBeansConfigurationException(exceptionMessage);
                     }
-                    else
-                    {
-                        found = true;
-                        component.setImplScopeType(annotation);
-                    }                    
+
+                    found = true;
+                    component.setImplScopeType(annotation);
                 }
             }
         }
@@ -467,7 +459,7 @@ public final class DefinitionUtil
             {
                 component.setImplScopeType(new DependentScopeLiteral());
 
-                if (allowLazyInit && component instanceof ManagedBean &&
isPurePojoBean(component.getBeanClass()))
+                if (allowLazyInit && component instanceof ManagedBean &&
isPurePojoBean(component.getWebBeansContext(), component.getBeanClass()))
                 {
                     // take the bean as Dependent but we could lazily initialize it
                     // because the bean doesn't contains any CDI feature
@@ -518,7 +510,7 @@ public final class DefinitionUtil
                 {
                     component.setImplScopeType(new DependentScopeLiteral());
 
-                    if (allowLazyInit && component instanceof ManagedBean &&
isPurePojoBean(component.getBeanClass()))
+                    if (allowLazyInit && component instanceof ManagedBean &&
isPurePojoBean(component.getWebBeansContext(), component.getBeanClass()))
                     {
                         // take the bean as Dependent but we could lazily initialize it
                         // because the bean doesn't contains any CDI feature
@@ -539,16 +531,30 @@ public final class DefinitionUtil
      * @param cls the Class to check
      * @return <code>false</code> if the bean uses CDI annotations which define
other beans somewhere
      */
-    private static boolean isPurePojoBean(Class<?> cls)
+    private static boolean isPurePojoBean(WebBeansContext webBeansContext, Class<?>
cls)
     {
         Class<?> superClass = cls.getSuperclass();
 
-        if ( superClass == Object.class || !isPurePojoBean(superClass))
+        if ( superClass == Object.class || !isPurePojoBean(webBeansContext, superClass))
         {
             return false;
         }
 
+        Set<String> annotations = webBeansContext.getScannerService().getAllAnnotations(cls.getSimpleName());
+        if (annotations != null)
+        {
+            for (String ann : annotations)
+            {
+                if (ann.startsWith("javax.inject") || ann.startsWith("javax.enterprise")
|| ann.startsWith("javax.interceptors"))
+                {
+                    return false;
+                }
+            }
+
+        }
 
+        return true;
+/*X
         Annotation[] anns = cls.getAnnotations();
         for (Annotation ann : anns)
         {
@@ -617,6 +623,7 @@ public final class DefinitionUtil
         }
 
         return true;
+*/
     }
 
 

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/corespi/scanner/AbstractMetaDataDiscovery.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/corespi/scanner/AbstractMetaDataDiscovery.java?rev=1078546&r1=1078545&r2=1078546&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/corespi/scanner/AbstractMetaDataDiscovery.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/corespi/scanner/AbstractMetaDataDiscovery.java
Sun Mar  6 18:49:28 2011
@@ -55,6 +55,11 @@ public abstract class AbstractMetaDataDi
     protected boolean isBDAScannerEnabled = false;
     protected BDABeansXmlScanner bdaBeansXmlScanner;
 
+    /**
+     * determines if cross referencing already got performed or not
+     */
+    private boolean isCrossReferenzed = false;
+
     protected AbstractMetaDataDiscovery()
     {
         initAnnotationDB();
@@ -66,10 +71,9 @@ public abstract class AbstractMetaDataDi
         {
             annotationDB = new AnnotationDB();
             annotationDB.setScanClassAnnotations(true);
-            annotationDB.setScanFieldAnnotations(false);
-            annotationDB.setScanMethodAnnotations(false);
-            annotationDB.setScanParameterAnnotations(false);
-            annotationDB.crossReferenceMetaAnnotations();
+            annotationDB.setScanFieldAnnotations(true);
+            annotationDB.setScanMethodAnnotations(true);
+            annotationDB.setScanParameterAnnotations(true);
         }
         catch(Exception e)
         {
@@ -167,6 +171,13 @@ public abstract class AbstractMetaDataDi
         return annotationDB;
     }
 
+    @Override
+    public Set<String> getAllAnnotations(String className)
+    {
+        return annotationDB.getAnnotationIndex().get(className);
+    }
+
+
     /**
      * add the given beans.xml path to the locations list 
      * @param beansXmlLocation location path
@@ -186,6 +197,8 @@ public abstract class AbstractMetaDataDi
     @Override
     public Set<Class<?>> getBeanClasses()
     {
+        crossReferenceBeans();
+
         Set<Class<?>> classSet = new HashSet<Class<?>>();
         Map<String,Set<String>> index = this.annotationDB.getClassIndex();
         
@@ -202,12 +215,31 @@ public abstract class AbstractMetaDataDi
         }    
         
         return classSet;
-    }    
+    }
+
+    /**
+     * Ensure that all Annotation CrossReferences got resolved.
+     */
+    protected synchronized void crossReferenceBeans()
+    {
+        if (!isCrossReferenzed)
+        {
+            try
+            {
+                annotationDB.crossReferenceMetaAnnotations();
+            }
+            catch (AnnotationDB.CrossReferenceException e)
+            {
+                throw new RuntimeException(e);
+            }
+            isCrossReferenzed = true;
+        }
+    }
 
 
     /* (non-Javadoc)
-     * @see org.apache.webbeans.corespi.ScannerService#getBeanXmls()
-     */
+    * @see org.apache.webbeans.corespi.ScannerService#getBeanXmls()
+    */
     @Override
     public Set<String> getBeanXmls()
     {

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/ClassUtil.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/ClassUtil.java?rev=1078546&r1=1078545&r2=1078546&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/ClassUtil.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/ClassUtil.java
Sun Mar  6 18:49:28 2011
@@ -1301,31 +1301,6 @@ public final class ClassUtil
         return true;
     }
 
-    public static boolean classHasMoreThanOneFieldWithName(Class<?> clazz, String fieldName)
-    {
-        Asserts.nullCheckForClass(clazz);
-        Asserts.assertNotNull(fieldName, "fieldName parameter can not be null");
-
-        Field[] fields = SecurityUtil.doPrivilegedGetDeclaredFields(clazz);
-        boolean ok = false;
-        for (Field field : fields)
-        {
-            if (field.getName().equals(fieldName))
-            {
-                if (ok)
-                {
-                    return true;
-                }
-                else
-                {
-                    ok = true;
-                }
-            }
-        }
-
-        return false;
-    }
-
     public static Field getFieldWithName(Class<?> clazz, String fieldName)
     {
         Asserts.nullCheckForClass(clazz);

Modified: openwebbeans/trunk/webbeans-osgi/src/main/java/org/apache/webbeans/osgi/scanner/OsgiMetaDataScannerService.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-osgi/src/main/java/org/apache/webbeans/osgi/scanner/OsgiMetaDataScannerService.java?rev=1078546&r1=1078545&r2=1078546&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-osgi/src/main/java/org/apache/webbeans/osgi/scanner/OsgiMetaDataScannerService.java
(original)
+++ openwebbeans/trunk/webbeans-osgi/src/main/java/org/apache/webbeans/osgi/scanner/OsgiMetaDataScannerService.java
Sun Mar  6 18:49:28 2011
@@ -223,7 +223,14 @@ public class OsgiMetaDataScannerService 
     {
         return beanClasses;
     }
-    
+
+    @Override
+    public Set<String> getAllAnnotations(String className)
+    {
+        //X TODO this needs go get implemented
+        return null;
+    }
+
     @Override
     public BDABeansXmlScanner getBDABeansXmlScanner()
     {

Modified: openwebbeans/trunk/webbeans-spi/src/main/java/org/apache/webbeans/spi/ScannerService.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-spi/src/main/java/org/apache/webbeans/spi/ScannerService.java?rev=1078546&r1=1078545&r2=1078546&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-spi/src/main/java/org/apache/webbeans/spi/ScannerService.java
(original)
+++ openwebbeans/trunk/webbeans-spi/src/main/java/org/apache/webbeans/spi/ScannerService.java
Sun Mar  6 18:49:28 2011
@@ -69,6 +69,13 @@ public interface ScannerService
      * @return bean classes
      */
     public Set<Class<?>> getBeanClasses();
+
+
+    /**
+     * @param className
+     * @return all Annotations used in the whole class
+     */
+    public Set<String> getAllAnnotations(String className);
     
     /**
      * Indicates if BDABeansXmlScanner is available. This method 



Mime
View raw message