KickJava   Java API By Example, From Geeks To Geeks.

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


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 AssemblyFactory facet provided by
34  * AssemblyFactoryManager component.
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 AssemblyFactorySegImpl
42   extends org.objectweb.openccm.OpenCCM_DCI.
43   AssemblyFactoryManagerSessionComposition.AssemblyFactorySeg
44 {
45     // ==================================================================
46
//
47
// Internal state
48
//
49
// ==================================================================
50
org.objectweb.openccm.OpenCCM_DCI.AssemblyFactoryManagerCCM AFM;
51  
52
53     // ==================================================================
54
//
55
// Internal method
56
//
57
// ==================================================================
58

59     // ==================================================================
60
//
61
// Constructor.
62
//
63
// ==================================================================
64
public AssemblyFactorySegImpl(){
65         super();
66     }
67     
68     // ==================================================================
69
//
70
// Public methods.
71
//
72
// ==================================================================
73
public void
74     setup()
75     {
76         AFM=(org.objectweb.openccm.OpenCCM_DCI.AssemblyFactoryManagerCCM)
77             get_context();
78     }
79     
80     // ==================================================================
81
//
82
// AssemblyFactory methods.
83
//
84
// ==================================================================
85

86     /**
87      * This method create an assembly taking in parameter a
88      * assembly file location.
89      * @param assembly_loc The assembly location
90      */

91     public org.omg.Components.Cookie
92     create_assembly(String JavaDoc assembly_loc)
93     throws org.omg.Components.Deployment.InvalidLocation,
94            org.omg.Components.CreateFailure
95     {
96         try{
97             //instantiate the assembly manager
98
org.objectweb.openccm.OpenCCM_DCI.AssemblyManager am=
99                 AFM.get_connection_assembly_manager_home()
100                 .create_assembly_manager(assembly_loc);
101           
102             //connect the homefinder service
103
am.connect_home_finder(AFM.get_connection_home_finder());
104             //connect the HomeRegistration interface
105
am.connect_home_registration(AFM.get_connection_home_registration());
106             //connect the nameservice service
107
am.connect_naming_service(AFM.get_connection_naming_service());
108             //connect the trading service
109
//am.connect_trader_service(AFM.get_connection_trader_service());
110
am.connect_dci_information(AFM.get_connection_dci_information());
111             //connect the AssemblyManagerRegistration interface
112
am.connect_assembly_manager_registration(AFM.provide_assembly_manager_registration());
113             //configure complete the AssemblyManager
114
// This one will register itself with AssemblyManagerRegistration
115
// and will be connect to AssemblyFactoryManager
116
am.configuration_complete();
117             //Retrieve all connection on AssemblyManager
118
org.objectweb.openccm.OpenCCM_DCI.
119                 AssemblyFactoryManagerPackage.assembly_managersConnection
120                 connect[]=AFM.get_connections_assembly_managers();
121             // Compare AssemblyManager ref to retrieve connection cookie
122
for(int i=0;i<connect.length;i++){
123                 if(connect[i].objref._is_equivalent(am))
124                     return connect[i].ck;
125             }
126             
127         }
128         catch(Exception JavaDoc e){
129             e.printStackTrace();
130             System.err.println(e.getMessage());
131             System.err.println("Cannot create the assembly");
132       }
133         throw new org.omg.Components.CreateFailure();
134     }
135
136     
137     /**
138      * org.omg.Components.Deployment.Assembly lookup method
139      * implementation. Returned the assembly binded to the
140      * cookie
141      * @param c The assembly cookie
142      * @return The assembly found
143      */

144     public org.omg.Components.Deployment.Assembly
145     lookup(org.omg.Components.Cookie c)
146     throws org.omg.Components.Deployment.InvalidAssembly
147     {
148         //Retrieve all the AssemblyManagerconnection
149
org.objectweb.openccm.OpenCCM_DCI.
150             AssemblyFactoryManagerPackage.assembly_managersConnection
151             connect[]=AFM.get_connections_assembly_managers();
152         //Compare all cookie to find the right assembly
153
for(int i=0;i<connect.length;i++)
154             {
155                 if(connect[i].ck.equals(c))
156                     return connect[i].objref.provide_assembly();
157             }
158         //The assembly was not found due to a bad cookie
159
throw new org.omg.Components.Deployment.InvalidAssembly();
160     }
161     
162     /**
163      * org.omg.Components.Deployment.Assembly destroy(cookie c) method
164      * implementation. Destroy the assembly binded to the given in
165      * parameter cookie.
166      * @param c The Assembly cookie
167      */

168     public void
169     destroy(org.omg.Components.Cookie c)
170     throws org.omg.Components.Deployment.InvalidAssembly,
171            org.omg.Components.RemoveFailure
172     {
173         //Retrieve all AssemblyManager connections.
174
org.objectweb.openccm.OpenCCM_DCI.
175             AssemblyFactoryManagerPackage.assembly_managersConnection
176             connect[]=AFM.get_connections_assembly_managers();
177         //Compare all connection cookie to found the right
178
// AssemblyManager and remove it.
179
for(int i=0;i<connect.length;i++){
180             if(connect[i].ck.equals(c))
181               connect[i].objref.remove();
182         }
183     }
184
185
186     // ==================================================================
187
//
188
// AssemblyFactoryExt methods.
189
//
190
// ==================================================================
191

192     
193     /**
194      * This method create an assembly taking in parameter a
195      * the XML code to process.
196      * @param xml the assembly descriptor XML code.
197      */

198     public org.omg.Components.Cookie
199     create_assembly_XML(java.lang.String JavaDoc xml)
200     throws org.omg.Components.CreateFailure
201     {
202
203         try{
204             // create the AssemblyManager
205
org.objectweb.openccm.OpenCCM_DCI.AssemblyManager am=
206                 AFM.get_connection_assembly_manager_home()
207                 .create_assembly_manager_xml(xml);
208                         //connect the homefinder service
209
am.connect_home_finder(AFM.get_connection_home_finder());
210             //connect the HomeRegistration interface
211
am.connect_home_registration(AFM.get_connection_home_registration());
212             //connect the nameservice service
213
am.connect_naming_service(AFM.get_connection_naming_service());
214             //connect the trading service
215
//am.connect_trader_service(AFM.get_connection_trader_service());
216
am.connect_dci_information(AFM.get_connection_dci_information());
217             //connect the AssemblyManagerRegistration interface
218
am.connect_assembly_manager_registration(AFM.provide_assembly_manager_registration());
219             //configure complete the AssemblyManager
220
// This one will register itself with AssemblyManagerRegistration
221
// and will be connect to AssemblyFactoryManager
222
am.configuration_complete();
223             //Retrieve all connection on AssemblyManager
224
org.objectweb.openccm.OpenCCM_DCI.
225                 AssemblyFactoryManagerPackage.assembly_managersConnection
226                 connect[]=AFM.get_connections_assembly_managers();
227             // Compare AssemblyManager ref to retrieve connection cookie
228
for(int i=0;i<connect.length;i++){
229                 if(connect[i].objref._is_equivalent(am))
230                     return connect[i].ck;
231             }
232            
233         }
234         catch(Exception JavaDoc e){
235             e.printStackTrace();
236             System.err.println(e.getMessage());
237             System.err.println("Cannot create the assembly");
238         }
239         
240         throw new org.omg.Components.CreateFailure();
241     }
242     
243     /**
244      * This method allow to retrieve the AssemblyManager binded
245      * with the given in parameter cookie.
246      * @param c The AssemblyManager cookie
247      * @return The AssemblyManager found.
248      */

249     public org.objectweb.openccm.OpenCCM_DCI.AssemblyManager
250     lookup_assembly_manager(org.omg.Components.Cookie c)
251     throws org.omg.Components.Deployment.InvalidAssembly
252     {
253         //Retrieve all the AssemblyManagerConnections
254
org.objectweb.openccm.OpenCCM_DCI.
255             AssemblyFactoryManagerPackage.assembly_managersConnection
256             connect[]=AFM.get_connections_assembly_managers();
257         //Compare all cookie to found the right AssemblyManager
258
for(int i=0;i<connect.length;i++){
259             if(connect[i].ck.equals(c))
260                 return (org.objectweb.openccm.OpenCCM_DCI.AssemblyManager)
261                     connect[i].objref;
262         }
263         //The AssemblyManager was not found due to a bad cookie.
264
throw new org.omg.Components.Deployment.InvalidAssembly();
265     }
266     
267     /**
268      * Destroy the current assembly factory manager including
269      * all the created assembly managers
270      */

271      public void
272      destroy_assembly_factory()
273      throws org.omg.Components.RemoveFailure
274      {
275         //Retrieve all AssemblyManager connections.
276
org.objectweb.openccm.OpenCCM_DCI.
277             AssemblyFactoryManagerPackage.assembly_managersConnection
278             connect[]=AFM.get_connections_assembly_managers();
279         //Compare all connection cookie to found the right
280
// AssemblyManager and remove it.
281
for(int i=0;i<connect.length;i++){
282               connect[i].objref.remove();
283         }
284      }
285 }
286
Popular Tags