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

webbeans-commits at lists.jboss.org webbeans-commits at lists.jboss.org
Thu Jan 8 12:40:09 EST 2009


Author: dallen6
Date: 2009-01-08 12:40:08 -0500 (Thu, 08 Jan 2009)
New Revision: 835

Added:
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/InjectionPointBean.java
Modified:
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/Resolver.java
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/SimpleBean.java
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/injection/InjectionPointFactory.java
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AbstractAnnotatedMember.java
Log:
Refactored some of the injection point metadata bean code.

Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/Resolver.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/Resolver.java	2009-01-08 17:25:51 UTC (rev 834)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/Resolver.java	2009-01-08 17:40:08 UTC (rev 835)
@@ -28,6 +28,7 @@
 import java.util.TreeSet;
 import java.util.concurrent.Callable;
 
+import javax.webbeans.InjectionPoint;
 import javax.webbeans.NullableDependencyException;
 import javax.webbeans.TypeLiteral;
 import javax.webbeans.manager.Bean;
@@ -35,6 +36,7 @@
 import javax.webbeans.manager.InterceptionType;
 import javax.webbeans.manager.Interceptor;
 
+import org.jboss.webbeans.bean.InjectionPointBean;
 import org.jboss.webbeans.introspector.AnnotatedItem;
 import org.jboss.webbeans.introspector.ForwardingAnnotatedItem;
 import org.jboss.webbeans.model.BindingTypeModel;
@@ -215,6 +217,10 @@
       {
          beans = new HashSet<Bean<T>>((List) manager.getBeans());
       }
+      else if (InjectionPoint.class.isAssignableFrom(element.getType()))
+      {
+         beans.add(InjectionPointBean.of(key, manager));
+      }
       else
       {
          beans = registerInjectionPoint(element);

Added: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/InjectionPointBean.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/InjectionPointBean.java	                        (rev 0)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/InjectionPointBean.java	2009-01-08 17:40:08 UTC (rev 835)
@@ -0,0 +1,66 @@
+/*
+ * 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.bean;
+
+import org.jboss.webbeans.ManagerImpl;
+import org.jboss.webbeans.introspector.AnnotatedItem;
+
+/**
+ * Bean for InjectionPoint metadata
+ * 
+ * @author David Allen
+ * 
+ */
+public class InjectionPointBean<T, S> extends AbstractFacadeBean<T, S, Object>
+{
+
+   /**
+    * Creates an InjectionPoint Web Bean for the injection of the containing bean owning
+    * the field, constructor or method for the annotated item
+    * 
+    * @param <T> must be InjectionPoint
+    * @param <S>
+    * @param field The annotated member field/parameter for the injection
+    * @param manager The RI manager implementation
+    * @return a new bean for this injection point
+    */
+   public static <T, S> InjectionPointBean<T, S> of(AnnotatedItem<T, S> field, ManagerImpl manager)
+   {
+      return new InjectionPointBean<T, S>(field, manager);
+   }
+
+   protected InjectionPointBean(AnnotatedItem<T, S> field, ManagerImpl manager)
+   {
+      super(field, manager);
+   }
+
+   @SuppressWarnings("unchecked")
+   @Override
+   public T create()
+   {
+      return (T) manager.getInjectionPointFactory().getPreviousInjectionPoint();
+   }
+
+   @Override
+   public void destroy(T instance)
+   {
+      // The instance is always in the Dependent context and can be garbage
+      // collected
+   }
+
+}


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

Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/SimpleBean.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/SimpleBean.java	2009-01-08 17:25:51 UTC (rev 834)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/SimpleBean.java	2009-01-08 17:40:08 UTC (rev 835)
@@ -119,15 +119,29 @@
          }
          InjectionPointFactory injectionPointFactory = manager.getInjectionPointFactory();
          injectionPointFactory.pushBean(this);
-         T instance = constructor.newInstance(manager);
-         injectionPointFactory.pushInstance(instance);
-         bindDecorators();
-         bindInterceptors();
-         injectEjbAndCommonFields(instance);
-         injectBoundFields(instance);
-         callInitializers(instance);
-         callPostConstruct(instance);
-         injectionPointFactory.popBeanAndInstance();
+         T instance = null;
+         try
+         {
+            instance = constructor.newInstance(manager);
+            try
+            {
+               injectionPointFactory.pushInstance(instance);
+               bindDecorators();
+               bindInterceptors();
+               injectEjbAndCommonFields(instance);
+               injectBoundFields(instance);
+               callInitializers(instance);
+               callPostConstruct(instance);
+            }
+            finally
+            {
+               injectionPointFactory.popInstance();
+            }
+         }
+         finally
+         {
+            injectionPointFactory.popBean();
+         }
          return instance;
       }
       finally
