KickJava   Java API By Example, From Geeks To Geeks.

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


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 import org.objectweb.fractal.api.factory.InstantiationException;
32
33 import org.objectweb.fractal.julia.ChainedNoSuchInterfaceException;
34 import org.objectweb.fractal.julia.Controller;
35 import org.objectweb.fractal.julia.InitializationContext;
36
37 import java.util.ArrayList JavaDoc;
38 import java.util.List JavaDoc;
39 import java.util.Map JavaDoc;
40
41 /**
42  * Provides a basic implementation of the {@link ContentController} interface.
43  * <br>
44  * <br>
45  * <b>Requirements</b>
46  * <ul>
47  * <li>none.</li>
48  * </ul>
49  */

50
51 public abstract class BasicContentControllerMixin
52   implements Controller, ContentController
53 {
54
55   // -------------------------------------------------------------------------
56
// Private constructor
57
// -------------------------------------------------------------------------
58

59   private BasicContentControllerMixin () {
60   }
61
62   // -------------------------------------------------------------------------
63
// Fields and methods added and overriden by the mixin class
64
// -------------------------------------------------------------------------
65

66   /**
67    * The internal interfaces of the component to which this controller object
68    * belongs.
69    */

70
71   public Map JavaDoc fcInternalInterfaces;
72
73   /**
74    * The sub components of the component to which this controller object
75    * belongs.
76    */

77
78   public List JavaDoc fcSubComponents;
79
80   /**
81    * Initializes the fields of this mixin and then calls the overriden method.
82    *
83    * @param ic information about the component to which this controller object
84    * belongs.
85    * @throws InstantiationException if the initialization fails.
86    */

87
88   public void initFcController (final InitializationContext ic)
89     throws InstantiationException JavaDoc
90   {
91     fcInternalInterfaces = ic.internalInterfaces;
92     _super_initFcController(ic);
93   }
94
95   public Object JavaDoc[] getFcInternalInterfaces () {
96     if (fcInternalInterfaces == null) {
97       return new Object JavaDoc[0];
98     }
99     // returns the names of all the public interfaces in fcInternalInterfaces
100
// interfaces whose name begins with '/' are private
101
int size = 0;
102     String JavaDoc[] names = new String JavaDoc[fcInternalInterfaces.size()];
103     names = (String JavaDoc[])fcInternalInterfaces.keySet().toArray(names);
104     for (int i = 0; i < names.length; ++i) {
105       if (names[i].charAt(0) != '/') {
106         ++size;
107       }
108     }
109     int index = 0;
110     Object JavaDoc[] itfs = new Object JavaDoc[size];
111     for (int i = 0; i < names.length; ++i) {
112       if (names[i].charAt(0) != '/') {
113         itfs[index++] = fcInternalInterfaces.get(names[i]);
114       }
115     }
116     return itfs;
117   }
118
119   public Object JavaDoc getFcInternalInterface (final String JavaDoc interfaceName)
120     throws NoSuchInterfaceException
121   {
122     Object JavaDoc itf;
123     if (fcInternalInterfaces == null) {
124       itf = null;
125     } else {
126       itf = fcInternalInterfaces.get(interfaceName);
127     }
128     if (itf == null) {
129       throw new ChainedNoSuchInterfaceException(
130         null, _this_weaveableOptC, interfaceName);
131     }
132     return itf;
133   }
134
135   public Component[] getFcSubComponents () {
136     if (fcSubComponents == null) {
137       return new Component[0];
138     }
139     return (Component[])fcSubComponents.toArray(
140       new Component[fcSubComponents.size()]);
141   }
142
143   public void addFcSubComponent (final Component subComponent)
144     throws IllegalContentException, IllegalLifeCycleException
145   {
146     if (fcSubComponents == null) {
147       fcSubComponents = new ArrayList JavaDoc();
148     }
149     fcSubComponents.add(subComponent);
150   }
151
152   public void removeFcSubComponent (final Component subComponent)
153     throws IllegalContentException, IllegalLifeCycleException
154   {
155     if (fcSubComponents != null) {
156       fcSubComponents.remove(subComponent);
157     }
158   }
159
160   // -------------------------------------------------------------------------
161
// Fields and methods required by the mixin class in the base class
162
// -------------------------------------------------------------------------
163

164   /**
165    * The <tt>weaveableOptC</tt> field required by this mixin. This field is
166    * supposed to reference the {@link Component} interface of the component to
167    * which this controller object belongs.
168    */

169
170   public Component _this_weaveableOptC;
171
172   /**
173    * The {@link Controller#initFcController initFcController} method overriden
174    * by this mixin.
175    *
176    * @param ic information about the component to which this controller object
177    * belongs.
178    * @throws InstantiationException if the initialization fails.
179    */

180
181   public abstract void _super_initFcController (InitializationContext ic)
182     throws InstantiationException JavaDoc;
183 }
184
Popular Tags