KickJava   Java API By Example, From Geeks To Geeks.

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


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 DCIManagerServer extends org.objectweb.openccm.corba.ApplicationServer
33 {
34     
35     // ==================================================================
36
//
37
// Internal state.
38
//
39
// ==================================================================
40
/*The name of the DCI*/
41     private String JavaDoc dciName;
42     /*The path to used to save the DCI IOR */
43     private String JavaDoc dciIORFilePath;
44     /*the registratio name*/
45     private NameComponent JavaDoc[] ncomp;
46     /*The home finder name component */
47     private NameComponent JavaDoc[] ncompHF;
48     /*The home finder name component */
49     private NameComponent JavaDoc[] ncompHR;
50     
51     /*Reference of the started DCI*/
52     private org.objectweb.openccm.OpenCCM_DCI.DCIManager DCI ;
53     // ==================================================================
54
//
55
// Constructor.
56
//
57
// ==================================================================
58

59     /**
60      ** The constructor.
61      **/

62     public
63     DCIManagerServer()
64     {
65         // Set EntityResolver for CCM DTDs
66
org.objectweb.ccm.descriptor.EntityResolver.setCCMResolver();
67     }
68
69     // ==================================================================
70
//
71
// Internal methods.
72
//
73
// ==================================================================
74

75     private void
76     computeArgs(String JavaDoc args[])
77     {
78         for(int i=0;i<args.length;i++){
79             if(args[i].startsWith("DCINAME="))
80                this.dciName=args[i].substring(8);
81             else if(args[i].startsWith("IORPATH="))
82                 this.dciIORFilePath=args[i].substring(8);
83                }
84     }
85     
86     // ==================================================================
87
//
88
// Public methods.
89
//
90
// ==================================================================
91

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

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

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

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

120     public int
121     before_run(String JavaDoc[] args)
122     {
123         //used to retrieve in the right order all the needed parameter
124
computeArgs(args);
125         
126         try{
127             //Initialize the ORB
128
org.objectweb.openccm.Components.Runtime.init(org.objectweb.openccm.corba.TheORB.getORB());
129             
130         
131         //Retrieve a DCIManagerHome reference
132
org.objectweb.openccm.OpenCCM_DCI.DCIManagerHome DCIHome=
133                 org.objectweb.openccm.OpenCCM_DCI.DCIManagerHomeHelper.
134                 narrow((new DeploymentComponentFactory()).
135                        install_home("org.objectweb.openccm.OpenCCM_DCI.cif.DCIManagerHomeImpl.create_home"));
136             
137             //Create a DCIManager
138
DCI= DCIHome.create();
139             //Set the DCIName
140
DCI.dci_name(dciName);
141             
142             //Retrieve a AssemblyFactoryHome reference
143
org.objectweb.openccm.OpenCCM_DCI.AssemblyManagerModelHome AMMH=
144                 org.objectweb.openccm.OpenCCM_DCI.
145                 AssemblyManagerModelHomeHelper.
146                 narrow((new DeploymentComponentFactory()).
147                        install_home("org.objectweb.openccm.OpenCCM_DCI.cif.AssemblyManagerModelHomeImpl.create_home"));
148             //Connect the assembly manager model used to install assembly
149
DCI.connect_assembly_manager_model_home(AMMH);
150
151             org.omg.CosNaming.NamingContextExt JavaDoc nce=
152                 org.omg.CosNaming
153                 .NamingContextExtHelper
154                 .narrow(org.objectweb.openccm.corba.TheNameService
155                         .getNamingContext().getNamingContext());
156             DCI.connect_naming_service(nce);
157                                     
158             DCI.configuration_complete();
159             
160
161             
162           // if(registrationName!=null){
163

164            String JavaDoc registrationName=
165                 System.getProperty("DCI_ns_dir")
166                 +dciName;
167                 
168            ncomp=org.objectweb.ccm
169                     .descriptor.componentassembly.ccm
170                     .deployer.registrar.RegisterwithnamingDeployer
171                     .rebind(nce,registrationName,DCI);
172             //}
173
//register homefinder service
174
ncompHF=org.objectweb.ccm
175                 .descriptor.componentassembly.ccm
176                 .deployer.registrar.RegisterwithnamingDeployer
177                 .rebind(nce,"OpenCCM/Services/HomeFinder",DCI.provide_home_finder());
178             ncompHR=org.objectweb.ccm
179                 .descriptor.componentassembly.ccm
180                 .deployer.registrar.RegisterwithnamingDeployer
181                 .rebind(nce,"OpenCCM/Services/HomeRegistration",DCI.provide_home_registration());
182             
183             // Output the IOR of the DCIManager.
184
org.objectweb.openccm.corba.TheORB.save_IOR(DCI,dciIORFilePath);
185             
186             return 0;
187         }
188         catch(Exception JavaDoc e){
189             e.printStackTrace();
190             System.out.println(e.getMessage());
191         }
192         return 0;
193         
194     }
195     
196     /**
197      ** After running the CORBA::ORB.
198      **/

199     public void
200     after_run()
201     {
202         try{
203             if(ncomp!=null){
204                 org.omg.CosNaming.NamingContextExt JavaDoc nce=
205                     org.omg.CosNaming
206                     .NamingContextExtHelper
207                     .narrow(org.objectweb.openccm.corba.TheNameService
208                             .getNamingContext().getNamingContext());
209                 
210                 nce.unbind(ncomp);
211                 nce.unbind(ncompHR);
212                 nce.unbind(ncompHF);
213                 System.err.println("The "+dciName+" DCI is unreferenced");
214             }
215         }
216         catch(Exception JavaDoc e)
217             {
218                 System.err.println("Cannot unbind The "+dciName+" DCI");
219             }
220             
221
222     }
223     
224 }
225
Popular Tags