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.dynamic;
05:
06: import com.tc.util.Assert;
07:
08: import java.util.HashSet;
09: import java.util.Set;
10:
11: /**
12: * A {@link ConfigItemListener} that simply delegates to others.
13: */
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
37: .toArray(new ConfigItemListener[this .listeners
38: .size()]);
39: }
40:
41: for (int i = 0; i < duplicate.length; ++i) {
42: duplicate[i].valueChanged(oldValue, newValue);
43: }
44: }
45:
46: }
|