KickJava   Java API By Example, From Geeks To Geeks.

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


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 import org.objectweb.fractal.api.factory.InstantiationException;
32
33 import org.objectweb.fractal.julia.Controller;
34 import org.objectweb.fractal.julia.InitializationContext;
35
36 /**
37  * Provides a container based implementation of the {@link BindingController}
38  * interface. This mixin implements the {@link BindingController} methods
39  * through delegation to the encapsulated "user component".
40  * <br>
41  * <br>
42  * <b>Requirements</b>
43  * <ul>
44  * <li>none.</li>
45  * </ul>
46  */

47
48 public abstract class ContainerBindingControllerMixin
49   implements Controller, BindingController
50 {
51
52   // -------------------------------------------------------------------------
53
// Private constructor
54
// -------------------------------------------------------------------------
55

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

63   /**
64    * The "user component" encapsulated in this container component.
65    */

66
67   public Object JavaDoc fcContent;
68
69   /**
70    * Initializes the fields of this mixin and then calls the overriden method.
71    *
72    * @param ic information about the component to which this controller object
73    * belongs.
74    * @throws InstantiationException if the initialization fails.
75    */

76
77   public void initFcController (final InitializationContext ic)
78     throws InstantiationException JavaDoc
79   {
80     fcContent = ic.content;
81     Component owner = (Component)ic.getOptionalInterface("component");
82     if (owner != null) {
83       try {
84         owner = (Component)owner.getFcInterface("component");
85         if (fcContent == this) {
86           // case of merge...AndContent options
87
if (this instanceof ContentBindingController) {
88             ((ContentBindingController)this).bindFcContent("component", owner);
89           }
90         } else if (fcContent instanceof BindingController) {
91           ((BindingController)fcContent).bindFc("component", owner);
92         }
93       } catch (Exception JavaDoc ignored) {
94       }
95     }
96     _super_initFcController(ic);
97   }
98
99   public String JavaDoc[] listFc () {
100     if (fcContent == this) {
101       // case of merge...AndContent options
102
if (this instanceof ContentBindingController) {
103         return ((ContentBindingController)this).listFcContent();
104       }
105     } else if (fcContent instanceof BindingController) {
106       return ((BindingController)fcContent).listFc();
107     }
108     return new String JavaDoc[0];
109   }
110
111   public Object JavaDoc lookupFc (final String JavaDoc clientItfName)
112     throws NoSuchInterfaceException
113   {
114     if (fcContent == this) {
115       // case of merge...AndContent options
116
ContentBindingController cbc = (ContentBindingController)this;
117       return cbc.lookupFcContent(clientItfName);
118     } else {
119       BindingController bc = (BindingController)fcContent;
120       return bc.lookupFc(clientItfName);
121     }
122   }
123
124   public void bindFc (final String JavaDoc clientItfName, final Object JavaDoc serverItf) throws
125     NoSuchInterfaceException,
126     IllegalBindingException,
127     IllegalLifeCycleException
128   {
129     if (fcContent == this) {
130       // case of merge...AndContent options
131
((ContentBindingController)this).bindFcContent(clientItfName, serverItf);
132     } else {
133       ((BindingController)fcContent).bindFc(clientItfName, serverItf);
134     }
135   }
136
137   public void unbindFc (final String JavaDoc clientItfName) throws
138     NoSuchInterfaceException,
139     IllegalBindingException,
140     IllegalLifeCycleException
141   {
142     if (fcContent == this) {
143       // case of merge...AndContent options
144
((ContentBindingController)this).unbindFcContent(clientItfName);
145     } else {
146       ((BindingController)fcContent).unbindFc(clientItfName);
147     }
148   }
149
150   // -------------------------------------------------------------------------
151
// Fields and methods required by the mixin class in the base class
152
// -------------------------------------------------------------------------
153

154   /**
155    * The {@link Controller#initFcController initFcController} method overriden
156    * by this mixin.
157    *
158    * @param ic information about the component to which this controller object
159    * belongs.
160    * @throws InstantiationException if the initialization fails.
161    */

162
163   public abstract void _super_initFcController (InitializationContext ic)
164     throws InstantiationException JavaDoc;
165 }
166
Popular Tags