KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.util.List JavaDoc;
27
28 /**
29  * A {@link ConfigurationListener} to manage the status of components,
30  * interfaces and bindings.
31  */

32
33 public class StatusManager implements ConfigurationListener {
34
35   public void rootComponentChanged (final Component oldValue) {
36     // does nothing
37
}
38
39   public void changeCountChanged (Component component, long changeCount) {
40     // does nothing
41
}
42
43   public void nameChanged (final Component component, final String JavaDoc oldValue) {
44     long status = component.getStatus();
45     String JavaDoc name = component.getName();
46     if (name.equals("")) {
47       status |= Component.NAME_MISSING;
48     } else {
49       status &= ~Component.NAME_MISSING;
50     }
51     component.setStatus(status);
52     saysItsModified (component);
53   }
54
55   public void typeChanged (final Component component, final String JavaDoc oldValue) {
56     long status = component.getStatus();
57     String JavaDoc type = component.getType();
58     /*if (type.equals("")) {
59       status |= Component.TYPE_MISSING;
60     } else {
61       status &= ~Component.TYPE_MISSING;
62     }*/

63     component.setStatus(status);
64     saysItsModified (component);
65   }
66
67   public void implementationChanged (
68     final Component component,
69     final String JavaDoc oldValue)
70   {
71     long status = component.getStatus();
72     String JavaDoc implementation = component.getImplementation();
73     if (implementation.equals("")) {
74       if (!component.isComposite()) {
75         status |= Component.IMPLEMENTATION_MISSING;
76       }
77     } else {
78       status &= ~Component.IMPLEMENTATION_MISSING;
79       try {
80         Class.forName(implementation);
81         status &= ~Component.IMPLEMENTATION_CLASS_NOT_FOUND;
82       } catch (ClassNotFoundException JavaDoc e) {
83         status |= Component.IMPLEMENTATION_CLASS_NOT_FOUND;
84       }
85     }
86     component.setStatus(status);
87     saysItsModified (component);
88   }
89
90   public void interfaceNameChanged (final Interface i, final String JavaDoc oldValue) {
91     long status = i.getStatus();
92     String JavaDoc name = i.getName();
93     if (name.equals("")) {
94       status |= Interface.NAME_MISSING;
95     } else {
96       status &= ~Interface.NAME_MISSING;
97     }
98     i.setStatus(status);
99     saysItsModified (i.getOwner());
100   }
101
102   public void interfaceSignatureChanged (
103     final Interface i,
104     final String JavaDoc oldValue)
105   {
106     long status = i.getStatus();
107     String JavaDoc signature = i.getSignature();
108     if (signature.equals("")) {
109       status |= Interface.SIGNATURE_MISSING;
110     } else {
111       status &= ~Interface.SIGNATURE_MISSING;
112       try {
113         Class.forName(signature);
114         status &= ~Interface.SIGNATURE_CLASS_NOT_FOUND;
115       } catch (ClassNotFoundException JavaDoc e) {
116         status |= Interface.SIGNATURE_CLASS_NOT_FOUND;
117       }
118
119       if (i instanceof ClientInterface) {
120         ClientInterface citf = (ClientInterface)i;
121         Binding bd = citf.getBinding();
122         if (bd != null) {
123           ServerInterface sitf = bd.getServerInterface();
124           if (sitf != null) {
125             verifyCompatibility (citf, sitf);
126           }
127         }
128       }
129       else {
130         ServerInterface sitf = (ServerInterface)i;
131         List JavaDoc bindings = sitf.getBindings();
132         for (int z = 0; z < bindings.size(); ++z) {
133           Binding bd = (Binding)bindings.get(z);
134           ClientInterface citf = bd.getClientInterface();
135           if (citf != null) {
136             verifyCompatibility (citf, sitf);
137           }
138         }
139       }
140     }
141     i.setStatus(status);
142     saysItsModified (i.getOwner());
143   }
144
145   public void interfaceContingencyChanged (
146     final Interface i,
147     final boolean oldValue)
148   {
149     saysItsModified (i.getOwner()); // does nothing
150
}
151
152   public void interfaceCardinalityChanged (
153     final Interface i,
154     final boolean oldValue)
155   {
156     saysItsModified (i.getOwner()); // does nothing
157
}
158
159   public void clientInterfaceAdded (
160     final Component component,
161     final ClientInterface i,
162     final int index)
163   {
164     saysItsModified (component); // does nothing
165
}
166
167   public void clientInterfaceRemoved (
168     final Component component,
169     final ClientInterface i,
170     final int index)
171   {
172     saysItsModified (component); // does nothing
173
}
174
175   public void serverInterfaceAdded (
176     final Component component,
177     final ServerInterface i,
178     final int index)
179   {
180     saysItsModified (component); // does nothing
181
}
182
183   public void serverInterfaceRemoved (
184     final Component component,
185     final ServerInterface i,
186     final int index)
187   {
188     saysItsModified (component); // does nothing
189
}
190
191   public void interfaceBound (
192     final ClientInterface citf,
193     final ServerInterface sitf)
194   {
195 /*@@@ */
196     // TODO à deplacer ailleurs (CompletionManager à écrire)
197
String JavaDoc tempo;
198
199     if (citf.getSignature().length() == 0) {
200       tempo = sitf.getSignature();
201       if (tempo.length() != 0) {
202         citf.setSignature(tempo);
203       }
204     }
205     if (sitf.getSignature().length() == 0) {
206       tempo = citf.getSignature();
207       if (tempo.length() != 0) {
208         sitf.setSignature(tempo);
209       }
210     }
211     if (citf.getName().length() == 0) {
212       tempo = sitf.getName();
213       if (tempo.length() != 0) {
214         citf.setName(tempo);
215       }
216     }
217     if (sitf.getName().length() == 0) {
218       tempo = citf.getName();
219       if (tempo.length() != 0) {
220         sitf.setName(tempo);
221       }
222     }
223     verifyCompatibility (citf, sitf);
224     saysItsModified (citf.getOwner());
225 //@@@
226
}
227
228   public void interfaceRebound (
229     final ClientInterface citf,
230     final ServerInterface oldSitf)
231   {
232     // TODO
233
verifyCompatibility (citf, oldSitf);
234     saysItsModified (citf.getOwner());
235   }
236
237   public void interfaceUnbound (
238     final ClientInterface citf,
239     final ServerInterface sitf)
240   {
241     // TODO
242
verifyCompatibility (citf, sitf);
243     saysItsModified (citf.getOwner());
244   }
245
246   public void attributeControllerChanged (
247     final Component component,
248     final String JavaDoc oldValue)
249   {
250     long status = component.getStatus();
251     String JavaDoc attributeController = component.getAttributeController();
252     List JavaDoc attributes = component.getAttributeNames();
253     if (attributeController.equals("")) {
254       if (attributes.size() > 0) {
255         status |= Component.ATTRIBUTE_CONTROLLER_MISSING;
256       }
257     } else {
258       status &= ~Component.ATTRIBUTE_CONTROLLER_MISSING;
259       try {
260         Class.forName(attributeController);
261         status &= ~Component.ATTRIBUTE_CONTROLLER_CLASS_NOT_FOUND;
262       } catch (ClassNotFoundException JavaDoc e) {
263         status |= Component.ATTRIBUTE_CONTROLLER_CLASS_NOT_FOUND;
264       }
265     }
266     component.setStatus(status);
267     saysItsModified (component);
268   }
269
270   public void attributeChanged (
271     final Component component,
272     final String JavaDoc attributeName,
273     final String JavaDoc oldValue)
274   {
275     long status = component.getStatus();
276     String JavaDoc attributeController = component.getAttributeController();
277     List JavaDoc attributes = component.getAttributeNames();
278     if (attributes.size() == 0) {
279       status &= ~Component.ATTRIBUTE_CONTROLLER_MISSING;
280     } else if (attributeController.equals("")) {
281       status |= Component.ATTRIBUTE_CONTROLLER_MISSING;
282     }
283     component.setStatus(status);
284     saysItsModified (component);
285   }
286
287   public void templateControllerDescriptorChanged (
288     final Component component,
289     final String JavaDoc oldValue)
290   {
291     saysItsModified (component); // does nothing
292
}
293
294   public void componentControllerDescriptorChanged (
295     final Component component,
296     final String JavaDoc oldValue)
297   {
298     saysItsModified (component); // does nothing
299
}
300
301   public void subComponentAdded (
302     final Component parent,
303     final Component child,
304     final int index)
305   {
306     long status = parent.getStatus();
307     status &= ~Component.IMPLEMENTATION_MISSING;
308     status &= ~Component.IMPLEMENTATION_CLASS_NOT_FOUND;
309     parent.setStatus(status);
310     saysItsModified (parent);
311   }
312
313   public void subComponentRemoved (
314     final Component parent,
315     final Component child,
316     final int index)
317   {
318     long status = parent.getStatus();
319     List JavaDoc subComponents = parent.getSubComponents();
320     String JavaDoc implementation = parent.getImplementation();
321     if (subComponents.size() == 0 && implementation.equals("")) {
322       status |= Component.IMPLEMENTATION_MISSING;
323     }
324     parent.setStatus(status);
325     saysItsModified (parent);
326   }
327
328   // -------------------------------------------------------------------------
329
// Other methods
330
// -------------------------------------------------------------------------
331

332   private void saysItsModified (Component component) {
333     Configuration cf = component.getConfiguration();
334     if (cf.getRootComponent().contains(component)) {
335       cf.setChangeCount(cf.getChangeCount() + 1);
336     }
337   }
338
339   private void verifyCompatibility (
340     final ClientInterface citf,
341     final ServerInterface sitf)
342   {
343     if (citf == null || sitf == null) {
344       return;
345     }
346     Binding bd = citf.getBinding();
347     if (bd == null) {
348       return;
349     }
350     if ((citf.getSignature().length() > 0) &&
351         (sitf.getSignature().length() > 0))
352     {
353       try {
354         Class JavaDoc c = Class.forName(citf.getSignature());
355         Class JavaDoc s = Class.forName(sitf.getSignature());
356         if (!s.isAssignableFrom(c)) {
357         }
358       } catch (ClassNotFoundException JavaDoc e) {
359         bd.setStatus(Binding.INCOMPATIBLE_TYPE_INTERFACES);
360         return;
361       }
362     }
363     bd.setStatus(Binding.OK);
364   }
365 }
366
Popular Tags