KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > celtix > configuration > impl > ConfiguratorImpl


1 package org.objectweb.celtix.configuration.impl;
2
3 import java.util.ArrayList JavaDoc;
4 import java.util.Collection JavaDoc;
5
6 import org.objectweb.celtix.configuration.Configuration;
7 import org.objectweb.celtix.configuration.Configurator;
8
9
10 /**
11  * REVISIT check if this could be based on javax.swing.TreeNode
12  *
13  */

14 public class ConfiguratorImpl implements Configurator {
15     
16     private final Configuration configuration;
17     private final Configurator hook;
18     private final Collection JavaDoc<Configurator> clients;
19     
20     public ConfiguratorImpl(Configuration c, Configuration parent) {
21         configuration = c;
22         clients = new ArrayList JavaDoc<Configurator>();
23         if (parent instanceof AbstractConfigurationImpl) {
24             hook = ((AbstractConfigurationImpl)parent).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 JavaDoc<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 JavaDoc clientId = c.getConfiguration().getId();
46         String JavaDoc clientNamepace = c.getConfiguration().getModel().getNamespaceURI();
47         for (Configurator client : clients) {
48             if (clientId.equals(client.getConfiguration().getId())
49                 && clientNamepace.equals(client.getConfiguration().getModel().getNamespaceURI())) {
50                 clients.remove(client);
51                 break;
52             }
53         }
54         clients.add(c);
55     }
56     public void unregisterClient(Configurator c) {
57         clients.remove(c);
58     }
59 }
60
Popular Tags