openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gerdo...@apache.org
Subject svn commit: r915019 - in /openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans: component/BeanManagerBean.java event/ObserverMethodImpl.java event/xml/BeanObserverXMLImpl.java
Date Mon, 22 Feb 2010 19:03:00 GMT
Author: gerdogdu
Date: Mon Feb 22 19:03:00 2010
New Revision: 915019

URL: http://svn.apache.org/viewvc?rev=915019&view=rev
Log:
Refactoring of recently committed changes.

Modified:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/BeanManagerBean.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/ObserverMethodImpl.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/xml/BeanObserverXMLImpl.java

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/BeanManagerBean.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/BeanManagerBean.java?rev=915019&r1=915018&r2=915019&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/BeanManagerBean.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/BeanManagerBean.java
Mon Feb 22 19:03:00 2010
@@ -26,6 +26,7 @@
     public BeanManagerBean()
     {
         super(WebBeansType.MANAGER, BeanManager.class);
+        setImplScopeType(new ApplicationScopeLiteral());
     }
 
     @Override
@@ -35,7 +36,6 @@
         {
             manager = BeanManagerImpl.getManager();
         }
-        setImplScopeType(new ApplicationScopeLiteral());
 
         return manager;
     }

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=915019&r1=915018&r2=915019&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
Mon Feb 22 19:03:00 2010
@@ -94,6 +94,16 @@
     /** the transaction phase */
     private final TransactionPhase phase;
     
+    private static class ObserverParams
+    {
+        private Bean<Object> bean;
+        
+        private Object instance;
+        
+        private CreationalContext<Object> creational;
+        
+        private boolean isBean = false;
+    }
     
     /**
      * Creates a new bean observer instance.
@@ -160,20 +170,24 @@
         Object object = null;
         
         CreationalContext<Object> creationalContext = null;
-        
+        List<ObserverParams> methodArgsMap = getMethodArguments(event);
+        ObserverParams[] obargs = null;
         try
         {
-            Object[] args = null;
-            
-            List<Object> argsObjects = getMethodArguments(event);
-            args = new Object[argsObjects.size()];
-            args = argsObjects.toArray(args);
-
             if (!this.observerMethod.isAccessible())
             {
                 this.observerMethod.setAccessible(true);
             }
             
+            obargs = new ObserverParams[methodArgsMap.size()];
+            obargs = methodArgsMap.toArray(obargs);
+            Object[] args = new Object[obargs.length];
+            int i = 0;
+            for(ObserverParams param : obargs)
+            {
+                args[i++] = param.instance;
+            }
+            
             //Static or not
             if (Modifier.isStatic(this.observerMethod.getModifiers()))
             {
@@ -210,10 +224,23 @@
         }
         finally
         {
+            //Destory bean instance
             if (baseComponent.getScope().equals(Dependent.class))
             {
                 baseComponent.destroy(object,(CreationalContext<Object>)creationalContext);
             }
+            
+            //Destroy observer method dependent instances
+            if(methodArgsMap != null)
+            {
+                for(ObserverParams param : obargs)
+                {
+                    if(param.isBean)
+                    {
+                        param.bean.destroy(param.instance, param.creational);
+                    }
+                }
+            }
         }
 
     }
@@ -224,16 +251,16 @@
      * @param event event instance
      * @return list of observer method parameters
      */
-    protected List<Object> getMethodArguments(Object event)
+    protected List<ObserverParams> getMethodArguments(Object event)
     {
         Type[] types = this.observerMethod.getGenericParameterTypes();
 
         Annotation[][] annots = this.observerMethod.getParameterAnnotations();
 
-        List<Object> list = new ArrayList<Object>();
+        List<ObserverParams> list = new ArrayList<ObserverParams>();
 
         BeanManagerImpl manager = BeanManagerImpl.getManager();
-
+        ObserverParams param = null;
         if (types.length > 0)
         {
             int i = 0;
@@ -254,7 +281,9 @@
                     {
                         if (observersAnnot.annotationType().equals(Observes.class))
                         {
-                            list.add(event);
+                            param = new ObserverParams();
+                            param.instance = event;
+                            list.add(param); 
                             observesAnnotation = true;
                             break;
                         }
@@ -269,13 +298,22 @@
                     if (bindingTypes.length > 0)
                     {
                         InjectionPoint point = InjectionPointFactory.getPartialInjectionPoint(null,
type, null, null, bindingTypes);
-                        Bean<?> bean = InjectionResolver.getInstance().getInjectionPointBean(point);
+                        @SuppressWarnings("unchecked")
+                        Bean<Object> bean = (Bean<Object>)InjectionResolver.getInstance().getInjectionPointBean(point);
+                        CreationalContext<Object> creational = manager.createCreationalContext(bean);
+                        Object instance = manager.getInstance(bean, creational); 
                         
-                        list.add(manager.getInstance(bean, manager.createCreationalContext(bean)));
+                        param = new ObserverParams();
+                        param.isBean = true;
+                        param.creational = creational;
+                        param.instance = instance;
+                        param.bean = bean;
+                        list.add(param);
                     }
                     else
                     {
-                        list.add(null);
+                        param = new ObserverParams();
+                        list.add(param);
                     }
                 }
                 

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/xml/BeanObserverXMLImpl.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/xml/BeanObserverXMLImpl.java?rev=915019&r1=915018&r2=915019&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/xml/BeanObserverXMLImpl.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/xml/BeanObserverXMLImpl.java
Mon Feb 22 19:03:00 2010
@@ -48,7 +48,7 @@
      * .Object)
      */
     @Override
-    protected List<Object> getMethodArguments(Object event)
+    protected List getMethodArguments(Object event)
     {
         List<Object> params = new ArrayList<Object>();
         BeanManagerImpl manager = BeanManagerImpl.getManager();



Mime
View raw message