[webbeans-commits] Webbeans SVN: r809 - in ri/trunk/webbeans-ri/src: main/java/org/jboss/webbeans/bean and 3 other directories.

webbeans-commits at lists.jboss.org webbeans-commits at lists.jboss.org
Wed Jan 7 09:41:44 EST 2009


Author: dallen6
Date: 2009-01-07 09:41:44 -0500 (Wed, 07 Jan 2009)
New Revision: 809

Added:
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/injection/InjectionPointFactory.java
Modified:
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/EnterpriseBean.java
   ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/InjectionPointTest.java
   ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/FieldInjectionPointBean.java
Log:
Modifications needed for injection point metadata and fixes to tests; integration code was thrown out due to conflicting design changes; all tests marked broken.

Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java	2009-01-07 14:03:14 UTC (rev 808)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java	2009-01-07 14:41:44 UTC (rev 809)
@@ -56,6 +56,7 @@
 import org.jboss.webbeans.ejb.EjbDescriptorCache;
 import org.jboss.webbeans.ejb.spi.EjbResolver;
 import org.jboss.webbeans.event.EventManager;
+import org.jboss.webbeans.injection.InjectionPointFactory;
 import org.jboss.webbeans.introspector.AnnotatedItem;
 import org.jboss.webbeans.introspector.AnnotatedMethod;
 import org.jboss.webbeans.introspector.jlr.AnnotatedClassImpl;
@@ -83,8 +84,10 @@
 
    // The enabled deployment types from web-beans.xml
    private transient List<Class<? extends Annotation>> enabledDeploymentTypes;
-   // The Web Beans manager
+   // The Web Beans event manager
    private transient final EventManager eventManager;
+   // An injection point metadata beans factory
+   InjectionPointFactory injectionPointFactory;
 
    // The bean resolver
    private transient final Resolver resolver;
@@ -132,6 +135,7 @@
       this.contextMap = new ContextMap();
       this.eventManager = new EventManager();
       this.ejbDescriptorCache = new EjbDescriptorCache();
+      this.injectionPointFactory = new InjectionPointFactory();
 
       List<Class<? extends Annotation>> defaultEnabledDeploymentTypes = new ArrayList<Class<? extends Annotation>>();
       defaultEnabledDeploymentTypes.add(0, Standard.class);
@@ -758,4 +762,15 @@
       return CurrentManager.rootManager();
    }
 
+   /**
+    * Accesses the factory used to create each instance of InjectionPoint
+    * that is injected into web beans.
+    * 
+    * @return the factory
+    */
+   public final InjectionPointFactory getInjectionPointFactory()
+   {
+      return injectionPointFactory;
+   }
+
 }

Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/EnterpriseBean.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/EnterpriseBean.java	2009-01-07 14:03:14 UTC (rev 808)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/EnterpriseBean.java	2009-01-07 14:41:44 UTC (rev 809)
@@ -33,7 +33,6 @@
 import javax.webbeans.Observes;
 import javax.webbeans.Produces;
 import javax.webbeans.Specializes;
-import javax.webbeans.manager.Manager;
 
 import org.jboss.webbeans.ManagerImpl;
 import org.jboss.webbeans.context.DependentContext;
@@ -340,7 +339,7 @@
     * @param instance The bean instance
     * @param manager The Web Beans manager
     */
