KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > fractal > julia > control > content > SuperContentMixin


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.content;
25
26 import org.objectweb.fractal.api.Component;
27 import org.objectweb.fractal.api.NoSuchInterfaceException;
28 import org.objectweb.fractal.api.control.ContentController;
29 import org.objectweb.fractal.api.control.IllegalContentException;
30 import org.objectweb.fractal.api.control.IllegalLifeCycleException;
31
32 /**
33  * Provides {@link SuperControllerNotifier notification} functions to a {@link
34  * ContentController}.
35  * <br>
36  * <br>
37  * <b>Requirements</b>
38  * <ul>
39  * <li>the component to which this controller object belongs must provide the
40  * {@link Component} interface.</li>
41  * </ul>
42  */

43
44 public abstract class SuperContentMixin implements ContentController {
45
46   // -------------------------------------------------------------------------
47
// Private constructor
48
// -------------------------------------------------------------------------
49

50   private SuperContentMixin () {
51   }
52
53   // -------------------------------------------------------------------------
54
// Fields and methods added and overriden by the mixin class
55
// -------------------------------------------------------------------------
56

57   /**
58    * Calls the overriden method and then notifies the given component it has
59    * been added in this component. This method does nothing if the given sub
60    * component does not provide the {@link SuperControllerNotifier} interface.
61    *
62    * @param subComponent the component to be added inside this component.
63    * @throws IllegalContentException if the given component cannot be added
64    * inside this component.
65    * @throws IllegalLifeCycleException if this component has a {@link
66    * LifeCycleController} interface, but it is not in an appropriate state
67    * to perform this operation.
68    */

69
70   public void addFcSubComponent (final Component subComponent)
71     throws IllegalContentException, IllegalLifeCycleException
72   {
73     _super_addFcSubComponent(subComponent);
74     SuperControllerNotifier scn = getFcSuperControllerNotifier(subComponent);
75     if (scn != null) {
76       try {
77         Component c = (Component)_this_weaveableC.getFcInterface("component");
78         scn.addedToFc(c);
79       } catch (NoSuchInterfaceException ignored) {
80       }
81     }
82   }
83
84   /**
85    * Calls the overriden method and then notifies the given component it has
86    * been removed from in this component. This method does nothing if the given
87    * sub component does not provide the {@link SuperControllerNotifier}
88    * interface.
89    *
90    * @param subComponent the component to be removed from this component.
91    * @throws IllegalContentException if the given component cannot be removed
92    * from this component.
93    * @throws IllegalLifeCycleException if this component has a {@link
94    * LifeCycleController} interface, but it is not in an appropriate state
95    * to perform this operation.
96    */

97
98   public void removeFcSubComponent (final Component subComponent)
99     throws IllegalContentException, IllegalLifeCycleException
100   {
101     _super_removeFcSubComponent(subComponent);
102     SuperControllerNotifier scn = getFcSuperControllerNotifier(subComponent);
103     if (scn != null) {
104       try {
105         Component c = (Component)_this_weaveableC.getFcInterface("component");
106         scn.removedFromFc(c);
107       } catch (NoSuchInterfaceException ignored) {
108       }
109     }
110   }
111
112   /**
113    * Returns the {@link SuperControllerNotifier} interface of the given
114    * component.
115    *
116    * @param c a component.
117    * @return the {@link SuperControllerNotifier} interface of the given
118    * component, or <tt>null</tt>.
119    */

120
121   private SuperControllerNotifier getFcSuperControllerNotifier (
122     final Component c)
123   {
124     try {
125       return (SuperControllerNotifier)c.getFcInterface("super-controller");
126     } catch (Exception JavaDoc e) {
127       try {
128         return (SuperControllerNotifier)c.
129           getFcInterface("/super-controller-notifier");
130       } catch (NoSuchInterfaceException ignored) {
131         return null;
132       }
133     }
134   }
135   // -------------------------------------------------------------------------
136
// Fields and methods required by the mixin class in the base class
137
// -------------------------------------------------------------------------
138

139   /**
140    * The <tt>weaveableC</tt> field required by this mixin. This field is
141    * supposed to reference the {@link Component} interface of the component to
142    * which this controller object belongs.
143    */

144
145   public Component _this_weaveableC;
146
147   /**
148    * The {@link ContentController#addFcSubComponent addFcSubComponent} method
149    * overriden by this mixin.
150    *
151    * @param subComponent the component to be added inside this component.
152    * @throws IllegalContentException if the given component cannot be added
153    * inside this component.
154    * @throws IllegalLifeCycleException if this component has a {@link
155    * LifeCycleController} interface, but it is not in an appropriate state
156    * to perform this operation.
157    */

158
159   public abstract void _super_addFcSubComponent (Component subComponent)
160     throws IllegalContentException, IllegalLifeCycleException;
161
162   /**
163    * The {@link ContentController#removeFcSubComponent removeFcSubComponent}
164    * method overriden by this mixin.
165    *
166    * @param subComponent the component to be removed from this component.
167    * @throws IllegalContentException if the given component cannot be removed
168    * from this component.
169    * @throws IllegalLifeCycleException if this component has a {@link
170    * LifeCycleController} interface, but it is not in an appropriate state
171    * to perform this operation.
172    */

173
174   public abstract void _super_removeFcSubComponent (Component subComponent)
175     throws IllegalContentException, IllegalLifeCycleException;
176 }
177
Popular Tags