KickJava   Java API By Example, From Geeks To Geeks.

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


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.Deployment;
28
29 import org.omg.CosNaming.NameComponent JavaDoc;
30
31
32 public class AssemblyFactoryManagerServer
33        extends org.objectweb.openccm.corba.ApplicationServer
34 {
35     
36     // ==================================================================
37
//
38
// Internal state.
39
//
40
// ==================================================================
41
/*The factory name*/
42     private String JavaDoc factoryName;
43     /*The ior file path*/
44     private String JavaDoc factoryIORFilePath;
45     /*The NS registration name*/
46     private NameComponent JavaDoc[]ncomp ;
47     /**Reference on the current DCIManager*/
48     private org.objectweb.openccm.OpenCCM_DCI.DCIManager DCI ;
49     
50      
51     
52
53     // ==================================================================
54
//
55
// Internal methods.
56
//
57
// ==================================================================
58

59     private void
60     computeArgs(String JavaDoc args[])
61     {
62         for(int i=0;i<args.length;i++){
63             if(args[i].startsWith("FACTORYNAME="))
64                this.factoryName=args[i].substring(12);
65         }
66         factoryIORFilePath=System.getProperty("WorkDir")+"/"+factoryName+".IOR";
67     }
68     
69    // ==================================================================
70
//
71
// Constructor.
72
//
73
// ==================================================================
74

75     /**
76      ** The constructor.
77      **/

78     public
79     AssemblyFactoryManagerServer()
80     {
81         // Set EntityResolver for CCM DTDs
82
org.objectweb.ccm.descriptor.EntityResolver.setCCMResolver();
83     }
84
85     // ==================================================================
86
//
87
// Public methods.
88
//
89
// ==================================================================
90

91     /**
92      ** The bootstrap main method.
93      **
94      ** @param args The command-line arguments.
95      **/

96     public static void
97     main(String JavaDoc args[])
98     {
99         AssemblyFactoryManagerServer server = new AssemblyFactoryManagerServer();
100         /*ParameterConverter pc=new ParameterConverter();
101         int status = server.start(pc.convertParameter(args));*/

102         int status = server.start(args);
103         System.exit(status);
104     }
105
106     // ==================================================================
107
//
108
// Methods for the org.objectweb.openccm.corba.ApplicationServer.
109
//
110
// ==================================================================
111

112     /**
113      ** Before running the CORBA::ORB.
114      **
115      ** @param args The command line arguments.
116      **
117      ** @return The status.
118      **/

119     public int
120     before_run(String JavaDoc[] args)
121     {
122        
123     try{
124         
125         computeArgs(args);
126             
127         //Initialize the ORB
128
org.objectweb.openccm.Components.Runtime.init(org.objectweb.openccm.corba.TheORB.getORB());
129         //Retrive the DCI reference
130
DCI=
131             org.objectweb.openccm.
132             OpenCCM_DCI.DCIManagerHelper.
133             narrow(org.objectweb.openccm.corba
134                    .TheORB.resolve_initial_reference("DCIManager"));
135         
136         //Retrieve a AssemblyFactoryManagerHome reference
137
org.objectweb.openccm.OpenCCM_DCI.AssemblyFactoryManagerHome AFMH=
138             org.objectweb.openccm.OpenCCM_DCI.AssemblyFactoryManagerHomeHelper.
139             narrow((new DeploymentComponentFactory()).
140                    install_home
141                    ("org.objectweb.openccm.OpenCCM_DCI.cif.AssemblyFactoryManagerHomeImpl.create_home"));
142         
143         //Create an AssemblyFactoryManager
144
org.objectweb.openccm.OpenCCM_DCI.AssemblyFactoryManager AFM=
145             AFMH.create();
146         //Retrieve a AssemblyManagerHome reference
147
org.objectweb.openccm.OpenCCM_DCI.AssemblyManagerHome AMH=
148             org.objectweb.openccm.OpenCCM_DCI.
149             AssemblyManagerHomeHelper.narrow
150             ((new DeploymentComponentFactory())
151              .install_home("org.objectweb.openccm.OpenCCM_DCI.cif.AssemblyManagerHomeImpl.create_home"));
152           
153         //Connect the AssemblyManagerHome to the AssemblyFactoryManager component
154
AFM.connect_assembly_manager_home(AMH);
155         // Plug the assemblyFactory interface needed for DCI::dci_deployment interface
156
DCI.connect_assembly_factory(AFM.provide_assembly_factory());
157         //Connect registration services
158
AFM.connect_home_registration(DCI.provide_home_registration());
159         // Connect the home finder service
160
AFM.connect_home_finder(DCI.provide_home_finder());
161         // AFM.connect_trader_service(DCI.provide_trader_service());
162
AFM.connect_dci_information(DCI.provide_dci_information());
163         //Configure complete the Assembly Factory Manager
164
AFM.configuration_complete();
165
166         
167          // Register the node if required
168
// if(registrationName!=null){
169
org.omg.CosNaming.NamingContextExt JavaDoc nce=
170                 org.omg.CosNaming
171                 .NamingContextExtHelper
172                 .narrow(org.objectweb.openccm.corba.TheNameService
173                         .getNamingContext().getNamingContext());
174             
175             String JavaDoc registrationName=
176                 System.getProperty("Assembly_factory_ns_dir")
177                 +factoryName;
178                         
179             ncomp=org.objectweb.ccm
180                 .descriptor.componentassembly.ccm
181                 .deployer.registrar.RegisterwithnamingDeployer
182                 .rebind(nce,registrationName,AFM);
183        /* org.objectweb.ccm
184                 .descriptor.componentassembly.ccm
185                 .RegisterwithnamingDeployer
186                 .rebind(nce,"AssemblyFactory",AFM.provide_assembly_factory());
187                 */

188          // }
189

190         // Output the IOR of the DCIManager.
191
org.objectweb.openccm.corba.TheORB.save_IOR(AFM, factoryIORFilePath);
192         
193         
194         return 0;
195     }
196     catch(Exception JavaDoc e){
197         e.printStackTrace();
198         System.out.println(e.getMessage());
199         
200     }
201     return 0;
202
203     }
204     
205     /**
206      ** After running the CORBA::ORB.
207      **/

208     public void
209     after_run()
210     {
211         try{
212             if(DCI!=null)
213                DCI.disconnect_assembly_factory();
214                
215             if(ncomp!=null){
216                 org.omg.CosNaming.NamingContextExt JavaDoc nce=
217                     org.omg.CosNaming
218                     .NamingContextExtHelper
219                     .narrow(org.objectweb.openccm.corba.TheNameService
220                             .getNamingContext().getNamingContext());
221                 
222                 nce.unbind(ncomp);
223                 
224                 System.err.println("The "+factoryName+" AssemblyFactory is unreferenced");
225             }
226         }
227         catch(Exception JavaDoc e)
228             {
229                 System.err.println("Cannot unbind The "+factoryName+"AssemblyFactory");
230             }
231     }
232     
233 }
234
Popular Tags