-   protected void injectBoundFields(T instance, Manager manager)
+   protected void injectBoundFields(T instance, ManagerImpl manager)
    {
       for (AnnotatedField<?> field : getInjectableFields())
       {

Added: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/injection/InjectionPointFactory.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/injection/InjectionPointFactory.java	                        (rev 0)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/injection/InjectionPointFactory.java	2009-01-07 14:41:44 UTC (rev 809)
@@ -0,0 +1,124 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.webbeans.injection;
+
+import java.lang.reflect.Member;
+import java.util.Stack;
+
+import javax.webbeans.InjectionPoint;
+import javax.webbeans.manager.Bean;
+
+import org.jboss.webbeans.introspector.jlr.AbstractAnnotatedMember;
+
+/**
+ * Factory used to create the container provided implementation for the
+ * InjectionPoint beans. This factory maintains a stack with the current bean
+ * and instance being created so that this information is readily available for
+ * construction of a new InjectionPoint bean.
+ * 
+ * @author David Allen
+ * 
+ */
+public class InjectionPointFactory
+{
+   private final Stack<Bean<?>> beans = new Stack<Bean<?>>();
+   private final Stack<Object> beanInstances = new Stack<Object>();
+   private final Stack<AbstractAnnotatedMember<?, ? extends Member>> injectionPoints = new Stack<AbstractAnnotatedMember<?, ? extends Member>>();
+
+   /**
+    * Pushes the current bean that is being instantiated onto a stack for later
+    * use.
+    * 
+    * @param currentBean The bean being instantiated
+    */
+   public void pushBean(Bean<?> currentBean)
+   {
+      beans.push(currentBean);
+   }
+
+   /**
+    * Pushes the current bean instance that has been instantiated, but has not
+    * yet had any injection points initialized.
+    * 
+    * @param currentInstance The bean instance last instantiated
+    */
+   public void pushInstance(Object currentInstance)
+   {
+      beanInstances.push(currentInstance);
+   }
+
+   /**
+    * Pushes the current injection point being processed.
+    * 
+    * @param injectedMember The metadata for the injection point
+    */
+   public void pushInjectionPoint(AbstractAnnotatedMember<?, ? extends Member> injectedMember)
+   {
+      injectionPoints.push(injectedMember);
+   }
+
+   /**
+    * Pops the bean and its current instance from the stack.  This should be called
+    * whenever all processing is complete for instantiating a bean.
+    */
+   public void popBeanAndInstance()
+   {
+      beans.pop();
+      beanInstances.pop();
+   }
+
+   /**
+    * Pops the current injection point being processed.  This should be called once
+    * the injection point is bound.
+    */
+   public void popInjectionPoint()
+   {
+      injectionPoints.pop();
+   }
+
+   /**
+    * Creates an InjectionPoint based on the current state of processing as
+    * indicated by this factory's stack of injection points and related
+    * information.
+    * 
+    * @return a new injection point metadata object
+    */
+   public InjectionPoint newInstance()
+   {
+      // When the injected member is a constructor, we are short one instance,
+      // so the instance on the top of the stack is the bean instance
+      // we want. Otherwise, it is the second to last instance same as
+      // the bean stack.
+      InjectionPoint injectionPoint = null;
+      Bean<?> currentBean = beans.pop();
+      AbstractAnnotatedMember<?, ? extends Member> currentInjection = injectionPoints.pop();
+      if (beanInstances.size() < beans.size())
+      {
+         injectionPoint = new InjectionPointImpl(injectionPoints.peek(), beans.peek(), beanInstances.peek());
+      }
+      else
+      {
+         Object currentInstance = beanInstances.pop();
+         injectionPoint = new InjectionPointImpl(injectionPoints.peek(), beans.peek(), beanInstances.peek());
+         beanInstances.push(currentInstance);
+      }
+      beans.push(currentBean);
+      injectionPoints.push(currentInjection);
+      return injectionPoint;
+   }
+}


Property changes on: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/injection/InjectionPointFactory.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/InjectionPointTest.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/InjectionPointTest.java	2009-01-07 14:03:14 UTC (rev 808)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/InjectionPointTest.java	2009-01-07 14:41:44 UTC (rev 809)
@@ -35,6 +35,7 @@
 import org.jboss.webbeans.test.beans.BeanWithInjectionPointMetadata;
 import org.jboss.webbeans.test.beans.ConstructorInjectionPointBean;
 import org.jboss.webbeans.test.beans.FieldInjectionPointBean;
+import org.jboss.webbeans.test.bindings.AnimalStereotypeAnnotationLiteral;
 import org.jboss.webbeans.test.mock.MockWebBeanDiscovery;
 import org.testng.annotations.Test;
 
@@ -61,6 +62,7 @@
          FieldInjectionPointBean beanWithInjectedBean = manager.getInstanceByType(FieldInjectionPointBean.class, new CurrentBinding());
          BeanWithInjectionPointMetadata beanWithInjectionPoint = beanWithInjectedBean.getInjectedBean();
          assert beanWithInjectionPoint.getInjectedMetadata() != null;
+         //TODO Fix injection issue where raw bean is used instead of proxied bean
          assert beanWithInjectionPoint.getInjectedMetadata().getInstance().equals(beanWithInjectedBean);
       }
       finally
@@ -84,8 +86,9 @@
          BeanWithInjectionPointMetadata beanWithInjectionPoint = beanWithInjectedBean.getInjectedBean();
          assert beanWithInjectionPoint.getInjectedMetadata() != null;
 
-         Set<Bean<FieldInjectionPointBean>> theBean = manager.resolveByType(FieldInjectionPointBean.class);
-         assert beanWithInjectionPoint.getInjectedMetadata().getBean().equals(theBean);
+         Set<Bean<FieldInjectionPointBean>> resolvedBeans = manager.resolveByType(FieldInjectionPointBean.class);
+         assert resolvedBeans.size() == 1;
+         assert beanWithInjectionPoint.getInjectedMetadata().getBean().equals(resolvedBeans.iterator().next());
       }
       finally
       {
@@ -107,7 +110,7 @@
          FieldInjectionPointBean beanWithInjectedBean = manager.getInstanceByType(FieldInjectionPointBean.class, new CurrentBinding());
          BeanWithInjectionPointMetadata beanWithInjectionPoint = beanWithInjectedBean.getInjectedBean();
          assert beanWithInjectionPoint.getInjectedMetadata() != null;
-         assert beanWithInjectionPoint.getInjectedMetadata().getType().equals(FieldInjectionPointBean.class);
+         assert beanWithInjectionPoint.getInjectedMetadata().getType().equals(BeanWithInjectionPointMetadata.class);
       }
       finally
       {
@@ -228,8 +231,8 @@
          assert beanWithInjectionPoint.getInjectedMetadata() != null;
          Set<Annotation> annotations = new HashSet<Annotation>(Arrays.asList(beanWithInjectionPoint.getInjectedMetadata().getAnnotations()));
          assert annotations.size() > 0;
-         assert annotations.contains(Current.class);
-         assert annotations.contains(AnimalStereotype.class);
+         assert annotations.contains(new CurrentBinding());
+         assert annotations.contains(new AnimalStereotypeAnnotationLiteral());
       }
       finally
       {
@@ -295,7 +298,7 @@
          FieldInjectionPointBean beanWithInjectedBean = manager.getInstanceByType(FieldInjectionPointBean.class, new CurrentBinding());
          BeanWithInjectionPointMetadata beanWithInjectionPoint = beanWithInjectedBean.getInjectedBean();
          assert beanWithInjectionPoint.getInjectedMetadata() != null;
-         assert beanWithInjectionPoint.getInjectedMetadata().getBean().getTypes().contains(InjectionPoint.class);
+         assert InjectionPoint.class.isAssignableFrom(beanWithInjectionPoint.getInjectedMetadata().getClass());
       }
       finally
       {

Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/FieldInjectionPointBean.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/FieldInjectionPointBean.java	2009-01-07 14:03:14 UTC (rev 808)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/FieldInjectionPointBean.java	2009-01-07 14:41:44 UTC (rev 809)
@@ -18,6 +18,7 @@
 package org.jboss.webbeans.test.beans;
 
 import javax.webbeans.Current;
+import javax.webbeans.RequestScoped;
 
 import org.jboss.webbeans.test.annotations.AnimalStereotype;
 
@@ -28,6 +29,7 @@
  * @author David Allen
  * 
  */
+ at RequestScoped
 public class FieldInjectionPointBean
 {
    @Current @AnimalStereotype




More information about the weld-commits mailing list