@@ -261,15 +275,14 @@
       for (AnnotatedField<?> injectableField : getInjectableFields())
       {
          injectionPointFactory.pushInjectionPoint(injectableField);
-         if (InjectionPoint.class.isAssignableFrom(injectableField.getType()))
+         try
          {
-            injectableField.inject(instance, injectionPointFactory.newInstance());
+            injectableField.inject(instance, manager);
          }
-         else
+         finally
          {
-            injectableField.inject(instance, manager);
+            injectionPointFactory.popInjectionPoint();
          }
-         injectionPointFactory.popInjectionPoint();
       }
    }
 

Modified: 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	2009-01-08 17:25:51 UTC (rev 834)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/injection/InjectionPointFactory.java	2009-01-08 17:40:08 UTC (rev 835)
@@ -73,12 +73,20 @@
    }
 
    /**
-    * Pops the bean and its current instance from the stack.  This should be called
+    * Pops the bean from the stack.  This should be called
     * whenever all processing is complete for instantiating a bean.
     */
-   public void popBeanAndInstance()
+   public void popBean()
    {
       beans.pop();
+   }
+
+   /**
+    * Pops the current instance from the stack.  This should be called
+    * whenever all processing is complete for instantiating a bean.
+    */
+   public void popInstance()
+   {
       beanInstances.pop();
    }
 
@@ -98,7 +106,7 @@
     * 
     * @return a new injection point metadata object
     */
-   public InjectionPoint newInstance()
+   public InjectionPoint getPreviousInjectionPoint()
    {
       // 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

Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AbstractAnnotatedMember.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AbstractAnnotatedMember.java	2009-01-08 17:25:51 UTC (rev 834)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AbstractAnnotatedMember.java	2009-01-08 17:40:08 UTC (rev 835)
@@ -26,7 +26,6 @@
 import java.util.Map;
 
 import javax.webbeans.BindingType;
-import javax.webbeans.InjectionPoint;
 import javax.webbeans.manager.Manager;
 
 import org.jboss.webbeans.ManagerImpl;
@@ -138,7 +137,7 @@
    {
       return Reflections.isTransient(getDelegate());
    }
-   
+
    /**
     * Gets the current value of the member
     * 
@@ -176,16 +175,16 @@
       }
       toString = "Abstract annotated member " + getName();
       return toString;
-   }   
-   
+   }
+
    public S getMember()
    {
       return getDelegate();
    }
 
    /**
-    * Helper method for getting the current parameter values from a list
-    * of annotated parameters.
+    * Helper method for getting the current parameter values from a list of
+    * annotated parameters.
     * 
     * @param parameters The list of annotated parameter to look up
     * @param manager The Web Beans manager
@@ -197,8 +196,8 @@
    }
 
    /**
-    * Helper method for getting the current parameter values from a list
-    * of annotated parameters.
+    * Helper method for getting the current parameter values from a list of
+    * annotated parameters.
     * 
     * @param parameters The list of annotated parameter to look up
     * @param manager The Web Beans manager
@@ -206,27 +205,30 @@
     */
    protected Object[] getParameterValues(List<AnnotatedParameter<Object>> parameters, Object specialVal, Class<? extends Annotation> specialParam, ManagerImpl manager)
    {
+      Object[] parameterValues = new Object[parameters.size()];
       InjectionPointFactory injectionPointFactory = manager.getInjectionPointFactory();
       injectionPointFactory.pushInjectionPoint(this);
-      Object[] parameterValues = new Object[parameters.size()];
-      Iterator<AnnotatedParameter<Object>> iterator = parameters.iterator();
-      for (int i = 0; i < parameterValues.length; i++)
+      try
       {
-         AnnotatedParameter<Object> param = iterator.next();
-         if ( specialParam!=null && param.isAnnotationPresent(specialParam)) 
+         Iterator<AnnotatedParameter<Object>> iterator = parameters.iterator();
+         for (int i = 0; i < parameterValues.length; i++)
          {
-            parameterValues[i] = specialVal;
+            AnnotatedParameter<Object> param = iterator.next();
+            if (specialParam != null && param.isAnnotationPresent(specialParam))
+            {
+               parameterValues[i] = specialVal;
+            }
+            else
+            {
+               parameterValues[i] = param.getValue(manager);
+            }
          }
-         else if ( InjectionPoint.class.isAssignableFrom(param.getType()) )
-         {
-            parameterValues[i] = injectionPointFactory.newInstance();
-         }
-         else 
-         {
-            parameterValues[i] = param.getValue(manager);
-         }
       }
-      injectionPointFactory.popInjectionPoint();
+      finally
+      {
+         injectionPointFactory.popInjectionPoint();
+
+      }
       return parameterValues;
    }
 




More information about the weld-commits mailing list