openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From strub...@apache.org
Subject svn commit: r1434703 - in /openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans: component/creation/ config/ container/ conversation/ decorator/ event/
Date Thu, 17 Jan 2013 14:57:21 GMT
Author: struberg
Date: Thu Jan 17 14:57:20 2013
New Revision: 1434703

URL: http://svn.apache.org/viewvc?rev=1434703&view=rev
Log:
OWB-344 generalize Decorator comparison

and remove lots of hardcoded WebBeansDecorator impl specific stuff

Modified:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/AbstractBeanBuilder.java
    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/InjectionResolver.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/conversation/ConversationManager.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/decorator/DecoratorComparator.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/decorator/DecoratorsManager.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/decorator/WebBeansDecorator.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/ObserverMethodImpl.java

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/AbstractBeanBuilder.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/AbstractBeanBuilder.java?rev=1434703&r1=1434702&r2=1434703&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/AbstractBeanBuilder.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/AbstractBeanBuilder.java
Thu Jan 17 14:57:20 2013
@@ -321,14 +321,14 @@ public abstract class AbstractBeanBuilde
         // No-binding annotation
         if (qualifiers.size() == 0 )
         {
-            qualifiers.add(new DefaultLiteral());
+            qualifiers.add(DefaultLiteral.INSTANCE);
         }
         else if(qualifiers.size() == 1)
         {
             Annotation annot = qualifiers.iterator().next();
             if(annot.annotationType().equals(Named.class))
             {
-                qualifiers.add(new DefaultLiteral());
+                qualifiers.add(DefaultLiteral.INSTANCE);
             }
         }
         

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=1434703&r1=1434702&r2=1434703&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
Thu Jan 17 14:57:20 2013
@@ -65,7 +65,6 @@ import org.apache.webbeans.container.Bea
 import org.apache.webbeans.container.InjectableBeanManager;
 import org.apache.webbeans.container.InjectionResolver;
 import org.apache.webbeans.corespi.se.DefaultJndiService;
-import org.apache.webbeans.decorator.WebBeansDecorator;
 import org.apache.webbeans.decorator.WebBeansDecoratorConfig;
 import org.apache.webbeans.deployment.StereoTypeModel;
 import org.apache.webbeans.event.ObserverMethodImpl;
@@ -342,12 +341,9 @@ public class BeansDeployer
         
         //Adding decorators to validate
         Set<Decorator<?>> decorators = webBeansContext.getDecoratorsManager().getDecorators();
-        for(Decorator decorator : decorators)
-        {
-            WebBeansDecorator wbDec = (WebBeansDecorator)decorator;
-            beans.add(wbDec);
-        }
-        
+
+        beans.addAll(decorators);
+
         
         logger.fine("Validation of the decorator's injection points has started.");
         

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=1434703&r1=1434702&r2=1434703&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
Thu Jan 17 14:57:20 2013
@@ -74,7 +74,6 @@ import org.apache.webbeans.component.thi
 import org.apache.webbeans.config.WebBeansContext;
 import org.apache.webbeans.context.creational.CreationalContextImpl;
 import org.apache.webbeans.decorator.DecoratorComparator;
-import org.apache.webbeans.decorator.WebBeansDecorator;
 import org.apache.webbeans.event.NotificationManager;
 import org.apache.webbeans.exception.WebBeansConfigurationException;
 import org.apache.webbeans.exception.definition.DuplicateDefinitionException;
@@ -418,20 +417,11 @@ public class BeanManagerImpl implements 
     {
         webBeansContext.getAnnotationManager().checkDecoratorResolverParams(types, bindingTypes);
         Set<Decorator<?>> intsSet = webBeansContext.getDecoratorsManager().findDeployedWebBeansDecorator(types,
bindingTypes);
-        Iterator<Decorator<?>> itSet = intsSet.iterator();
-
-        List<Decorator<?>> decoratorList = new ArrayList<Decorator<?>>();
-        while (itSet.hasNext())
-        {
-            WebBeansDecorator decorator = (WebBeansDecorator) itSet.next();
-            decoratorList.add(decorator);
-
-        }
 
+        List<Decorator<?>> decoratorList = new ArrayList<Decorator<?>>(intsSet);
         Collections.sort(decoratorList, new DecoratorComparator(webBeansContext));
 
         return decoratorList;
-
     }
 
     /**

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/InjectionResolver.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/InjectionResolver.java?rev=1434703&r1=1434702&r2=1434703&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/InjectionResolver.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/InjectionResolver.java
Thu Jan 17 14:57:20 2013
@@ -74,7 +74,7 @@ public class InjectionResolver
      */
     private WebBeansContext webBeansContext;
     
