KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > config > schema > listen > ConfigurationChangeListenerSet


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package com.tc.config.schema.listen;
5
6 import org.apache.xmlbeans.XmlObject;
7
8 import com.tc.util.Assert;
9
10 import java.util.HashSet JavaDoc;
11 import java.util.Iterator JavaDoc;
12 import java.util.Set JavaDoc;
13
14 /**
15  * A set of {@link ConfigurationChangeListener}s.
16  */

17 public class ConfigurationChangeListenerSet implements ConfigurationChangeListener {
18
19   // This must be declared as a HashSet, not just a Set, so that we can clone it (below).
20
private final HashSet JavaDoc changeListeners;
21
22   public ConfigurationChangeListenerSet() {
23     this.changeListeners = new HashSet JavaDoc();
24   }
25
26   public synchronized void addListener(ConfigurationChangeListener listener) {
27     Assert.assertNotNull(listener);
28     this.changeListeners.add(listener);
29   }
30
31   public synchronized void removeListener(ConfigurationChangeListener listener) {
32     Assert.assertNotNull(listener);
33     this.changeListeners.remove(listener);
34   }
35
36   public void configurationChanged(XmlObject oldConfig, XmlObject newConfig) {
37     Set JavaDoc dup;
38
39     synchronized (this) {
40       dup = (Set JavaDoc) this.changeListeners.clone();
41     }
42
43     Iterator JavaDoc iter = dup.iterator();
44     while (iter.hasNext()) {
45       ((ConfigurationChangeListener) iter.next()).configurationChanged(oldConfig, newConfig);
46     }
47   }
48
49 }
50
Popular Tags