openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dblev...@apache.org
Subject svn commit: r820405 - /incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/NotificationManager.java
Date Wed, 30 Sep 2009 19:23:49 GMT
Author: dblevins
Date: Wed Sep 30 19:23:49 2009
New Revision: 820405

URL: http://svn.apache.org/viewvc?rev=820405&view=rev
Log:
Cleaned up fireEvent method to flatten it a bit and remove redundant else cases.

Modified:
    incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/NotificationManager.java

Modified: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/NotificationManager.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/NotificationManager.java?rev=820405&r1=820404&r2=820405&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/NotificationManager.java
(original)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/NotificationManager.java
Wed Sep 30 19:23:49 2009
@@ -18,7 +18,6 @@
 import java.lang.reflect.Type;
 import java.util.Arrays;
 import java.util.HashSet;
-import java.util.Iterator;
 import java.util.Map;
 import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
@@ -166,6 +165,8 @@
 
     public void fireEvent(Object event, Annotation... bindings)
     {
+        Transaction transaction = transactionService.getTransaction();
+
         Set<Observer<Object>> observers = resolveObservers(event, bindings);
 
         TransactionalNotifier transNotifier = null;
@@ -173,52 +174,37 @@
         {
             try
             {
-                if(observer instanceof BeanObserverImpl)
+                if (transaction != null && isTransactional(observer))
                 {
+
+                    // TODO: we only need to register once
+                    transaction.registerSynchronization(this);
+
+                    if (transNotifier == null)
+                    {
+                        transNotifier = new TransactionalNotifier(event);
+                        this.transactionSet.add(transNotifier);
+                    }
+
+                    // Register for transaction
                     BeanObserverImpl<Object> beanObserver = (BeanObserverImpl<Object>)
observer;
                     TransactionalObserverType type = beanObserver.getType();
-                    if (!(type.equals(TransactionalObserverType.NONE)))
+                    if (type.equals(TransactionalObserverType.AFTER_TRANSACTION_COMPLETION))
                     {
-                        Transaction transaction = transactionService.getTransaction();
-
-                        if (transaction != null)
-                        {
-                            transaction.registerSynchronization(this);
-
-                            if (transNotifier == null)
-                            {
-                                transNotifier = new TransactionalNotifier(event);
-                                this.transactionSet.add(transNotifier);
-                            }
-
-                            // Register for transaction
-                            if (type.equals(TransactionalObserverType.AFTER_TRANSACTION_COMPLETION))
-                            {
-                                transNotifier.addAfterCompletionObserver(observer);
-                            }
-                            else if (type.equals(TransactionalObserverType.AFTER_TRANSACTION_SUCCESS))
-                            {
-                                transNotifier.addAfterCompletionSuccessObserver(observer);
-                            }
-                            else if (type.equals(TransactionalObserverType.AFTER_TRANSACTION_FAILURE))
-                            {
-                                transNotifier.addAfterCompletionFailureObserver(observer);
-                            }
-                            else if (type.equals(TransactionalObserverType.BEFORE_TRANSACTION_COMPLETION))
-                            {
-                                transNotifier.addBeforeCompletionObserver(observer);
-                            }
-                        }
-                        else
-                        {
-                            observer.notify(event);
-                        }
+                        transNotifier.addAfterCompletionObserver(observer);
                     }
-                    else
+                    else if (type.equals(TransactionalObserverType.AFTER_TRANSACTION_SUCCESS))
                     {
-                        observer.notify(event);
+                        transNotifier.addAfterCompletionSuccessObserver(observer);
+                    }
+                    else if (type.equals(TransactionalObserverType.AFTER_TRANSACTION_FAILURE))
+                    {
+                        transNotifier.addAfterCompletionFailureObserver(observer);
+                    }
+                    else if (type.equals(TransactionalObserverType.BEFORE_TRANSACTION_COMPLETION))
+                    {
+                        transNotifier.addBeforeCompletionObserver(observer);
                     }
-
                 }
                 else
                 {
@@ -249,6 +235,23 @@
         }
     }
 
+    private boolean isTransactional(Observer<?> observer)
+    {
+        if (!(observer instanceof BeanObserverImpl))
+        {
+            return false;
+        }
+
+        BeanObserverImpl<?> beanObserver = (BeanObserverImpl<?>) observer;
+
+        if (beanObserver.getType().equals(TransactionalObserverType.NONE))
+        {
+            return false;
+        }
+
+        return true;
+    }
+
     public <T> void addObservableComponentMethods(InjectionTargetBean<?> component)
     {
         Asserts.assertNotNull(component, "component parameter can not be null");



Mime
View raw message