-    private final static Annotation[] DEFAULT_LITERAL_ARRAY = new Annotation[]{new DefaultLiteral()};
+    private final static Annotation[] DEFAULT_LITERAL_ARRAY = new Annotation[]{DefaultLiteral.INSTANCE};
     private final static Annotation[] ANY_LITERAL_ARRAY = new Annotation[]{new AnyLiteral()};
 
     /**

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/conversation/ConversationManager.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/conversation/ConversationManager.java?rev=1434703&r1=1434702&r2=1434703&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/conversation/ConversationManager.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/conversation/ConversationManager.java
Thu Jan 17 14:57:20 2013
@@ -204,7 +204,7 @@ public class ConversationManager
     public Conversation getConversationBeanReference()
     {
         BeanManager beanManager = webBeansContext.getBeanManagerImpl();
-        Bean<Conversation> bean = (Bean<Conversation>)beanManager.getBeans(Conversation.class,
new DefaultLiteral()).iterator().next();
+        Bean<Conversation> bean = (Bean<Conversation>)beanManager.getBeans(Conversation.class,
DefaultLiteral.INSTANCE).iterator().next();
         Conversation conversation =(Conversation) beanManager.getReference(bean, Conversation.class,
beanManager.createCreationalContext(bean));
 
         return conversation;

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/decorator/DecoratorComparator.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/decorator/DecoratorComparator.java?rev=1434703&r1=1434702&r2=1434703&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/decorator/DecoratorComparator.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/decorator/DecoratorComparator.java
Thu Jan 17 14:57:20 2013
@@ -39,20 +39,16 @@ public class DecoratorComparator<T> impl
 
     public int compare(Decorator<T> o1, Decorator<T> o2)
     {
-        WebBeansDecorator<T> src = (WebBeansDecorator<T>) o1;
-        WebBeansDecorator<T> target = (WebBeansDecorator<T>) o2;
-
         if (o1.equals(o2))
         {
             return 0;
         }
         else
         {
-            Class<?> o1Clazz = src.getClazz();
-            Class<?> o2Clazz = target.getClazz();
+            Class<?> o1Clazz = o1.getBeanClass();
+            Class<?> o2Clazz = o2.getBeanClass();
 
             return webBeansContext.getDecoratorsManager().compare(o1Clazz, o2Clazz);
-
         }
     }
 

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/decorator/DecoratorsManager.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/decorator/DecoratorsManager.java?rev=1434703&r1=1434702&r2=1434703&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/decorator/DecoratorsManager.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/decorator/DecoratorsManager.java
Thu Jan 17 14:57:20 2013
@@ -21,20 +21,19 @@ package org.apache.webbeans.decorator;
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Type;
 import java.util.ArrayList;
-import java.util.Collections;
 import java.util.HashSet;
-import java.util.Iterator;
 import java.util.List;
 import java.util.Set;
 import java.util.concurrent.CopyOnWriteArrayList;
 import java.util.concurrent.CopyOnWriteArraySet;
 
-import javax.decorator.Decorator;
+import javax.enterprise.inject.spi.Decorator;
 
 import org.apache.webbeans.annotation.DefaultLiteral;
 import org.apache.webbeans.component.OwbBean;
 import org.apache.webbeans.config.WebBeansContext;
 import org.apache.webbeans.exception.WebBeansConfigurationException;
+import org.apache.webbeans.util.AnnotationUtil;
 import org.apache.webbeans.util.Asserts;
 
 public class DecoratorsManager
@@ -50,7 +49,7 @@ public class DecoratorsManager
     /**
      * Active and enabled decorators
      */
