[seam-commits] Seam SVN: r12645 - modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/event.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Mon Apr 26 08:51:02 EDT 2010


Author: nickarls
Date: 2010-04-26 08:51:01 -0400 (Mon, 26 Apr 2010)
New Revision: 12645

Added:
   modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/event/AbstractListener.java
Modified:
   modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/event/DelegatingPhaseListener.java
   modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/event/DelegatingSystemEventListener.java
Log:
cleanup to abstract listener superclass

Added: modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/event/AbstractListener.java
===================================================================
--- modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/event/AbstractListener.java	                        (rev 0)
+++ modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/event/AbstractListener.java	2010-04-26 12:51:01 UTC (rev 12645)
@@ -0,0 +1,54 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */ 
+package org.jboss.seam.faces.event;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.spi.Bean;
+
+import org.jboss.weld.extensions.beanManager.BeanManagerAware;
+
+/**
+ * Superclass for event listeners
+ * 
+ * @author Nicklas Karlsson
+ *
+ * @param <T> Listener class
+ */
+public class AbstractListener<T> extends BeanManagerAware
+{
+   @SuppressWarnings("unchecked")
+   protected List<T> getListeners(Class<? extends T>... classes)
+   {
+      List<T> listeners = new ArrayList<T>();
+      for (Class<? extends T> clazz : classes) {
+         Bean<? extends T> bean = (Bean<? extends T>) getBeanManager().getBeans(clazz).iterator().next();
+         CreationalContext<? extends T> context = getBeanManager().createCreationalContext(bean);
+         T listener = (T) getBeanManager().getReference(bean, clazz, context);
+         listeners.add(listener);
+      }
+      return listeners;
+   }
+   
+}

Modified: modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/event/DelegatingPhaseListener.java
===================================================================
--- modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/event/DelegatingPhaseListener.java	2010-04-26 11:35:27 UTC (rev 12644)
+++ modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/event/DelegatingPhaseListener.java	2010-04-26 12:51:01 UTC (rev 12645)
@@ -21,18 +21,12 @@
  */
 package org.jboss.seam.faces.event;
 
-import java.util.ArrayList;
 import java.util.List;
 
-import javax.enterprise.context.spi.CreationalContext;
-import javax.enterprise.inject.spi.Bean;
-import javax.enterprise.inject.spi.BeanManager;
 import javax.faces.event.PhaseEvent;
 import javax.faces.event.PhaseId;
 import javax.faces.event.PhaseListener;
 
-import org.jboss.weld.extensions.beanManager.BeanManagerAware;
-
 /**
  * Provide CDI injection to PhaseListener artifacts by delegating through this
  * class.
@@ -40,7 +34,7 @@
  * @author <a href="mailto:lincolnbaxter at gmail.com>Lincoln Baxter, III</a>
  * 
  */
-public class DelegatingPhaseListener extends BeanManagerAware implements PhaseListener
+public class DelegatingPhaseListener extends AbstractListener<PhaseListener> implements PhaseListener
 {
    private static final long serialVersionUID = 8454616175394888259L;
 
@@ -83,16 +77,7 @@
    @SuppressWarnings("unchecked")
    private List<PhaseListener> getPhaseListeners()
    {
-      BeanManager manager = getBeanManager();
-      List<PhaseListener> result = new ArrayList<PhaseListener>();
-
-      Bean<PhaseEventBridge> bean = (Bean<PhaseEventBridge>) manager.getBeans(PhaseEventBridge.class).iterator().next();
-      CreationalContext<PhaseEventBridge> context = manager.createCreationalContext(bean);
-      PhaseEventBridge listener = (PhaseEventBridge) manager.getReference(bean, PhaseEventBridge.class, context);
-
-      result.add(listener);
-
-      return result;
+      return getListeners(PhaseEventBridge.class);
    }
 
 }

Modified: modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/event/DelegatingSystemEventListener.java
===================================================================
--- modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/event/DelegatingSystemEventListener.java	2010-04-26 11:35:27 UTC (rev 12644)
+++ modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/event/DelegatingSystemEventListener.java	2010-04-26 12:51:01 UTC (rev 12645)
@@ -21,18 +21,12 @@
  */
 package org.jboss.seam.faces.event;
 
-import java.util.ArrayList;
 import java.util.List;
 
-import javax.enterprise.context.spi.CreationalContext;
-import javax.enterprise.inject.spi.Bean;
-import javax.enterprise.inject.spi.BeanManager;
 import javax.faces.event.AbortProcessingException;
 import javax.faces.event.SystemEvent;
 import javax.faces.event.SystemEventListener;
 
-import org.jboss.weld.extensions.beanManager.BeanManagerAware;
-
 /**
  * Provide CDI injection to SystemEventListener artifacts by delegating through
  * this class.
@@ -40,7 +34,7 @@
  * @author <a href="mailto:lincolnbaxter at gmail.com>Lincoln Baxter, III</a>
  * 
  */
-public class DelegatingSystemEventListener extends BeanManagerAware implements SystemEventListener
+public class DelegatingSystemEventListener extends AbstractListener<SystemEventListener> implements SystemEventListener
 {
 
    public boolean isListenerForSource(final Object source)
@@ -62,20 +56,7 @@
    @SuppressWarnings("unchecked")
    private List<SystemEventListener> getEventListeners()
    {
-      List<SystemEventListener> result = new ArrayList<SystemEventListener>();
-      BeanManager manager = getBeanManager();
-      if (manager == null)
-      {
-         return result;
-      }
-
-      Bean<SystemEventBridge> bean = (Bean<SystemEventBridge>) manager.getBeans(SystemEventBridge.class).iterator().next();
-      CreationalContext<SystemEventBridge> context = manager.createCreationalContext(bean);
-      SystemEventBridge listener = (SystemEventBridge) manager.getReference(bean, SystemEventBridge.class, context);
-
-      result.add(listener);
-
-      return result;
+      return getListeners(SystemEventBridge.class);
    }
 
 }



More information about the seam-commits mailing list