[webbeans-commits] Webbeans SVN: r801 - in ri/trunk/webbeans-ri/src: main/java/org/jboss/webbeans/bootstrap and 2 other directories.

webbeans-commits at lists.jboss.org webbeans-commits at lists.jboss.org
Wed Jan 7 02:58:22 EST 2009


Author: nickarls
Date: 2009-01-07 02:58:22 -0500 (Wed, 07 Jan 2009)
New Revision: 801

Added:
   ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/newbean/valid/AnnotatedConstructorParameter.java
   ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/newbean/valid/AnnotatedField.java
   ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/newbean/valid/AnnotatedInitializerParameter.java
   ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/newbean/valid/AnnotatedProducerParameter.java
Removed:
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/NewBean.java
   ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/newbean/valid/Sample.java
Modified:
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bootstrap/WebBeansBootstrap.java
   ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/newbean/NewBeanTest.java
Log:
Bootstrapping @New

Deleted: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/NewBean.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/NewBean.java	2009-01-06 23:52:50 UTC (rev 800)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/NewBean.java	2009-01-07 07:58:22 UTC (rev 801)
@@ -1,62 +0,0 @@
-package org.jboss.webbeans.bean;
-
-import java.lang.annotation.Annotation;
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.Set;
-
-import javax.webbeans.Dependent;
-import javax.webbeans.Standard;
-import javax.webbeans.manager.Bean;
-import javax.webbeans.manager.Manager;
-
-import org.jboss.webbeans.binding.NewBinding;
-import org.jboss.webbeans.introspector.AnnotatedItem;
-
-public class NewBean<T> extends ForwardingBean<T>
-{
-   private AbstractClassBean<T> wrappedBean;
-   
-   public NewBean(AbstractClassBean<T> wrappedBean, Manager manager)
-   {
-      super(manager);
-      this.wrappedBean = wrappedBean;
-   }
-
-   @Override
-   protected Bean<T> delegate()
-   {
-      return wrappedBean;
-   }
-
-   @Override
-   public Class<? extends Annotation> getScopeType()
-   {
-      return Dependent.class;
-   }
-
-   @Override
-   public Class<? extends Annotation> getDeploymentType()
-   {
-      return Standard.class;
-   }
-
-   @Override
-   public String getName()
-   {
-      return null;
-   }
-
-   public Set<AnnotatedItem<?, ?>> getInjectionPoints()
-   {
-      return wrappedBean.getInjectionPoints();
-   }
-
-   @Override
-   public Set<Annotation> getBindingTypes()
-   {
-      return new HashSet<Annotation>(Arrays.asList(new NewBinding()));
-   }
-   
-   
-}

Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bootstrap/WebBeansBootstrap.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bootstrap/WebBeansBootstrap.java	2009-01-06 23:52:50 UTC (rev 800)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bootstrap/WebBeansBootstrap.java	2009-01-07 07:58:22 UTC (rev 801)
@@ -17,13 +17,7 @@
 
 package org.jboss.webbeans.bootstrap;
 
-import static org.jboss.webbeans.bean.BeanFactory.createEnterpriseBean;
-import static org.jboss.webbeans.bean.BeanFactory.createEventBean;
-import static org.jboss.webbeans.bean.BeanFactory.createInstanceBean;
-import static org.jboss.webbeans.bean.BeanFactory.createObserver;
-import static org.jboss.webbeans.bean.BeanFactory.createProducerFieldBean;
-import static org.jboss.webbeans.bean.BeanFactory.createProducerMethodBean;
-import static org.jboss.webbeans.bean.BeanFactory.createSimpleBean;
+import static org.jboss.webbeans.bean.BeanFactory.*;
 
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Constructor;
@@ -37,6 +31,7 @@
 import javax.webbeans.DefinitionException;
 import javax.webbeans.Fires;
 import javax.webbeans.Initializer;
+import javax.webbeans.New;
 import javax.webbeans.Observer;
 import javax.webbeans.Observes;
 import javax.webbeans.Obtains;
@@ -48,6 +43,7 @@
 import org.jboss.webbeans.bean.BeanFactory;
 import org.jboss.webbeans.bean.EventBean;
 import org.jboss.webbeans.bean.InstanceBean;
