KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > fractal > julia > control > binding > AutoBindingMixin


1 /***
2  * Julia: France Telecom's implementation of the Fractal API
3  * Copyright (C) 2001-2002 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: Eric.Bruneton@rd.francetelecom.com
20  *
21  * Author: Eric Bruneton
22  */

23
24 package org.objectweb.fractal.julia.control.binding;
25
26 import org.objectweb.fractal.api.Component;
27 import org.objectweb.fractal.api.Interface;
28 import org.objectweb.fractal.api.NoSuchInterfaceException;
29 import org.objectweb.fractal.api.control.BindingController;
30 import org.objectweb.fractal.api.control.ContentController;
31 import org.objectweb.fractal.api.control.IllegalBindingException;
32 import org.objectweb.fractal.api.control.IllegalLifeCycleException;
33 import org.objectweb.fractal.api.type.InterfaceType;
34
35 /**
36  * A mixin to simplify the management of collection interfaces with composite
37  * components.
38  * <br>
39  * <br>
40  * <b>Requirements</b>
41  * <ul>
42  * <li>TODO.</li>
43  * </ul>
44  */

45
46 public abstract class AutoBindingMixin {
47   
48   // -------------------------------------------------------------------------
49
// Private constructor
50
// -------------------------------------------------------------------------
51

52   private AutoBindingMixin () {
53   }
54
55   // -------------------------------------------------------------------------
56
// Fields and methods added and overriden by the mixin class
57
// -------------------------------------------------------------------------
58

59   /**
60    * Calls the overriden method, and then creates a corresponding internal
61    * binding, if necessary. This internal binding is created only if the
62    * interface is an external client collection interface "aXXX", and if there
63    * is a "model binding" to the internal server collection interface "a".
64    *
65    * @param clientItfType the type of the <tt>clientItfName</tt> interface.
66    * @param clientItfName the name of a client interface of the component to
67    * which this interface belongs.
68    * @param serverItf a server interface.
69    * @throws NoSuchInterfaceException if there is no such client interface.
70    * @throws IllegalBindingException if the binding cannot be created.
71    * @throws IllegalLifeCycleException if this component has a {@link
72    * org.objectweb.fractal.api.control.LifeCycleController} interface, but
73    * it is not in an appropriate state to perform this operation.
74    */

75
76   public void bindFc (
77     final InterfaceType clientItfType,
78     final String JavaDoc clientItfName,
79     final Object JavaDoc serverItf)
80     throws
81     NoSuchInterfaceException,
82     IllegalBindingException,
83     IllegalLifeCycleException
84   {
85     _super_bindFc(clientItfType, clientItfName, serverItf);
86     if (clientItfType.isFcCollectionItf()) {
87       String JavaDoc sItfName = clientItfType.getFcItfName();
88       ContentController cc;
89       try {
90         cc = (ContentController)_this_weaveableC.getFcInterface("content-controller");
91       } catch (NoSuchInterfaceException e) {
92         cc = null;
93       }
94       if (cc != null && !clientItfName.equals(sItfName)) {
95         Object JavaDoc sItf = cc.getFcInternalInterface(sItfName);
96         Object JavaDoc itf = cc.getFcInternalInterface(clientItfName);
97         try {
98           Object JavaDoc[] itfs = Util.getFcClientItfsBoundTo((Interface)sItf).toArray();
99           for (int i = 0; i < itfs.length; ++i) {
100             Interface cItf = (Interface)itfs[i];
101             InterfaceType cItfType = (InterfaceType)cItf.getFcItfType();
102             if (cItfType.isFcCollectionItf()) {
103               Component c = cItf.getFcItfOwner();
104               BindingController bc =
105                 (BindingController)c.getFcInterface("binding-controller");
106               String JavaDoc s =
107                 cItfType.getFcItfName() + clientItfName.substring(sItfName.length());
108               bc.bindFc(s, itf);
109             }
110           }
111         } catch (Exception JavaDoc e) {
112           throw new ChainedIllegalBindingException(
113             e, _this_weaveableC, null, clientItfName, null,
114             "Error during automatic creation of bindings from the model binding");
115         }
116       }
117       if (clientItfName.equals(sItfName)) {
118         Interface sItf = (Interface)serverItf;
119         InterfaceType sItfType = (InterfaceType)sItf.getFcItfType();
120         if (sItf.isFcInternalItf() &&
121             sItfType.isFcCollectionItf() &&
122             sItf.getFcItfName().equals(sItfType.getFcItfName()))
123         {
124           Component sComp = sItf.getFcItfOwner();
125           try {
126             BindingController bc =
127               (BindingController)sComp.getFcInterface("binding-controller");
128             cc =
129               (ContentController)sComp.getFcInterface("content-controller");
130             String JavaDoc s = sItf.getFcItfName();
131             String JavaDoc[] itfs = bc.listFc();
132             for (int i = 0; i < itfs.length; ++i) {
133               if (itfs[i].length() > s.length() && itfs[i].startsWith(s)) {
134                 _this_bindFc(
135                   clientItfName + itfs[i].substring(s.length()),
136                   cc.getFcInternalInterface(itfs[i]));
137               }
138             }
139           } catch (Exception JavaDoc e) {
140             throw new ChainedIllegalBindingException(
141               e, _this_weaveableC, null, clientItfName, null,
142               "Error during automatic creation of bindings from the model binding");
143           }
144         }
145       }
146     }
147   }
148
149   /**
150    * Calls the overriden method, and then removes the corresponding internal
151    * bindings, if necessary. This internal binding is removed only if the
152    * interface is an external client collection interface "aXXX", and if there
153    * is a "model binding" to the internal server collection interface "a".
154    * @param clientItfType the type of the <tt>clientItfName</tt> interface.
155    * @param clientItfName the name of a client interface of the component to
156    * which this interface belongs.
157    * @throws NoSuchInterfaceException if there is no such client interface.
158    * @throws IllegalBindingException if the binding cannot be removed.
159    * @throws IllegalLifeCycleException if this component has a {@link
160    * org.objectweb.fractal.api.control.LifeCycleController} interface, but
161    * it is not in an appropriate state to perform this operation.
162    */

163
164   public void unbindFc (
165     final InterfaceType clientItfType,
166     final String JavaDoc clientItfName)
167     throws
168     NoSuchInterfaceException,
169     IllegalBindingException,
170     IllegalLifeCycleException
171   {
172     _super_unbindFc(clientItfType, clientItfName);
173     if (clientItfType.isFcCollectionItf()) {
174       ContentController cc;
175       try {
176         cc = (ContentController)_this_weaveableC.getFcInterface("content-controller");
177       } catch (NoSuchInterfaceException e) {
178         return;
179       }
180       String JavaDoc sItfName = clientItfType.getFcItfName();
181       Object JavaDoc sItf = cc.getFcInternalInterface(sItfName);
182       try {
183         Object JavaDoc[] itfs = Util.getFcClientItfsBoundTo((Interface)sItf).toArray();
184         for (int i = 0; i < itfs.length; ++i) {
185           Interface cItf = (Interface)itfs[i];
186           InterfaceType cItfType = (InterfaceType)cItf.getFcItfType();
187           if (cItfType.isFcCollectionItf()) {
188             Component c = cItf.getFcItfOwner();
189             BindingController bc =
190               (BindingController)c.getFcInterface("binding-controller");
191             String JavaDoc s =
192               cItfType.getFcItfName() + clientItfName.substring(sItfName.length());
193             bc.unbindFc(s);
194           }
195         }
196       } catch (Exception JavaDoc e) {
197         throw new ChainedIllegalBindingException(
198           e, _this_weaveableC, null, clientItfName, null,
199           "Error during automatic destruction of bindings from the model binding");
200       }
201     }
202   }
203   
204   // -------------------------------------------------------------------------
205
// Fields and methods required by the mixin class in the base class
206
// -------------------------------------------------------------------------
207

208   /**
209    * The <tt>weaveableC</tt> field required by this mixin. This field is
210    * supposed to reference the {@link Component} interface of the component to
211    * which this controller object belongs.
212    */

213
214   public Component _this_weaveableC;
215
216   /**
217    * The {@link BindingController#bindFc bindFc} method required by this mixin.
218    *
219    * @param clientItfName the name of a client interface of the component to
220    * which this interface belongs.
221    * @param serverItf a server interface.
222    * @throws NoSuchInterfaceException if there is no such client interface.
223    * @throws IllegalBindingException if the binding cannot be created.
224    * @throws IllegalLifeCycleException if this component has a {@link
225    * LifeCycleController} interface, but it is not in an appropriate state
226    * to perform this operation.
227    */

228
229   public abstract void _this_bindFc (String JavaDoc clientItfName, Object JavaDoc serverItf) throws
230     NoSuchInterfaceException,
231     IllegalBindingException,
232     IllegalLifeCycleException;
233
234   /**
235    * The {@link TypeBindingMixin#bindFc(InterfaceType,String,Object) bindFc}
236    * method overriden by this mixin.
237    *
238    * @param clientItfType the type of the <tt>clientItfName</tt> interface.
239    * @param clientItfName the name of a client interface of the component to
240    * which this interface belongs.
241    * @param serverItf a server interface.
242    * @throws NoSuchInterfaceException if there is no such client interface.
243    * @throws IllegalBindingException if the binding cannot be created.
244    * @throws IllegalLifeCycleException if this component has a {@link
245    * org.objectweb.fractal.api.control.LifeCycleController} interface, but
246    * it is not in an appropriate state to perform this operation.
247    */

248
249   public abstract void _super_bindFc (
250     InterfaceType clientItfType,
251     String JavaDoc clientItfName,
252     Object JavaDoc serverItf)
253     throws
254     NoSuchInterfaceException,
255     IllegalBindingException,
256     IllegalLifeCycleException;
257
258   /**
259    * The {@link TypeBindingMixin#unbindFc(InterfaceType,String) unbindFc}
260    * method overriden by this mixin.
261    *
262    * @param clientItfType the type of the <tt>clientItfName</tt> interface.
263    * @param clientItfName the name of a client interface of the component to
264    * which this interface belongs.
265    * @throws NoSuchInterfaceException if there is no such client interface.
266    * @throws IllegalBindingException if the binding cannot be removed.
267    * @throws IllegalLifeCycleException if this component has a {@link
268    * org.objectweb.fractal.api.control.LifeCycleController} interface, but
269    * it is not in an appropriate state to perform this operation.
270    */

271
272   public abstract void _super_unbindFc (
273     InterfaceType clientItfType,
274     String JavaDoc clientItfName)
275     throws
276     NoSuchInterfaceException,
277     IllegalBindingException,
278     IllegalLifeCycleException;
279 }
280
Popular Tags