01: package org.objectweb.celtix.configuration.impl;
02:
03: import java.util.ArrayList;
04: import java.util.Collection;
05:
06: import org.objectweb.celtix.configuration.Configuration;
07: import org.objectweb.celtix.configuration.Configurator;
08:
09: /**
10: * REVISIT check if this could be based on javax.swing.TreeNode
11: *
12: */
13: public class ConfiguratorImpl implements Configurator {
14:
15: private final Configuration configuration;
16: private final Configurator hook;
17: private final Collection<Configurator> clients;
18:
19: public ConfiguratorImpl(Configuration c, Configuration parent) {
20: configuration = c;
21: clients = new ArrayList<Configurator>();
22: if (parent instanceof AbstractConfigurationImpl) {
23: hook = ((AbstractConfigurationImpl) parent)
24: .getConfigurator();
25: hook.registerClient(this );
26: } else {
27: hook = null;
28: }
29: }
30:
31: public Configuration getConfiguration() {
32: return configuration;
33: }
34:
35: public Collection<Configurator> getClients() {
36: return clients;
37: }
38:
39: public Configurator getHook() {
40: return hook;
41: }
42:
43: public synchronized void registerClient(Configurator c) {
44: // replace an existing client hook if it has the same namespace and id
45: Object clientId = c.getConfiguration().getId();
46: String clientNamepace = c.getConfiguration().getModel()
47: .getNamespaceURI();
48: for (Configurator client : clients) {
49: if (clientId.equals(client.getConfiguration().getId())
50: && clientNamepace.equals(client.getConfiguration()
51: .getModel().getNamespaceURI())) {
52: clients.remove(client);
53: break;
54: }
55: }
56: clients.add(c);
57: }
58:
59: public void unregisterClient(Configurator c) {
60: clients.remove(c);
61: }
62: }
|