+import org.jboss.webbeans.bean.NewSimpleBean;
 import org.jboss.webbeans.bean.ProducerFieldBean;
 import org.jboss.webbeans.bean.ProducerMethodBean;
 import org.jboss.webbeans.bean.SimpleBean;
@@ -69,26 +65,26 @@
 import org.jboss.webbeans.util.Reflections;
 
 /**
- * Common bootstrapping functionality that is run at application startup and detects
- * and register beans
+ * Common bootstrapping functionality that is run at application startup and
+ * detects and register beans
  * 
  * @author Pete Muir
  */
 public abstract class WebBeansBootstrap
-{ 
+{
    // The log provider
    private static LogProvider log = Logging.getLogProvider(WebBeansBootstrap.class);
-   
+
    // The Web Beans manager
    private ManagerImpl manager;
-   
+
    protected void initManager(Naming naming, EjbResolver ejbResolver, ResourceLoader resourceLoader)
    {
       this.manager = new ManagerImpl(naming, ejbResolver, resourceLoader);
       manager.getNaming().bind(ManagerImpl.JNDI_KEY, getManager());
       CurrentManager.setRootManager(manager);
    }
-   
+
    public ManagerImpl getManager()
    {
       return manager;
@@ -97,7 +93,7 @@
    protected abstract WebBeanDiscovery getWebBeanDiscovery();
 
    public abstract ResourceLoader getResourceLoader();
-   
+
    protected void validateBootstrap()
    {
       if (getManager() == null)
@@ -125,7 +121,8 @@
    }
 
    /**
-    * Register the bean with the getManager(), including any standard (built in) beans
+    * Register the bean with the getManager(), including any standard (built in)
+    * beans
     * 
     * @param classes The classes to register as Web Beans
     */
@@ -133,9 +130,37 @@
    {
       Set<AbstractBean<?, ?>> beans = createBeans(classes);
       beans.addAll(createStandardBeans());
+      // TODO: Is there any better way to do this? Currently, producer method parameters aren't
+      // listed in the containing beans injection points since they will be separated into 
+      // producer beans of their own so we'll have to make a second pass to make sure we hit the
+      // created producer beans also.
+      registerNewBeans(beans);
       getManager().setBeans(beans);
    }
-   
+
+   private void registerNewBeans(Set<AbstractBean<?, ?>> beans)
+   {
+      Set<AbstractBean<?, ?>> newBeans = new HashSet<AbstractBean<?, ?>>();
+      for (AbstractBean<?, ?> bean : beans)
+      {
+         for (AnnotatedItem<?, ?> injectionPoint : bean.getInjectionPoints())
+            if (injectionPoint.isAnnotationPresent(New.class))
+            {
+               if (manager.getEjbDescriptorCache().containsKey(injectionPoint.getType()))
+               {
+
+               }
+               else
+               {
+                  NewSimpleBean<?> newSimpleBean = createNewSimpleBean(injectionPoint.getType(), manager);
+                  newBeans.add(newSimpleBean);
+                  log.info("Web Bean: " + newSimpleBean);
+               }
+            }
+      }
+      beans.addAll(newBeans);
+   }
+
    /**
     * Creates the standard beans used internally by the RI
     * 
@@ -148,25 +173,25 @@
       final ManagerImpl managerImpl = getManager();
       createBean(new SimpleBean<ManagerImpl>(ManagerImpl.class, getManager())
       {
-   
+
          @Override
          protected void initConstructor()
          {
             // No - op, no constructor needed
          }
-         
+
          @Override
          protected void initInjectionPoints()
          {
             injectionPoints = Collections.emptySet();
          }
-         
+
          @Override
          public ManagerImpl create()
          {
             return managerImpl;
          }
-   
+
       }, beans);
       return beans;
    }
@@ -198,9 +223,10 @@
       }
       return beans;
    }
-   
+
    /**
-    * Creates a Web Bean from a bean abstraction and adds it to the set of created beans
+    * Creates a Web Bean from a bean abstraction and adds it to the set of
+    * created beans
     * 
     * Also creates the implicit field- and method-level beans, if present
     * 
@@ -228,11 +254,11 @@
       }
       for (AnnotatedItem injectionPoint : bean.getInjectionPoints())
       {
-         if ( injectionPoint.isAnnotationPresent(Fires.class) )  
+         if (injectionPoint.isAnnotationPresent(Fires.class))
          {
             registerEvent(injectionPoint, beans);
          }
-         if ( injectionPoint.isAnnotationPresent(Obtains.class) )  
+         if (injectionPoint.isAnnotationPresent(Obtains.class))
          {
             InstanceBean<Object, Field> instanceBean = createInstanceBean(injectionPoint, getManager());
             beans.add(instanceBean);
@@ -250,17 +276,16 @@
          {
             throw new DefinitionException("Observer method can only have one parameter annotated @Observes " + observer);
          }
-         
+
       }
       log.info("Web Bean: " + bean);
    }
 
-
    /**
     * Starts the boot process.
     * 
-    * Discovers the beans and registers them with the getManager(). Also resolves the
-    * injection points.
+    * Discovers the beans and registers them with the getManager(). Also
+    * resolves the injection points.
     * 
     * @param webBeanDiscovery The discovery implementation
     */
@@ -270,7 +295,8 @@
       {
          log.info("Starting Web Beans RI " + getVersion());
          validateBootstrap();
-         // Must populate EJB cache first, as we need it to detect whether a bean is an EJB!
+         // Must populate EJB cache first, as we need it to detect whether a
+         // bean is an EJB!
          getManager().getEjbDescriptorCache().addAll(getWebBeanDiscovery().discoverEjbs());
          registerBeans(getWebBeanDiscovery().discoverWebBeanClasses());
          log.info("Validing Web Bean injection points");
@@ -303,7 +329,7 @@
    {
       getManager().addObserver(observer, (Class<T>) eventType, bindings);
    }
-   
+
    /**
     * Iterates through the injection points and creates and registers any Event
     * observables specified with the @Observable annotation
@@ -312,24 +338,25 @@
     * @param beans A set of beans to add the Event beans to
     */
    @SuppressWarnings("unchecked")
-   private void registerEvents(Set<AnnotatedItem<?,?>> injectionPoints, Set<AbstractBean<?, ?>> beans)
+   private void registerEvents(Set<AnnotatedItem<?, ?>> injectionPoints, Set<AbstractBean<?, ?>> beans)
    {
       for (AnnotatedItem injectionPoint : injectionPoints)
       {
          registerEvent(injectionPoint, beans);
       }
    }
-   
+
    @SuppressWarnings("unchecked")
    private void registerEvent(AnnotatedItem injectionPoint, Set<AbstractBean<?, ?>> beans)
    {
-      if ( injectionPoint.isAnnotationPresent(Fires.class) )
+      if (injectionPoint.isAnnotationPresent(Fires.class))
       {
          EventBean<Object, Method> eventBean = createEventBean(injectionPoint, getManager());
          beans.add(eventBean);
          log.info("Web Bean: " + eventBean);
-      }      
+      }
    }
+
    /**
     * Indicates if the type is a simple Web Bean
     * 
@@ -341,29 +368,23 @@
       EJBApiAbstraction ejbApiAbstraction = new EJBApiAbstraction(getResourceLoader());
       JSFApiAbstraction jsfApiAbstraction = new JSFApiAbstraction(getResourceLoader());
       ServletApiAbstraction servletApiAbstraction = new ServletApiAbstraction(getResourceLoader());
-      //TODO: check 3.2.1 for more rules!!!!!!
-      return !type.isAnnotation() && 
-      	    !Reflections.isAbstract(type) && 
-      	    !servletApiAbstraction.SERVLET_CLASS.isAssignableFrom(type) && 
-      	    !servletApiAbstraction.FILTER_CLASS.isAssignableFrom(type) && 
-      	    !servletApiAbstraction.SERVLET_CONTEXT_LISTENER_CLASS.isAssignableFrom(type) && 
-      	    !servletApiAbstraction.HTTP_SESSION_LISTENER_CLASS.isAssignableFrom(type) && 
-      	    !servletApiAbstraction.SERVLET_REQUEST_LISTENER_CLASS.isAssignableFrom(type) && 
-      	    !ejbApiAbstraction.ENTERPRISE_BEAN_CLASS.isAssignableFrom(type) && 
-      	    !jsfApiAbstraction.UICOMPONENT_CLASS.isAssignableFrom(type) &&
-      	    hasSimpleWebBeanConstructor(type);
+      // TODO: check 3.2.1 for more rules!!!!!!
+      return !type.isAnnotation() && !Reflections.isAbstract(type) && !servletApiAbstraction.SERVLET_CLASS.isAssignableFrom(type) && !servletApiAbstraction.FILTER_CLASS.isAssignableFrom(type) && !servletApiAbstraction.SERVLET_CONTEXT_LISTENER_CLASS.isAssignableFrom(type) && !servletApiAbstraction.HTTP_SESSION_LISTENER_CLASS.isAssignableFrom(type) && !servletApiAbstraction.SERVLET_REQUEST_LISTENER_CLASS.isAssignableFrom(type) && !ejbApiAbstraction.ENTERPRISE_BEAN_CLASS.isAssignableFrom(type) && !jsfApiAbstraction.UICOMPONENT_CLASS.isAssignableFrom(type) && hasSimpleWebBeanConstructor(type);
    }
 
-   private static boolean hasSimpleWebBeanConstructor(Class<?> type) {
-      try {
+   private static boolean hasSimpleWebBeanConstructor(Class<?> type)
+   {
+      try
+      {
          type.getDeclaredConstructor();
          return true;
       }
       catch (NoSuchMethodException nsme)
       {
-         for (Constructor<?> c: type.getDeclaredConstructors())
+         for (Constructor<?> c : type.getDeclaredConstructors())
          {
-            if (c.isAnnotationPresent(Initializer.class)) return true;
+            if (c.isAnnotationPresent(Initializer.class))
+               return true;
          }
          return false;
       }

Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/newbean/NewBeanTest.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/newbean/NewBeanTest.java	2009-01-06 23:52:50 UTC (rev 800)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/newbean/NewBeanTest.java	2009-01-07 07:58:22 UTC (rev 801)
@@ -16,7 +16,10 @@
 import org.jboss.webbeans.test.SpecAssertion;
 import org.jboss.webbeans.test.SpecVersion;
 import org.jboss.webbeans.test.mock.MockWebBeanDiscovery;
-import org.jboss.webbeans.test.newbean.valid.Sample;
+import org.jboss.webbeans.test.newbean.valid.AnnotatedConstructorParameter;
+import org.jboss.webbeans.test.newbean.valid.AnnotatedField;
+import org.jboss.webbeans.test.newbean.valid.AnnotatedInitializerParameter;
+import org.jboss.webbeans.test.newbean.valid.AnnotatedProducerParameter;
 import org.jboss.webbeans.test.newbean.valid.WrappedBean;
 import org.jboss.webbeans.util.Proxies.TypeInfo;
 import org.testng.annotations.BeforeMethod;
@@ -337,7 +340,7 @@
    @SpecAssertion(section = "3.9")
    public void testNewAnnotationMayBeAppliedToField()
    {
-      webBeansBootstrap.setWebBeanDiscovery(new MockWebBeanDiscovery(Sample.class));
+      webBeansBootstrap.setWebBeanDiscovery(new MockWebBeanDiscovery(AnnotatedField.class));
       webBeansBootstrap.boot();
       assert manager.resolveByType(WrappedBean.class, new NewBinding()).size() == 1;
    }
@@ -354,7 +357,9 @@
    @SpecAssertion(section = "3.9")
    public void testNewAnnotationMayBeAppliedToProducerMethodParameter()
    {
-      assert false;
+      webBeansBootstrap.setWebBeanDiscovery(new MockWebBeanDiscovery(AnnotatedProducerParameter.class));
+      webBeansBootstrap.boot();
+      assert manager.resolveByType(WrappedBean.class, new NewBinding()).size() == 1;
    }
 
    /**
@@ -369,7 +374,9 @@
    @SpecAssertion(section = "3.9")
    public void testNewAnnotationMayBeAppliedToInitializerMethodParameter()
    {
-      assert false;
+      webBeansBootstrap.setWebBeanDiscovery(new MockWebBeanDiscovery(AnnotatedInitializerParameter.class));
+      webBeansBootstrap.boot();
+      assert manager.resolveByType(WrappedBean.class, new NewBinding()).size() == 1;
    }
 
    /**
@@ -384,7 +391,9 @@
    @SpecAssertion(section = "3.9")
    public void testNewAnnotationMayBeAppliedToConstructorMethodParameter()
    {
-      assert false;
+      webBeansBootstrap.setWebBeanDiscovery(new MockWebBeanDiscovery(AnnotatedConstructorParameter.class));
+      webBeansBootstrap.boot();
+      assert manager.resolveByType(WrappedBean.class, new NewBinding()).size() == 1;
    }
 
    /**

Added: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/newbean/valid/AnnotatedConstructorParameter.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/newbean/valid/AnnotatedConstructorParameter.java	                        (rev 0)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/newbean/valid/AnnotatedConstructorParameter.java	2009-01-07 07:58:22 UTC (rev 801)
@@ -0,0 +1,28 @@
+package org.jboss.webbeans.test.newbean.valid;
+
+import javax.webbeans.Initializer;
+import javax.webbeans.New;
+import javax.webbeans.Produces;
+
+
+public class AnnotatedConstructorParameter
+{
+   @New
+   WrappedBean reference;
+
+   @Initializer
+   public AnnotatedConstructorParameter(@New WrappedBean reference)
+   {
+   }
+
+   @Initializer
+   public void init(@New WrappedBean reference)
+   {
+   }
+
+   @Produces
+   Object produce(@New WrappedBean reference)
+   {
+      return new Object();
+   }
+}

Copied: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/newbean/valid/AnnotatedField.java (from rev 800, ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/newbean/valid/Sample.java)
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/newbean/valid/AnnotatedField.java	                        (rev 0)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/newbean/valid/AnnotatedField.java	2009-01-07 07:58:22 UTC (rev 801)
@@ -0,0 +1,11 @@
+package org.jboss.webbeans.test.newbean.valid;
+
+import javax.webbeans.New;
+
+
+public class AnnotatedField
+{
+   @New
+   WrappedBean reference;
+
+}


Property changes on: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/newbean/valid/AnnotatedField.java
___________________________________________________________________
Name: svn:mergeinfo
   + 

Added: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/newbean/valid/AnnotatedInitializerParameter.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/newbean/valid/AnnotatedInitializerParameter.java	                        (rev 0)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/newbean/valid/AnnotatedInitializerParameter.java	2009-01-07 07:58:22 UTC (rev 801)
@@ -0,0 +1,13 @@
+package org.jboss.webbeans.test.newbean.valid;
+
+import javax.webbeans.Initializer;
+import javax.webbeans.New;
+
+
+public class AnnotatedInitializerParameter
+{
+   @Initializer
+   public void init(@New WrappedBean reference)
+   {
+   }
+}

Added: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/newbean/valid/AnnotatedProducerParameter.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/newbean/valid/AnnotatedProducerParameter.java	                        (rev 0)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/newbean/valid/AnnotatedProducerParameter.java	2009-01-07 07:58:22 UTC (rev 801)
@@ -0,0 +1,14 @@
+package org.jboss.webbeans.test.newbean.valid;
+
+import javax.webbeans.New;
+import javax.webbeans.Produces;
+
+
+public class AnnotatedProducerParameter
+{
+   @Produces
+   Object produce(@New WrappedBean reference)
+   {
+      return new Object();
+   }
+}

Deleted: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/newbean/valid/Sample.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/newbean/valid/Sample.java	2009-01-06 23:52:50 UTC (rev 800)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/newbean/valid/Sample.java	2009-01-07 07:58:22 UTC (rev 801)
@@ -1,28 +0,0 @@
-package org.jboss.webbeans.test.newbean.valid;
-
-import javax.webbeans.Initializer;
-import javax.webbeans.New;
-import javax.webbeans.Produces;
-
-
-public class Sample
-{
-   @New
-   WrappedBean reference;
-
-   @Initializer
-   public Sample(@New WrappedBean reference)
-   {
-   }
-
-   @Initializer
-   public void init(@New WrappedBean reference)
-   {
-   }
-
-   @Produces
-   Object produce(@New WrappedBean reference)
-   {
-      return new Object();
-   }
-}




More information about the weld-commits mailing list