KickJava   Java API By Example, From Geeks To Geeks.

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


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 public class ServerActivatorMain extends org.objectweb.openccm.corba.ApplicationServer
30 {
31     
32     // ==================================================================
33
//
34
// Internal state.
35
//
36
// ==================================================================
37

38     /**
39      ** To store the component server name.
40      **/

41     protected String JavaDoc name_ ="ServerActivator";
42     
43     // ==================================================================
44
//
45
// Constructor.
46
//
47
// ==================================================================
48

49     /**
50      ** The constructor.
51      **/

52     public
53     ServerActivatorMain()
54     {
55     }
56     
57     
58     // ==================================================================
59
//
60
// Public methods.
61
//
62
// ==================================================================
63

64     /**
65      ** The bootstrap main method.
66      **
67      ** @param args The command-line arguments.
68      **/

69     public static void
70     main(String JavaDoc args[])
71     {
72     ServerActivatorMain server = new ServerActivatorMain();
73     int status = server.start(args);
74     System.exit(status);
75     }
76     
77     // ==================================================================
78
//
79
// Methods for the org.objectweb.openccm.corba.ApplicationServer.
80
//
81
// ==================================================================
82

83     /**
84      ** Before running the CORBA::ORB.
85      **
86      ** @param args The command line arguments.
87      ** args[0] nom de la machine locale
88      ** args[1] non du fichier a ecrire
89      **
90      ** @return The status.
91      **/

92     public int
93     before_run(String JavaDoc[] args)
94     {
95         // System.err.println("args[0]:"+args[0]+"args[1]:"+args[1]+"args[2]:"+args[2]+"args[3]:"+args[3]);
96
name_=name_+args[2];
97     // Init the OpenCCM Components runtime.
98
org.objectweb.openccm.Components.Runtime.init();
99     
100     // Create the server servant.
101
ServerActivatorImpl afi=null;
102     if(args[1].equalsIgnoreCase("pda_true"))
103         afi = new ServerActivatorImpl(args[2],args[3],true);
104     else afi = new ServerActivatorImpl(args[2],args[3]);
105     
106     // Activate it.
107
org.omg.CORBA.Object JavaDoc ref =
108         afi._this_object(org.objectweb.openccm.corba.TheORB.getORB());
109     
110     org.omg.Components.Deployment.ServerActivator serverRef =
111         org.omg.Components.Deployment.ServerActivatorHelper.narrow(ref);
112     
113     // Obtain the Name Service.
114
org.objectweb.openccm.corba.NamingContext ns =
115         org.objectweb.openccm.corba.TheNameService.getNamingContext();
116
117     // Bind the server object in the name service.
118
ns.rebind(name_, serverRef);
119     
120     // Output the IOR of the ServerActivator.
121
org.objectweb.openccm.corba.TheORB.save_IOR(serverRef, args[0]);
122     
123     try{
124             //setup componentinstallation for this JVM
125
org.omg.CosNaming.NameComponent JavaDoc[] ncomp
126                 = new org.omg.CosNaming.NameComponent JavaDoc[1];
127         
128         ncomp[0]= new org.omg.CosNaming.NameComponent JavaDoc("ComponentInstallation"+args[2],"");
129         
130         org.omg.CORBA.Object JavaDoc obj = org.objectweb.openccm.corba.TheNameService
131                                             .getNamingContext().getNamingContext().resolve(ncomp);
132         
133         org.omg.Components.Deployment.ComponentInstallation server_inst=
134         org.omg.Components.Deployment.ComponentInstallationHelper.narrow(obj);
135         
136         
137         server_inst.install("openccm_plugins", "file:"+args[3]+"/jar/OpenCCM_Plugins.jar");
138         
139         TheComponentInstallation.setComponentInstallation(server_inst);
140         }
141     catch(Exception JavaDoc e){ e.printStackTrace();}
142     
143     // Return OK.
144
System.out.println("The OpenCCM Server Activator ["+name_+"] is ready.");
145     return 0;
146     }
147     
148     /**
149      ** After running the CORBA::ORB.
150      **/

151     public void
152     after_run()
153     {
154     // Obtain the Name Service.
155
org.objectweb.openccm.corba.NamingContext ns =
156         org.objectweb.openccm.corba.TheNameService.getNamingContext();
157
158     // Unbind the server object from the name service.
159
ns.unbind(name_);
160     }
161     
162 }
163
Popular Tags