-    private Set<javax.enterprise.inject.spi.Decorator<?>> webBeansDecorators
= new CopyOnWriteArraySet<javax.enterprise.inject.spi.Decorator<?>>();
+    private Set<Decorator<?>> webBeansDecorators = new CopyOnWriteArraySet<Decorator<?>>();
 
 
 
@@ -108,7 +107,7 @@ public class DecoratorsManager
         for(Class<?> decoratorClazz : enabledDecorators)
         {
             //Validate decorator classes
-            if(!decoratorClazz.isAnnotationPresent(Decorator.class) && !containsCustomDecoratorClass(decoratorClazz))
+            if(!decoratorClazz.isAnnotationPresent(javax.decorator.Decorator.class) &&
!containsCustomDecoratorClass(decoratorClazz))
             {
                 throw new WebBeansConfigurationException("Given class : " + decoratorClazz
+ " is not a decorator class");
             }   
@@ -127,12 +126,12 @@ public class DecoratorsManager
         return additionalDecoratorClasses.contains(clazz);
     }
 
-    public Set<javax.enterprise.inject.spi.Decorator<?>> getDecorators()
+    public Set<Decorator<?>> getDecorators()
     {
         return webBeansDecorators;
     }
 
-    public void addDecorator(javax.enterprise.inject.spi.Decorator decorator)
+    public void addDecorator(Decorator decorator)
     {
         webBeansDecorators.add(decorator);
         if (decorator instanceof OwbBean)
@@ -141,17 +140,14 @@ public class DecoratorsManager
 
             if(owbBean.isPassivationCapable())
             {
-                webBeansContext.getBeanManagerImpl().addPassivationInfo((OwbBean)decorator);
+                webBeansContext.getBeanManagerImpl().addPassivationInfo(decorator);
             }
         }
     }
 
