KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > fractal > gui > model > DerivedConfiguration


1 /***
2  * FractalGUI: a graphical tool to edit Fractal component configurations.
3  * Copyright (C) 2003 France Telecom R&D
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  * Contact: fractal@objectweb.org
20  *
21  * Authors: Eric Bruneton, Patrice Fauvel
22  */

23
24 package org.objectweb.fractal.gui.model;
25
26 import org.objectweb.fractal.api.control.BindingController;
27
28 import java.util.Map JavaDoc;
29 import java.util.HashMap JavaDoc;
30 import java.util.Iterator JavaDoc;
31
32 /**
33  * A sub {@link Configuration} of another {@link Configuration}. The root
34  * component of this configuration is just a reference to a sub component of the
35  * root component of a master configuration. This configuration listens to the
36  * master configuration, and forwards to its own listeners the notifications
37  * that concern the sub components of its own root component.
38  */

39
40 public class DerivedConfiguration implements
41   Configuration,
42   ConfigurationListener,
43   BindingController
44 {
45
46   /**
47    * A mandatory client interface bound to the master configuration.
48    */

49
50   public final static String JavaDoc CONFIGURATION_BINDING = "configuration";
51
52   /**
53    * A collection client interface bound to the {@link ConfigurationListener
54    * listeners} of this model.
55    */

56
57   public final static String JavaDoc CONFIGURATION_LISTENERS_BINDING =
58     "configuration-listeners";
59
60   /**
61    * The configuration from which this configuration derives.
62    */

63
64   private Configuration configuration;
65
66   /**
67    * The listeners client interface.
68    */

69
70   private Map JavaDoc listeners;
71
72   /**
73    * The root component of this configuration. This component is a component of
74    * the master configuration.
75    */

76
77   private Component root;
78
79   /**
80    * Status of this configuration.
81    */

82
83   private long changeCount;
84
85   /**
86    * Constructs a new {@link DerivedConfiguration} component.
87    */

88
89   public DerivedConfiguration () {
90     root = new BasicComponent(null); // TODO
91
listeners = new HashMap JavaDoc();
92   }
93
94   // -------------------------------------------------------------------------
95
// Implementation of the BindingController interface
96
// -------------------------------------------------------------------------
97

98   public String JavaDoc[] listFc () {
99     int size = listeners.size();
100     String JavaDoc[] names = new String JavaDoc[size + 1];
101     listeners.keySet().toArray(names);
102     names[size] = CONFIGURATION_BINDING;
103     return names;
104   }
105
106   public Object JavaDoc lookupFc (final String JavaDoc clientItfName) {
107     if (CONFIGURATION_BINDING.equals(clientItfName)) {
108       return configuration;
109     } else if (clientItfName.startsWith(CONFIGURATION_LISTENERS_BINDING)) {
110       return listeners.get(clientItfName);
111     }
112     return null;
113   }
114
115   public void bindFc (
116     final String JavaDoc clientItfName,
117     final Object JavaDoc serverItf)
118   {
119     if (CONFIGURATION_BINDING.equals(clientItfName)) {
120       configuration = (Configuration)serverItf;
121     } else if (clientItfName.startsWith(CONFIGURATION_LISTENERS_BINDING)) {
122       listeners.put(clientItfName, serverItf);
123     }
124   }
125
126   public void unbindFc (final String JavaDoc clientItfName) {
127     if (CONFIGURATION_BINDING.equals(clientItfName)) {
128       configuration = null;
129     } else if (clientItfName.startsWith(CONFIGURATION_LISTENERS_BINDING)) {
130       listeners.remove(clientItfName);
131     }
132   }
133
134   // -------------------------------------------------------------------------
135
// Implementation of the Configuration interface
136
// -------------------------------------------------------------------------
137

138   public Component getRootComponent () {
139     return root;
140   }
141
142   public void setRootComponent (final Component root) {
143     Component oldRoot = this.root;
144     if (root != oldRoot) {
145       this.root = root;
146       Iterator JavaDoc i = listeners.values().iterator();
147       while (i.hasNext()) {
148         ConfigurationListener l = (ConfigurationListener)i.next();
149         l.rootComponentChanged(oldRoot);
150       }
151     }
152   }
153
154   public long getChangeCount () {
155     return changeCount;
156   }
157
158   public void setChangeCount (long changeCount) {
159     this.changeCount = changeCount;
160     Iterator JavaDoc i = listeners.values().iterator();
161     while (i.hasNext()) {
162       ConfigurationListener l = (ConfigurationListener)i.next();
163       l.changeCountChanged(getRootComponent(), changeCount);
164     }
165   }
166
167
168   public String JavaDoc getStorage () {
169     return configuration.getStorage();
170   }
171
172   public void setStorage (String JavaDoc storage) {
173     configuration.setStorage(storage);
174   }
175
176   // -------------------------------------------------------------------------
177
// Implementation of the ConfigurationListener interface
178
// -------------------------------------------------------------------------
179

180   public void changeCountChanged (Component component, long changeCount)
181   {
182     // does nothing
183
}
184
185   public void rootComponentChanged (final Component oldValue) {
186     root = configuration.getRootComponent();
187     Iterator JavaDoc i = listeners.values().iterator();
188     while (i.hasNext()) {
189       ConfigurationListener l = (ConfigurationListener)i.next();
190       l.rootComponentChanged(oldValue);
191     }
192   }
193
194   public void nameChanged (final Component component, final String JavaDoc oldValue) {
195     if (root.contains(component)) {
196       Iterator JavaDoc i = listeners.values().iterator();
197       while (i.hasNext()) {
198         ConfigurationListener l = (ConfigurationListener)i.next();
199         l.nameChanged(component, oldValue);
200       }
201     }
202   }
203
204   public void typeChanged (final Component component, final String JavaDoc oldValue) {
205     if (root.contains(component)) {
206       Iterator JavaDoc i = listeners.values().iterator();
207       while (i.hasNext()) {
208         ConfigurationListener l = (ConfigurationListener)i.next();
209         l.typeChanged(component, oldValue);
210       }
211     }
212   }
213
214   public void implementationChanged (
215     final Component component,
216     final String JavaDoc oldValue)
217   {
218     if (root.contains(component)) {
219       Iterator JavaDoc i = listeners.values().iterator();
220       while (i.hasNext()) {
221         ConfigurationListener l = (ConfigurationListener)i.next();
222         l.implementationChanged(component, oldValue);
223       }
224     }
225   }
226
227   public void interfaceNameChanged (final Interface i, final String JavaDoc oldValue) {
228     if (root.contains(i.getOwner())) {
229       Iterator JavaDoc j = listeners.values().iterator();
230       while (j.hasNext()) {
231         ConfigurationListener l = (ConfigurationListener)j.next();
232         l.interfaceNameChanged(i, oldValue);
233       }
234     }
235   }
236
237   public void interfaceSignatureChanged (
238     final Interface i,
239     final String JavaDoc oldValue)
240   {
241     if (root.contains(i.getOwner())) {
242       Iterator JavaDoc j = listeners.values().iterator();
243       while (j.hasNext()) {
244         ConfigurationListener l = (ConfigurationListener)j.next();
245         l.interfaceSignatureChanged(i, oldValue);
246       }
247     }
248   }
249
250   public void interfaceContingencyChanged (
251     final Interface i, final boolean oldValue)
252   {
253     if (root.contains(i.getOwner())) {
254       Iterator JavaDoc j = listeners.values().iterator();
255       while (j.hasNext()) {
256         ConfigurationListener l = (ConfigurationListener)j.next();
257         l.interfaceContingencyChanged(i, oldValue);
258       }
259     }
260   }
261
262   public void interfaceCardinalityChanged (
263     final Interface i,
264     final boolean oldValue)
265   {
266     if (root.contains(i.getOwner())) {
267       Iterator JavaDoc j = listeners.values().iterator();
268       while (j.hasNext()) {
269         ConfigurationListener l = (ConfigurationListener)j.next();
270         l.interfaceCardinalityChanged(i, oldValue);
271       }
272     }
273   }
274
275   public void clientInterfaceAdded (
276     final Component component,
277     final ClientInterface i,
278     final int index)
279   {
280     if (root.contains(component)) {
281       Iterator JavaDoc j = listeners.values().iterator();
282       while (j.hasNext()) {
283         ConfigurationListener l = (ConfigurationListener)j.next();
284         l.clientInterfaceAdded(component, i, index);
285       }
286     }
287   }
288
289   public void clientInterfaceRemoved (
290     final Component component,
291     final ClientInterface i,
292     final int index)
293   {
294     if (root.contains(component)) {
295       Iterator JavaDoc j = listeners.values().iterator();
296       while (j.hasNext()) {
297         ConfigurationListener l = (ConfigurationListener)j.next();
298         l.clientInterfaceRemoved(component, i, index);
299       }
300     }
301   }
302
303   public void serverInterfaceAdded (
304     final Component component,
305     final ServerInterface i,
306     final int index)
307   {
308     if (root.contains(component)) {
309       Iterator JavaDoc j = listeners.values().iterator();
310       while (j.hasNext()) {
311         ConfigurationListener l = (ConfigurationListener)j.next();
312         l.serverInterfaceAdded(component, i, index);
313       }
314     }
315   }
316
317   public void serverInterfaceRemoved (
318     final Component component,
319     final ServerInterface i,
320     final int index)
321   {
322     if (root.contains(component)) {
323       Iterator JavaDoc j = listeners.values().iterator();
324       while (j.hasNext()) {
325         ConfigurationListener l = (ConfigurationListener)j.next();
326         l.serverInterfaceRemoved(component, i, index);
327       }
328     }
329   }
330
331   public void interfaceBound (
332     final ClientInterface citf,
333     final ServerInterface sitf)
334   {
335     if (root.contains(citf.getOwner())) {
336       Iterator JavaDoc i = listeners.values().iterator();
337       while (i.hasNext()) {
338         ConfigurationListener l = (ConfigurationListener)i.next();
339         l.interfaceBound(citf, sitf);
340       }
341     }
342   }
343
344   public void interfaceRebound (
345     final ClientInterface citf,
346     final ServerInterface oldSitf)
347   {
348     if (root.contains(citf.getOwner())) {
349       Iterator JavaDoc i = listeners.values().iterator();
350       while (i.hasNext()) {
351         ConfigurationListener l = (ConfigurationListener)i.next();
352         l.interfaceRebound(citf, oldSitf);
353       }
354     }
355   }
356
357   public void interfaceUnbound (
358     final ClientInterface citf,
359     final ServerInterface sitf)
360   {
361     if (root.contains(citf.getOwner())) {
362       Iterator JavaDoc i = listeners.values().iterator();
363       while (i.hasNext()) {
364         ConfigurationListener l = (ConfigurationListener)i.next();
365         l.interfaceUnbound(citf, sitf);
366       }
367     }
368   }
369
370   public void attributeControllerChanged (
371     final Component component,
372     final String JavaDoc oldValue)
373   {
374     if (root.contains(component)) {
375       Iterator JavaDoc i = listeners.values().iterator();
376       while (i.hasNext()) {
377         ConfigurationListener l = (ConfigurationListener)i.next();
378         l.attributeControllerChanged(component, oldValue);
379       }
380     }
381   }
382
383   public void attributeChanged (
384     final Component component,
385     final String JavaDoc attributeName,
386     final String JavaDoc oldValue)
387   {
388     if (root.contains(component)) {
389       Iterator JavaDoc i = listeners.values().iterator();
390       while (i.hasNext()) {
391         ConfigurationListener l = (ConfigurationListener)i.next();
392         l.attributeChanged(component, attributeName, oldValue);
393       }
394     }
395   }
396
397   public void templateControllerDescriptorChanged (
398     final Component component,
399     final String JavaDoc oldValue)
400   {
401     if (root.contains(component)) {
402       Iterator JavaDoc i = listeners.values().iterator();
403       while (i.hasNext()) {
404         ConfigurationListener l = (ConfigurationListener)i.next();
405         l.templateControllerDescriptorChanged(component, oldValue);
406       }
407     }
408   }
409
410   public void componentControllerDescriptorChanged (
411     final Component component,
412     final String JavaDoc oldValue)
413   {
414     if (root.contains(component)) {
415       Iterator JavaDoc i = listeners.values().iterator();
416       while (i.hasNext()) {
417         ConfigurationListener l = (ConfigurationListener)i.next();
418         l.componentControllerDescriptorChanged(component, oldValue);
419       }
420     }
421   }
422
423   public void subComponentAdded (
424     final Component parent,
425     final Component child,
426     final int index)
427   {
428     if (root.contains(parent)) {
429       Iterator JavaDoc i = listeners.values().iterator();
430       while (i.hasNext()) {
431         ConfigurationListener l = (ConfigurationListener)i.next();
432         l.subComponentAdded(parent, child, index);
433       }
434     }
435   }
436
437   public void subComponentRemoved (
438     final Component parent,
439     final Component child,
440     final int index)
441   {
442     if (root.contains(parent)) {
443       Iterator JavaDoc i = listeners.values().iterator();
444       while (i.hasNext()) {
445         ConfigurationListener l = (ConfigurationListener)i.next();
446         l.subComponentRemoved(parent, child, index);
447       }
448     }
449   }
450 }
451
Popular Tags