1 22 package org.jboss.kernel.plugins.event; 23 24 import org.jboss.kernel.Kernel; 25 import org.jboss.kernel.plugins.AbstractKernelObject; 26 import org.jboss.kernel.spi.event.KernelEventEmitter; 27 import org.jboss.kernel.spi.event.KernelEventFilter; 28 import org.jboss.kernel.spi.event.KernelEventListener; 29 import org.jboss.kernel.spi.event.KernelEventManager; 30 import org.jboss.kernel.spi.registry.KernelRegistry; 31 import org.jboss.kernel.spi.registry.KernelRegistryEntry; 32 33 39 public class AbstractEventManager extends AbstractKernelObject implements KernelEventManager 40 { 41 42 protected KernelRegistry registry; 43 44 49 public AbstractEventManager() throws Throwable 50 { 51 } 52 53 public void setKernel(Kernel kernel) throws Throwable 54 { 55 super.setKernel(kernel); 56 registry = kernel.getRegistry(); 57 } 58 59 public void registerListener(Object name, KernelEventListener listener, KernelEventFilter filter, Object handback) throws Throwable 60 { 61 getEmitter(name).registerListener(listener, filter, handback); 62 } 63 64 public void unregisterListener(Object name, KernelEventListener listener, KernelEventFilter filter, Object handback) throws Throwable 65 { 66 getEmitter(name).unregisterListener(listener, filter, handback); 67 } 68 69 protected KernelEventEmitter getEmitter(Object name) throws Throwable 70 { 71 KernelRegistryEntry entry = registry.getEntry(name); 72 73 Object object = entry.getTarget(); 74 if (object == null || object instanceof KernelEventEmitter == false) 75 throw new ClassCastException (name + " is not a " + KernelEventEmitter.class.getName()); 76 77 return (KernelEventEmitter) object; 78 } 79 } 80 | Popular Tags |