KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > openccm > OpenCCM_DCI > cif > ContainerSegImpl


1 /*====================================================================
2
3 OpenCCM: The Open CORBA Component Model Platform
4 Copyright (C) 2000-2005 INRIA - USTL - LIFL - GOAL
5 Contact: openccm@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): Briclet Frederic
23 Contributor(s): Philippe Merle.
24
25 ====================================================================
26 $Id: ContainerSegImpl.java,v 1.3 2005/06/27 14:59:16 merle Exp $
27 ====================================================================*/

28
29 package org.objectweb.openccm.OpenCCM_DCI.cif;
30
31 import org.objectweb.openccm.OpenCCM_DCI.*;
32 import org.objectweb.openccm.Deployment.ContainerLocalImpl;
33 import org.objectweb.openccm.Deployment.listener.ContainerListenerDefault;
34 import org.objectweb.openccm.corba.*;
35
36
37 /**
38  * This is the implementation of the Container facet provided by the
39  * ContainerManager component.
40  * This class inherits from the skeleton
41  * generated by the OpenCCM's CIF to Java mapping generator.
42  *
43  * @author <a HREF="mailto:Frederic.Briclet@lifl.fr">Briclet Frederic</A>
44  */

45
46 public class ContainerSegImpl
47        extends org.objectweb.openccm.OpenCCM_DCI.
48                 ContainerManagerSessionComposition.ContainerSeg
49        implements org.objectweb.openccm.Deployment.ContainerHomeInformation
50 {
51
52     // ==================================================================
53
//
54
// Internal state.
55
//
56
// ==================================================================
57
// reference on a container
58
private org.objectweb.openccm.Deployment.ContainerImpl container ;
59     //the container configuration
60
private org.omg.Components.ConfigValue[] configuration;
61     //Cookie to the parent ComponentServer
62
private org.omg.Components.Cookie cookie;
63     //Reference on the CCM object
64
private org.objectweb.openccm.OpenCCM_DCI.ContainerManagerCCM cont;
65     // ==================================================================
66
//
67
// Internal methods.
68
//
69
// ==================================================================
70

71     private org.objectweb.openccm.OpenCCM_DCI.ContainerManagerCCM
72     getCont()
73     {
74         if(cont==null)
75             cont=(org.objectweb.openccm.OpenCCM_DCI.ContainerManagerCCM)
76               get_context();
77         return cont;
78     }
79     // ==================================================================
80
//
81
// constructor.
82
//
83
// ==================================================================
84
public ContainerSegImpl(){
85         super();
86     }
87    
88     // ==================================================================
89
//
90
// public methods.
91
//
92
// ==================================================================
93
/**
94      * Method used by the container manager main segment to configure
95      * the container.
96      * @param configuration the container configuration
97      */

98     public void
99     configuration(org.omg.Components.ConfigValue[] configuration)
100     {
101         try{
102           
103             //process container configuration
104

105             container= new org.objectweb.openccm.Deployment
106
                            .ContainerImpl(configuration,
107                                            null,
108                                            get_context()
109                                            .get_connection_component_installation());
110            container._delegate().set_container_home_info(this);
111            /*container.add_listener
112                 (new ContainerListenerDefault
113                 (new ContainerLocalImpl(container._delegate())));*/

114                 
115 /* Contributor: Philippe Merle
116  *
117  * Following does not work on JacORB 2.0.
118  
119            org.omg.CORBA.Object ref =
120                 container._this_object(org.objectweb
121                                        .ccm.CORBA.TheORB.getORB());
122
123  * Replaced by the following
124  */

125
126           
127             org.omg.CORBA.Object JavaDoc ref = null;
128             try
129             {
130                 byte[] oid = org.objectweb.openccm.corba.TheRootPOA.getRootPOA().activate_object(container);
131                 ref = org.objectweb.openccm.corba.TheRootPOA.getRootPOA().id_to_reference(oid);
132             }
133             catch(Exception JavaDoc ex)
134             {
135                 ex.printStackTrace();
136             }
137
138 /* End of the correction. */
139
140              
141                 
142               //set the configuration
143
this.configuration=configuration;
144             //create a deleguate container
145

146                                                
147             org.omg.Components.Deployment.Container cont_ref =
148                 org.omg.Components.Deployment.ContainerHelper.narrow(ref);
149             container.the_container_ref(cont_ref);
150
151             //set a internal attribute
152

153         }
154         catch(Exception JavaDoc e){
155             e.printStackTrace();
156         }
157     }
158     /**
159      * Setting method used by the ContainerManager main segment
160      * to set the registration cookie with the parent componentserver.
161      * @param cookie The cookie to memorize
162      */

163     public void
164     cookie(org.omg.Components.Cookie cookie)
165     {
166       this.cookie=cookie;
167     }
168     
169     /**
170      * Unregister the home reference from the home list
171      */

172     public void
173     unregister_home(org.omg.Components.CCMHome ref)
174     throws org.omg.Components.RemoveFailure
175     {
176           try{
177             // Retrieves all ContainerManager connection
178
org.objectweb.openccm.OpenCCM_DCI.
179                 ContainerManagerPackage.homes_createdConnection
180                 connect[]=getCont().get_connections_homes_created();
181             //compare all home reference
182
for(int i=0;i<connect.length;i++)
183                 if(connect[i].objref._is_equivalent(ref))
184                     {
185                         getCont().disconnect_homes_created(connect[i].ck);
186                         return ;
187                     }
188             }
189             catch(org.omg.Components.ExceededConnectionLimit ecl){
190                 ecl.printStackTrace();
191             }
192         throw new org.omg.Components.RemoveFailure();
193     }
194     // ==================================================================
195
//
196
// Components::Deployment::Container methods.
197
//
198
// ==================================================================
199

200     /**
201      * This methods returned the parent componentserver
202      * @return The parent componentserver
203      */

204     public
205     org.omg.Components.Deployment.ComponentServer
206     get_component_server(){
207         return getCont().get_connection_component_server();
208     }
209
210     /**
211      * This method allows Home installation.
212      * @param uuid The archive uuid
213      * @param entrypt The component home entrypoint
214      * @param config Configvalue to configure the home
215      */

216     public org.omg.Components.CCMHome
217         install_home(java.lang.String JavaDoc uuid,
218                      java.lang.String JavaDoc entrypt,
219                      org.omg.Components.ConfigValue[] config)
220         throws org.omg.Components.Deployment.UnknownImplId,
221                org.omg.Components.Deployment.ImplEntryPointNotFound,
222                org.omg.Components.Deployment.InstallationFailure,
223                org.omg.Components.Deployment.InvalidConfiguration
224     {
225         // deleguate the installation to the container attribute
226
org.omg.Components.CCMHome home=
227             container.install_home(uuid,entrypt,config);
228         
229         try{
230             // connect the created home to the ContainerManager component
231
getCont().connect_homes_created(home);
232         }
233         catch(Exception JavaDoc e)
234             {
235                 System.err.println(e.getMessage());
236                 throw new org.omg.Components.Deployment.InstallationFailure();
237             }
238         //return the home created
239
return home;
240     }
241
242     /**
243      * This method remove a home.
244      * TODO: Disconnect the home form ContaierManager
245      * @param homeref The reference of the home to remove
246      */

247     public
248     void
249     remove_home(org.omg.Components.CCMHome homeref)
250         throws org.omg.Components.RemoveFailure
251     {
252         try{
253             // Retrieves all ContainerManager connection
254
org.objectweb.openccm.OpenCCM_DCI.
255                 ContainerManagerPackage.homes_createdConnection
256                 connect[]=getCont().get_connections_homes_created();
257             //compare all home reference
258
for(int i=0;i<connect.length;i++)
259                 if(connect[i].objref._is_equivalent(homeref))
260                     {
261                         //remove the home reference will be done by the callback
262
//method unregister_home
263
//connect[i].objref.remove_home();
264
homeref.remove_home();
265                         return ;
266                     }
267         }
268         catch(Exception JavaDoc ecl){
269             ecl.printStackTrace();
270         }
271         throw new org.omg.Components.RemoveFailure();
272         
273     }
274
275     /**
276      * This method return an array of all the running home
277      * created by this container.
278      */

279     public org.omg.Components.CCMHome[]
280     get_homes()
281     {
282         //Retrieve all the ContainerManager connection
283
org.objectweb.openccm.OpenCCM_DCI.
284           ContainerManagerPackage.homes_createdConnection
285           connect[]=getCont().get_connections_homes_created();
286         //Create a home array
287
org.omg.Components.CCMHome[] homes=
288           new org.omg.Components.CCMHome[connect.length];
289         // Fill the home array
290
for(int i=0;i<connect.length;i++)
291           homes[i]=connect[i].objref;
292         //return the array
293
return homes;
294     }
295
296     /**
297      * Remove the current container and all the home created.
298      */

299     public void
300     remove()
301     throws org.omg.Components.RemoveFailure
302     {
303         try
304             {
305                 //unregister the container from its parent componentserver
306
get_context().get_connection_container_manager_registration()
307                     .unregister_container_manager(cookie);
308                 //retrieve all the home connection
309
org.objectweb.openccm.OpenCCM_DCI.
310                   ContainerManagerPackage.homes_createdConnection
311                   connect[]=getCont().get_connections_homes_created();
312                 //remove all the home
313
for(int i=0;i<connect.length;i++){
314                     //cont.disconnect_homes_created(connect[i].ck);
315
connect[i].objref.remove_home();
316                 }
317
318                 //Remove the deleguation container
319
container.remove();
320
321                 // Next line is commented as it causes an error.
322
// getCont().remove();
323
}
324         catch(Exception JavaDoc e )
325             {
326                 System.err.println("Cannot disconnect Container/ComponentServer/Node");
327                 e.printStackTrace(System.err);
328                 throw new org.omg.Components.RemoveFailure();
329             }
330     }
331   
332     // ==================================================================
333
//
334
// Accessor methods.
335
//
336
// ==================================================================
337

338     public org.omg.Components.ConfigValue[]
339     configuration()
340     {
341         return this.configuration;
342     }
343
344
345 }
346
Popular Tags