-    public  Set<javax.enterprise.inject.spi.Decorator<?>> findDeployedWebBeansDecorator(Set<Type>
apiTypes, Annotation... anns)
+    public  Set<Decorator<?>> findDeployedWebBeansDecorator(Set<Type> apiTypes,
Annotation... anns)
     {
-        Set<javax.enterprise.inject.spi.Decorator<?>> set = new HashSet<javax.enterprise.inject.spi.Decorator<?>>();
-
-        Iterator<javax.enterprise.inject.spi.Decorator<?>> it = Collections.unmodifiableSet(getDecorators()).iterator();
-        WebBeansDecorator<?> decorator = null;
+        Set<Decorator<?>> set = new HashSet<Decorator<?>>();
 
         List<Class<? extends Annotation>> bindingTypes = new ArrayList<Class<?
extends Annotation>>();
         Set<Annotation> listAnnot = new HashSet<Annotation>();
@@ -163,14 +159,12 @@ public class DecoratorsManager
 
         if (listAnnot.isEmpty())
         {
-            listAnnot.add(new DefaultLiteral());
+            listAnnot.add(DefaultLiteral.INSTANCE);
         }
 
-        while (it.hasNext())
+        for (Decorator<?> decorator : getDecorators())
         {
-            decorator = (WebBeansDecorator<?>) it.next();
-
-            if (decorator.isDecoratorMatch(apiTypes, listAnnot))
+            if (isDecoratorMatch(decorator, apiTypes, listAnnot))
             {
                 set.add(decorator);
             }
@@ -180,6 +174,67 @@ public class DecoratorsManager
 
     }
 
+    private boolean isDecoratorMatch(Decorator<?> decorator, Set<Type> apiTypes,
Set<Annotation> annotations)
+    {
+        if (!apiTypesMatchDelegateType(decorator, apiTypes))
+        {
+            return false;
+        }
+
+        for (Annotation bindingType : decorator.getDelegateQualifiers())
+        {
+            if (!bindingMatchesAnnotations(bindingType, annotations))
+            {
+                return false;
+            }
+        }
+
+        return true;
+    }
+
+    private boolean bindingMatchesAnnotations(Annotation bindingType, Set<Annotation>
annotations)
+    {
+
+        for (Annotation annot : annotations)
+        {
+            if (AnnotationUtil.isQualifierEqual(annot, bindingType))
+            {
+                return true;
+            }
+        }
+
+        return false;
+    }
+
+    /**
+     * Helper method to check if any of a list of Types are assignable to the
+     * delegate type.
+     *
+     * @param apiTypes Set of apiTypes to check against the delegate type
+     * @return true if one of the types is assignable to the delegate type
+     */
+    private boolean apiTypesMatchDelegateType(Decorator<?> decorator, Set<Type>
apiTypes)
+    {
+        boolean ok = false;
+        for (Type apiType : apiTypes)
+        {
+            if (DecoratorResolverRules.compareType(decorator.getDelegateType(), apiType))
+            {
+                ok = true;
+                break;
+            }
+        }
+
+        if(ok)
+        {
+            return true;
+        }
+
+        return false;
+    }
+
+
+
 
     public void clear()
     {

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/decorator/WebBeansDecorator.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/decorator/WebBeansDecorator.java?rev=1434703&r1=1434702&r2=1434703&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/decorator/WebBeansDecorator.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/decorator/WebBeansDecorator.java
Thu Jan 17 14:57:20 2013
@@ -26,7 +26,6 @@ import org.apache.webbeans.config.WebBea
 import org.apache.webbeans.exception.WebBeansConfigurationException;
 import org.apache.webbeans.exception.WebBeansException;
 import org.apache.webbeans.logger.WebBeansLoggerFacade;
-import org.apache.webbeans.util.AnnotationUtil;
 import org.apache.webbeans.util.ClassUtil;
 
 import javax.decorator.Delegate;
@@ -58,8 +57,10 @@ import java.util.logging.Level;
  * @version $Rev$ $Date$
  *
  * @param <T> decorator type info
+ *
+ * @deprecated replaced by DecoratorBean
  */
-public class WebBeansDecorator<T> extends InjectionTargetBean<T> implements OwbDecorator<T>
+public class WebBeansDecorator<T> extends InjectionTargetBean<T> implements Decorator<T>
 {
     /** Decorator class */
     private Class<?> clazz;
@@ -295,66 +296,6 @@ public class WebBeansDecorator<T> extend
         }
     }
     
-    private boolean bindingMatchesAnnotations(Annotation bindingType, Set<Annotation>
annotations)
-    {
-
-        for (Annotation annot : annotations)
-        {
-            if (AnnotationUtil.isQualifierEqual(annot, bindingType))
-            {
-                return true;
-            }
-        }
-
-        return false;
-    }
-
-    /**
-     * Helper method to check if any of a list of Types are assignable to the
-     * delegate type.
-     * 
-     * @param apiTypes Set of apiTypes to check against the delegate type
-     * @return true if one of the types is assignable to the delegate type
-     */
-    private boolean apiTypesMatchDelegateType(Set<Type> apiTypes)
-    {
-        boolean ok = false;
-        for (Type apiType : apiTypes)
-        {
-            if (DecoratorResolverRules.compareType(getDelegateType(), apiType))
-            {
-                ok = true;
-                break;
-            }
-        }
-        
-        if(ok) 
-        {
-            return true;
-        }
-
-        return false;
-    }
-
-    public boolean isDecoratorMatch(Set<Type> apiTypes, Set<Annotation> annotations)
-    {
-
-        if (!apiTypesMatchDelegateType(apiTypes))
-        {
-            return false;
-        }
-
-        for (Annotation bindingType : getDelegateQualifiers())
-        {
-            if (!bindingMatchesAnnotations(bindingType, annotations))
-            {
-                return false;
-            }
-        }
-
-        return true;
-    }
-
     public Set<Annotation> getDelegateQualifiers()
     {
         if(customDecorator != null)

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/ObserverMethodImpl.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/ObserverMethodImpl.java?rev=1434703&r1=1434702&r2=1434703&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/ObserverMethodImpl.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/ObserverMethodImpl.java
Thu Jan 17 14:57:20 2013
@@ -353,7 +353,7 @@ public class ObserverMethodImpl<T> imple
                 if (annot.length == 0)
                 {
                     annot = new Annotation[1];
-                    annot[0] = new DefaultLiteral();
+                    annot[0] = DefaultLiteral.INSTANCE;
                 }
                 else
                 {



Mime
View raw message