1 16 17 package org.springframework.context.event; 18 19 import java.util.Collection ; 20 21 import org.springframework.beans.BeanUtils; 22 import org.springframework.context.ApplicationListener; 23 import org.springframework.core.CollectionFactory; 24 25 59 public abstract class AbstractApplicationEventMulticaster implements ApplicationEventMulticaster { 60 61 62 private Collection applicationListeners = CollectionFactory.createLinkedSetIfPossible(16); 63 64 65 82 public void setCollectionClass(Class collectionClass) { 83 if (collectionClass == null) { 84 throw new IllegalArgumentException ("collectionClass must not be null"); 85 } 86 if (!Collection .class.isAssignableFrom(collectionClass)) { 87 throw new IllegalArgumentException ("collectionClass must implement [java.util.Collection]"); 88 } 89 Collection newColl = (Collection ) BeanUtils.instantiateClass(collectionClass); 92 newColl.addAll(this.applicationListeners); 93 this.applicationListeners = newColl; 94 } 95 96 97 public void addApplicationListener(ApplicationListener listener) { 98 this.applicationListeners.add(listener); 99 } 100 101 public void removeApplicationListener(ApplicationListener listener) { 102 this.applicationListeners.remove(listener); 103 } 104 105 public void removeAllListeners() { 106 this.applicationListeners.clear(); 107 } 108 109 117 protected Collection getApplicationListeners() { 118 return applicationListeners; 119 } 120 121 } 122 | Popular Tags |