1 4 package com.tc.config.schema.dynamic; 5 6 import com.tc.util.Assert; 7 8 import java.util.HashSet ; 9 import java.util.Set ; 10 11 14 public class CompoundConfigItemListener implements ConfigItemListener { 15 16 private final Set listeners; 17 18 public CompoundConfigItemListener() { 19 this.listeners = new HashSet (); 20 } 21 22 public synchronized void addListener(ConfigItemListener listener) { 23 Assert.assertNotNull(listener); 24 this.listeners.add(listener); 25 } 26 27 public synchronized void removeListener(ConfigItemListener listener) { 28 Assert.assertNotNull(listener); 29 this.listeners.remove(listener); 30 } 31 32 public void valueChanged(Object oldValue, Object newValue) { 33 ConfigItemListener[] duplicate; 34 35 synchronized (this) { 36 duplicate = (ConfigItemListener[]) this.listeners.toArray(new ConfigItemListener[this.listeners.size()]); 37 } 38 39 for (int i = 0; i < duplicate.length; ++i) { 40 duplicate[i].valueChanged(oldValue, newValue); 41 } 42 } 43 44 } 45 | Popular Tags |