KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > openccm > Deployment > ComponentServerBase


1 /*====================================================================
2
3 OpenCCM: The Open CORBA Component Model Platform
4 Copyright (C) 2000-2002 USTL - LIFL - GOAL
5 Contact: openccm-team@objectweb.org
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 USA
21
22 Initial developer(s): Mathieu Vadet.
23 Contributor(s): Sylvain Leblanc, Romain Rouvoy________.
24
25 ====================================================================*/

26
27 package org.objectweb.openccm.Deployment;
28
29 /**
30  * This class implements the OMG IDL
31  * ::Components::Deployment::ComponentServer interface.
32  *
33  * @author <a HREF="mailto:Mathieu.Vadet@lifl.fr">Mathieu Vadet</a>
34  * @author <a HREF="mailto:Sylvain.Leblanc@lifl.fr">Sylvain Leblanc</a>
35  * @author <a HREF="mailto:Romain.Rouvoy@lifl.fr">Romain Rouvoy</a>
36  *
37  * @version 0.3
38  */

39
40 public class ComponentServerBase
41 {
42     // ==================================================================
43
//
44
// Internal state.
45
//
46
// ==================================================================
47

48     /**
49      **
50      **/

51     protected org.objectweb.ccm.util.Vector containers_;
52
53     /**
54      **
55      **/

56     protected org.omg.Components.ConfigValue[] configuration_;
57
58     /**
59      * ----> Fred Modification begining
60      ** The server reference isn't needed anymore
61      **/

62     //protected ServerImpl the_server_;
63
// ----> Fred Modification begining
64

65     /**
66      ** Listener for additionnal plugins
67      **/

68     protected org.objectweb.openccm.Deployment.listener.ComponentServerListener listener_;
69     
70
71     // ==================================================================
72
//
73
// Constructor.
74
//
75
// ==================================================================
76

77     /**
78      ** The constructor.
79      **
80      ** @param classLoader The class loader used to load home classes.
81      **/

82     public
83     ComponentServerBase( // The server reference isn't needed anymore
84
/*ServerImpl server*/)
85     {
86         // The server reference isn't needed anymore
87
//the_server_ = server;
88
containers_ = new org.objectweb.ccm.util.Vector();
89         configuration_ = new org.omg.Components.ConfigValue[0];
90                 listener_ = null;
91       
92                 org.objectweb.openccm.Deployment.listener.TheComponentServerConfigurator.get_instance().configure_component_server(new ComponentServerLocalImpl(this));
93     }
94
95     /**
96      * Fred Adding :
97      * Adding a new constructor supporting the ComponentServer configuration
98      * This constructore is used by ServerActivator
99      */

100     public ComponentServerBase( org.omg.Components.ConfigValue[] config){
101         containers_ = new org.objectweb.ccm.util.Vector();
102         this.listener_ = null;
103         this.configuration_=config;
104         org.objectweb.openccm.Deployment.listener.TheComponentServerConfigurator.get_instance().configure_component_server(new ComponentServerLocalImpl(this));
105         
106     }
107     // ==================================================================
108
//
109
// Internal methods.
110
//
111
// ==================================================================
112

113     // ==================================================================
114
//
115
// Public methods.
116
//
117
// ==================================================================
118
/**
119          ** Add a new listener for the deployment
120          **
121          ** @param listener the listener to add
122          **/

123     public void
124         add_listener (org.objectweb.openccm.Deployment.listener.ComponentServerListener listener)
125     {
126                 if (listener_ == null)
127                         listener_ = listener;
128                 else
129                         listener_.set_delegate(listener);
130     }
131     // ------ >Fred modification begining
132
/**
133      *
134      * asComponentServer isn't support here anymore.
135      * asComponentServer traitment is done by ComponentServerImpl object.
136      **/

137    /* public org.omg.Components.Deployment.ComponentServer
138     asComponentServer()
139     {
140         return the_server_.provide_component_server();
141     }*/

142      // ------ >Fred modification ending
143

144     
145     /**
146      ** Register the reference into the internal list
147          **
148          ** @param cont_ref the reference to the container
149          **
150      **/

151     public void
152         add_container (org.omg.Components.Deployment.Container cont_ref)
153     {
154         containers_.add(cont_ref);
155                 listener_.on_add (cont_ref);
156     }
157     
158     /**
159      * To unregister a container.
160      *
161      * Added for Bug #306.
162      */

163     public void
164     unregister_container(org.omg.Components.Deployment.Container ref)
165     throws org.omg.Components.RemoveFailure
166     {
167     listener_.on_remove (ref);
168     
169       for(java.util.Iterator JavaDoc it=containers_.iterator();it.hasNext(); )
170           if(ref._is_equivalent(((org.omg.Components.Deployment.Container)it.next())))
171            {
172             it.remove();
173             return ;
174         }
175              
176         // The reference was not foound throw a Remove Exception
177
throw new org.omg.Components.RemoveFailure();
178     }
179
180     // ==================================================================
181
//
182
// Methods for the ::Components::Deployment::ComponentServer interface.
183
//
184
// ==================================================================
185

186     //
187
// IDL:omg.org/Components/Deployment/ComponentServer/configuration:1.0
188
//
189
/**
190      ** To obtain the component server configuration.
191      **
192      **/

193     public org.omg.Components.ConfigValue[]
194     configuration()
195     {
196         return configuration_;
197     }
198
199     //
200
// IDL:omg.org/Components/Deployment/ComponentServer/configuration:1.0
201
//
202
/**
203      ** To set the component server configuration.
204      ** Note : configuration is a readonly attribute, but this allow us to
205      ** set the configuration later in the instanciation process
206      ** which can be useful as we don't have server activator yet.
207      **
208      **/

209     public void
210     configuration(org.omg.Components.ConfigValue[] config)
211     {
212         configuration_ = config;
213     }
214
215     //
216
// IDL:omg.org/Components/Deployment/ComponentServer/get_server_activator:1.0
217
//
218
/**
219      ** To obtain the server activator that has created this component server.
220      **
221      **/

222     public org.omg.Components.Deployment.ServerActivator
223     get_server_activator()
224     {
225         //
226
// TODO : implement, but needs to have the server activator too
227
//
228
throw new org.omg.CORBA.NO_IMPLEMENT JavaDoc();
229     }
230
231     //
232
// IDL:omg.org/Components/Deployment/ComponentServer/create_container:1.0
233
//
234
/**
235      ** To create a container.
236      **
237      **/

238     public org.omg.Components.Deployment.Container
239     create_container(ComponentServerImpl csi,org.omg.Components.ConfigValue[] config)
240     throws org.omg.Components.CreateFailure,
241            org.omg.Components.Deployment.InvalidConfiguration
242     {
243         // create the object.
244
ContainerImpl cont = new ContainerImpl(config,csi);
245
246         // activate the object.
247
org.omg.CORBA.Object JavaDoc ref = cont._this_object(org.objectweb.openccm.corba.TheORB.getORB());
248         org.omg.Components.Deployment.Container cont_ref =
249                         org.omg.Components.Deployment.ContainerHelper.narrow(ref);
250         cont.the_container_ref(cont_ref);
251                 listener_.on_create (cont_ref);
252
253         return cont_ref;
254     }
255
256     //
257
// IDL:omg.org/Components/Deployment/ComponentServer/remove_container:1.0
258
//
259
/**
260      ** To remove a container.
261      **
262      **/

263     public void
264     remove_container(org.omg.Components.Deployment.Container ref)
265     throws org.omg.Components.RemoveFailure
266     {
267 /* Bug #306
268    OLD CODE
269
270         listener_.on_remove (ref);
271         boolean b = containers_.remove(ref);
272         if (!b)
273             throw new org.omg.Components.RemoveFailure();
274
275    NEW CODE
276 */

277
278       // Tests if ref is a container of this component server.
279
for(int i=0; i<containers_.size(); i++)
280       {
281           org.omg.Components.Deployment.Container c =
282               (org.omg.Components.Deployment.Container)containers_.get(i);
283
284           // If ref is a container of this component server then removes it.
285
if(ref._is_equivalent(c))
286       {
287               ref.remove();
288               return;
289           }
290       }
291
292       // Else ref is not a container of this component server.
293
throw new org.omg.Components.RemoveFailure();
294     }
295
296     //
297
// IDL:omg.org/Components/Deployment/ComponentServer/get_containers:1.0
298
//
299
/**
300      ** To obtain all created containers references.
301      **
302      **/

303     public org.omg.Components.Deployment.Container[]
304     get_containers()
305     {
306         org.omg.Components.Deployment.Container[] result =
307             new org.omg.Components.Deployment.Container[containers_.size()];
308
309         for (int i=0;i<result.length;i++)
310             result[i] = (org.omg.Components.Deployment.Container)containers_.get(i);
311
312         return result;
313     }
314
315     //
316
// IDL:omg.org/Components/Deployment/ComponentServer/remove:1.0
317
//
318
/**
319      ** To remove this component server.
320      **
321      **/

322     public void
323     remove()
324     throws org.omg.Components.RemoveFailure
325     {
326 /* Bug #306
327    NEW CODE
328 */

329         // Removes all its containers.
330
org.omg.Components.Deployment.Container[] containers = get_containers();
331         for(int i=0; i<containers.length; i++)
332         {
333             containers[i].remove();
334         }
335         listener_.on_destroy();
336         
337         //----------> Fred modification
338
// The desactivation treatment is now support by the ComponentServer Impl
339
/*
340         try {
341             org.objectweb.openccm.corba.TheRootPOA.getRootPOA().deactivate_object(org.objectweb.openccm.corba.TheRootPOA.getRootPOA().reference_to_id(asComponentServer()));
342         } catch (org.omg.PortableServer.POAPackage.WrongAdapter ex) {
343             throw new org.omg.Components.RemoveFailure();
344         } catch (org.omg.PortableServer.POAPackage.WrongPolicy ex) {
345             throw new org.omg.Components.RemoveFailure();
346         } catch (org.omg.PortableServer.POAPackage.ObjectNotActive ex) {
347             throw new org.omg.Components.RemoveFailure();
348         }*/

349     }
350 }
351
352
Popular Tags