KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*====================================================================
2
3 OpenCCM: The Open CORBA Component Model Platform
4 Copyright (C) 2000-2002 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): ___________________________________________________.
24
25 ====================================================================*/

26
27 package org.objectweb.openccm.OpenCCM_DCI.cif;
28
29 import org.objectweb.openccm.OpenCCM_DCI.*;
30 import org.objectweb.openccm.corba.*;
31
32 /**
33  * This is the implementation of the
34  * Components::Deployment::ComponentServer interface.
35  *
36  * This class inherits from the skeleton
37  * generated by the OpenCCM's CIF to Java mapping generator.
38  *
39  * @author <a HREF="mailto:Frederic.Briclet@lifl.fr">Briclet Frederic</A>
40  */

41 public class ComponentServerSegImpl
42     extends org.objectweb.openccm.OpenCCM_DCI.
43              ComponentServerManagerSessionComposition.ComponentServerSeg
44 {
45     // ==================================================================
46
//
47
// Internal state.
48
//
49
// ==================================================================
50
//Configuration of the component server
51
private org.omg.Components.ConfigValue[] configuration;
52     //Cookie connection with NodeManager
53
private org.omg.Components.Cookie cookie;
54     //A reference on the main interface
55
private org.objectweb.openccm.OpenCCM_DCI.ComponentServerManagerCCM CS;
56     //Boolean used to manager removal process
57
private boolean removed;
58
59     // ==================================================================
60
//
61
// Constructor.
62
//
63
// ==================================================================
64
public ComponentServerSegImpl(){
65         super();
66         //Retrieve reference of the main context
67

68     }
69
70     // ==================================================================
71
//
72
// Internal methods.
73
//
74
// ==================================================================
75

76     private org.objectweb.openccm.OpenCCM_DCI.ComponentServerManagerCCM
77     getCS()
78     {
79         if(CS==null)
80            CS=(org.objectweb.openccm
81             .OpenCCM_DCI.ComponentServerManagerCCM)get_context();
82         return CS;
83     }
84     // ==================================================================
85
//
86
// Public methods.
87
//
88
// ==================================================================
89
public void
90     configuration(org.omg.Components.ConfigValue[] configuration)
91     {
92         this.configuration=configuration;
93     }
94     
95     public void
96     cookie(org.omg.Components.Cookie cookie)
97     {
98       this.cookie=cookie;
99     }
100
101     // ==================================================================
102
//
103
// org.omg.Components.Deployment.ComponentServer methods.
104
//
105
// ==================================================================
106

107     /**
108      * The accessor method to the configuration attribute
109      * @return the current configuration
110      */

111     public org.omg.Components.ConfigValue[]
112     configuration(){
113         return this.configuration;
114     }
115
116     /**
117      * This method return the parent ServerActivator
118      * @return the parent ServerActivator
119      */

120     public org.omg.Components.Deployment.ServerActivator
121     get_server_activator(){
122         return getCS().get_connection_parent_server_activator();
123     }
124
125     /**
126      * Create a new container with specified config value.
127      * @param config the config value to use
128      * @return the container created.
129      */

130     public
131     org.omg.Components.Deployment.Container
132     create_container(org.omg.Components.ConfigValue[] config)
133         throws org.omg.Components.CreateFailure,
134                org.omg.Components.Deployment.InvalidConfiguration
135     {
136         
137         //Retrieve a connection on the ContainerManagerHome
138
ContainerManagerHome conthome=
139             getCS().get_connection_container_manager_home();
140         //create a new ContainerManager
141
org.objectweb.openccm.OpenCCM_DCI.ContainerManager contm=
142             conthome.create();
143         //Setting up its configuration
144
contm.config(config);
145         
146         try{
147             //connect the ContainerManagerRegistration interface
148
contm.connect_container_manager_registration(getCS().provide_container_manager_registration());
149             //connect the parent ComponentServer
150
contm.connect_component_server(getCS().provide_component_server());
151             //connect the ComponentInstallation to use
152
contm.connect_component_installation(get_context().get_connection_component_installation());
153         }
154         catch(org.omg.Components.AlreadyConnected e)
155             {
156                 System.err.println(e.getMessage());
157                 throw new org.omg.Components.CreateFailure();
158             }
159         try{
160             // configure complete the ContainerManager
161
contm.configuration_complete();
162         }
163         catch(org.omg.Components.InvalidConfiguration e2)
164             {
165                  System.err.println(e2.getMessage());
166                 throw new org.omg.Components.Deployment.InvalidConfiguration();
167             }
168         //Return a reference of the provided Container facet.
169
return contm.provide_container();
170     }
171     
172     /**
173      * Remove a container child.
174      */

175     public void
176     remove_container(org.omg.Components.Deployment.Container cref)
177     throws org.omg.Components.RemoveFailure
178     {
179         //Retrieve connection with all ContainerManager
180
org.objectweb.openccm.OpenCCM_DCI.
181             ComponentServerManagerPackage.container_managersConnection
182             connect[]=getCS().get_connections_container_managers();
183         //compare all container reference to find the right container
184
// and remove it.
185
for(int i=0;i<connect.length;i++)
186             if(connect[i].objref.
187                provide_container().
188                _is_equivalent(cref))
189                 {
190                     connect[i].objref.remove();
191                     return ;
192                 }
193         //The container reference was not a child of this component server
194
throw new org.omg.Components.RemoveFailure();
195     }
196
197     /**
198      * This method provide a list of all the current container children
199      */

200     public org.omg.Components.Deployment.Container[]
201     get_containers()
202     {
203         //Retrieve all the ContainerManager connection
204
org.objectweb.openccm.OpenCCM_DCI.
205             ComponentServerManagerPackage.container_managersConnection
206             connect[]=getCS().get_connections_container_managers();
207         //build a container array
208
org.omg.Components.Deployment.Container[] cont=
209             new org.omg.Components.Deployment.Container[connect.length];
210         //Fill the container array
211
for(int i=0;i<connect.length;i++)
212             cont[i]=connect[i].objref.provide_container();
213         //return the array.
214
return cont;
215        
216     }
217
218     //
219
// IDL:omg.org/Components/Deployment/ComponentServer/remove:1.0
220
//
221
/***/
222     public void
223     remove()
224     throws org.omg.Components.RemoveFailure
225     {
226         if(!removed)
227             {
228                 removed=true;
229                 
230                 try
231                     {
232                         //unregister the componnentservermanager
233
get_context().get_connection_component_server_manager_registration()
234                             .unregister_component_server_manager(cookie);
235                         //retrieve all connection with containermanager
236
org.objectweb.openccm.OpenCCM_DCI.
237                             ComponentServerManagerPackage.container_managersConnection
238                             connect[]=getCS().get_connections_container_managers();
239                         
240                         //remove all the container
241
for(int i=0;i<connect.length;i++)
242                             connect[i].objref.remove();
243                         //remove the main segment
244
getCS().remove();
245                     }
246                 catch(Exception JavaDoc e )
247                     {
248                         System.out.println("Cannot disconnect ComponentServer/Node");
249                         e.printStackTrace();
250                         throw new org.omg.Components.RemoveFailure();
251                     }
252             }
253        
254     }
255   
256
257
258 }
259
Popular Tags