KickJava   Java API By Example, From Geeks To Geeks.

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


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.NoSuchInterfaceException;
28 import org.objectweb.fractal.api.control.BindingController;
29 import org.objectweb.fractal.api.control.IllegalBindingException;
30 import org.objectweb.fractal.api.control.IllegalLifeCycleException;
31
32 import org.objectweb.fractal.julia.ComponentInterface;
33 import org.objectweb.fractal.julia.Interceptor;
34
35 /**
36  * Provides output interceptors management to a {@link BindingController}. This
37  * mixin is only useful for the {@link ContainerBindingControllerMixin}, since
38  * the {@link CompositeBindingMixin} and the {@link OptimizedCompositeBindingMixin}
39  * already manage interceptors.
40  * <br>
41  * <br>
42  * <b>Requirements</b>
43  * <ul>
44  * <li>the component to which this controller object belongs must provide the
45  * {@link Component} interface. Moreover this mixin does nothing if the
46  * component does not provide interface introspection functions.</li>
47  * </ul>
48  */

49
50 public abstract class InterceptorBindingMixin implements BindingController {
51
52   // -------------------------------------------------------------------------
53
// Private constructor
54
// -------------------------------------------------------------------------
55

56   private InterceptorBindingMixin () {
57   }
58
59   // -------------------------------------------------------------------------
60
// Fields and methods added and overriden by the mixin class
61
// -------------------------------------------------------------------------
62

63   /**
64    * Calls the overriden method and returns the corresponding {@link
65    * Interceptor#getFcItfDelegate getFcItfDelegate} (if the result is an {@link
66    * Interceptor}).
67    *
68    * @param clientItfName the name of a client interface of the component to
69    * which this interface belongs.
70    * @return the server interface to which the given interface is bound, or <tt>
71    * null</tt> if it is not bound.
72    * @throws NoSuchInterfaceException if the component to which this interface
73    * belongs does not have a client interface whose name is equal to the
74    * given name.
75    */

76
77   public Object JavaDoc lookupFc (final String JavaDoc clientItfName)
78     throws NoSuchInterfaceException
79   {
80     Object JavaDoc o = _super_lookupFc(clientItfName);
81     if (o instanceof Interceptor) {
82       // skips the output interceptor, if there is one
83
o = ((Interceptor)o).getFcItfDelegate();
84     }
85     return o;
86   }
87
88   /**
89    * Gets the interceptor of the given client interface, updates its {@link
90    * Interceptor#getFcItfDelegate getFcItfDelegate}, and then calls the
91    * overriden method with the interceptor as server interface (if there is
92    * an interceptor for the client interface).
93    *
94    * @param clientItfName the name of a client interface of the component to
95    * which this interface belongs.
96    * @param serverItf a server interface.
97    * @throws NoSuchInterfaceException if there is no such client interface.
98    * @throws IllegalBindingException if the binding cannot be created.
99    * @throws IllegalLifeCycleException if this component has a {@link
100    * LifeCycleController} interface, but it is not in an appropriate state
101    * to perform this operation.
102    */

103
104   public void bindFc (final String JavaDoc clientItfName, final Object JavaDoc serverItf) throws
105     NoSuchInterfaceException,
106     IllegalBindingException,
107     IllegalLifeCycleException
108   {
109     Object JavaDoc o = _this_weaveableC.getFcInterface(clientItfName);
110     if (o instanceof ComponentInterface) {
111       o = ((ComponentInterface)o).getFcItfImpl();
112       if (o instanceof Interceptor) {
113         ((Interceptor)o).setFcItfDelegate(serverItf);
114       } else {
115         o = serverItf;
116       }
117     } else {
118       o = serverItf;
119     }
120     _super_bindFc(clientItfName, o);
121   }
122
123   /**
124    * Gets the interceptor of the given client interface, updates its {@link
125    * Interceptor#getFcItfDelegate getFcItfDelegate}, and then calls the
126    * overriden method (if there is an interceptor for the client interface).
127    *
128    * @param clientItfName the name of a client interface of the component to
129    * which this interface belongs.
130    * @throws NoSuchInterfaceException if there is no such client interface.
131    * @throws IllegalBindingException if the binding cannot be removed.
132    * @throws IllegalLifeCycleException if this component has a {@link
133    * LifeCycleController} interface, but it is not in an appropriate state
134    * to perform this operation.
135    */

136
137   public void unbindFc (final String JavaDoc clientItfName) throws
138     NoSuchInterfaceException,
139     IllegalBindingException,
140     IllegalLifeCycleException
141   {
142     Object JavaDoc o = _this_weaveableC.getFcInterface(clientItfName);
143     if (o instanceof ComponentInterface) {
144       o = ((ComponentInterface)o).getFcItfImpl();
145       if (o instanceof Interceptor) {
146         ((Interceptor)o).setFcItfDelegate(null);
147       }
148     }
149     _super_unbindFc(clientItfName);
150   }
151
152   // -------------------------------------------------------------------------
153
// Fields and methods required by the mixin class in the base class
154
// -------------------------------------------------------------------------
155

156   /**
157    * The <tt>weaveableC</tt> field required by this mixin. This field is
158    * supposed to reference the {@link Component} interface of the component to
159    * which this controller object belongs.
160    */

161
162   public Component _this_weaveableC;
163
164   /**
165    * The {@link BindingController#lookupFc lookupFc} method overriden by this
166    * mixin.
167    *
168    * @param clientItfName the name of a client interface of the component to
169    * which this interface belongs.
170    * @return the server interface to which the given interface is bound, or <tt>
171    * null</tt> if it is not bound.
172    * @throws NoSuchInterfaceException if the component to which this interface
173    * belongs does not have a client interface whose name is equal to the
174    * given name.
175    */

176
177   public abstract Object JavaDoc _super_lookupFc (String JavaDoc clientItfName) throws
178     NoSuchInterfaceException;
179
180   /**
181    * The {@link BindingController#bindFc bindFc} method overriden by this mixin.
182    *
183    * @param clientItfName the name of a client interface of the component to
184    * which this interface belongs.
185    * @param serverItf a server interface.
186    * @throws NoSuchInterfaceException if there is no such client interface.
187    * @throws IllegalBindingException if the binding cannot be created.
188    * @throws IllegalLifeCycleException if this component has a {@link
189    * LifeCycleController} interface, but it is not in an appropriate state
190    * to perform this operation.
191    */

192
193   public abstract void _super_bindFc (String JavaDoc clientItfName, Object JavaDoc serverItf) throws
194     NoSuchInterfaceException,
195     IllegalBindingException,
196     IllegalLifeCycleException;
197
198   /**
199    * The {@link BindingController#unbindFc unbindFc} method overriden by this
200    * mixin.
201    *
202    * @param clientItfName the name of a client interface of the component to
203    * which this interface belongs.
204    * @throws NoSuchInterfaceException if there is no such client interface.
205    * @throws IllegalBindingException if the binding cannot be removed.
206    * @throws IllegalLifeCycleException if this component has a {@link
207    * LifeCycleController} interface, but it is not in an appropriate state
208    * to perform this operation.
209    */

210
211   public abstract void _super_unbindFc (String JavaDoc clientItfName) throws
212     NoSuchInterfaceException,
213     IllegalBindingException,
214     IllegalLifeCycleException;
215 }
216
Popular Tags