KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > config > schema > dynamic > CompoundConfigItemListener


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.dynamic;
5
6 import com.tc.util.Assert;
7
8 import java.util.HashSet JavaDoc;
9 import java.util.Set JavaDoc;
10
11 /**
12  * A {@link ConfigItemListener} that simply delegates to others.
13  */

14 public class CompoundConfigItemListener implements ConfigItemListener {
15
16   private final Set JavaDoc listeners;
17
18   public CompoundConfigItemListener() {
19     this.listeners = new HashSet JavaDoc();
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 JavaDoc oldValue, Object JavaDoc 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