01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */
04: package com.tc.config.schema.listen;
05:
06: import org.apache.xmlbeans.XmlObject;
07:
08: import com.tc.util.Assert;
09:
10: import java.util.HashSet;
11: import java.util.Iterator;
12: import java.util.Set;
13:
14: /**
15: * A set of {@link ConfigurationChangeListener}s.
16: */
17: public class ConfigurationChangeListenerSet implements
18: ConfigurationChangeListener {
19:
20: // This must be declared as a HashSet, not just a Set, so that we can clone it (below).
21: private final HashSet changeListeners;
22:
23: public ConfigurationChangeListenerSet() {
24: this .changeListeners = new HashSet();
25: }
26:
27: public synchronized void addListener(
28: ConfigurationChangeListener listener) {
29: Assert.assertNotNull(listener);
30: this .changeListeners.add(listener);
31: }
32:
33: public synchronized void removeListener(
34: ConfigurationChangeListener listener) {
35: Assert.assertNotNull(listener);
36: this .changeListeners.remove(listener);
37: }
38:
39: public void configurationChanged(XmlObject oldConfig,
40: XmlObject newConfig) {
41: Set dup;
42:
43: synchronized (this ) {
44: dup = (Set) this .changeListeners.clone();
45: }
46:
47: Iterator iter = dup.iterator();
48: while (iter.hasNext()) {
49: ((ConfigurationChangeListener) iter.next())
50: .configurationChanged(oldConfig, newConfig);
51: }
52: }
53:
54: }
|