KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*====================================================================
2
3 OpenCCM: The Open CORBA Component Model Platform
4 Copyright (C) 2000-2002 USTL - LIFL - GOAL
5 Contact: openccm-team@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): Raphael Marvie, Philippe Merle.
23 Contributor(s): Mathieu Vadet______________________________________.
24
25 ====================================================================*/

26
27 package org.objectweb.openccm.Deployment;
28
29 /**
30  * This class implements the Component Server main.
31  *
32  * @author <a HREF="mailto:Raphael.Marvie@lifl.fr">Raphael Marvie</a>
33  * <a HREF="mailto:Philippe.Merle@lifl.fr">Philippe Merle</a>
34  * <a HREF="mailto:Mathieu.Vadet@lifl.fr">Mathieu Vadet</a>
35  *
36  * @version 0.3
37  */

38
39 public class ServerMain
40        extends org.objectweb.openccm.corba.ApplicationServer
41 {
42     // ==================================================================
43
//
44
// Internal state.
45
//
46
// ==================================================================
47

48     /**
49      ** To store the component server name.
50      **/

51     protected String JavaDoc name_ = null;
52
53     // ==================================================================
54
//
55
// Constructor.
56
//
57
// ==================================================================
58

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

62     public
63     ServerMain()
64     {
65     }
66
67     // ==================================================================
68
//
69
// Internal methods.
70
//
71
// ==================================================================
72

73     // ==================================================================
74
//
75
// Public methods.
76
//
77
// ==================================================================
78

79     /**
80      ** The bootstrap main method.
81      **
82      ** @param args The command-line arguments.
83      **/

84     public static void
85     main(String JavaDoc args[])
86     {
87     ServerMain server = new ServerMain();
88     int status = server.start(args);
89     System.exit(status);
90     }
91
92     // ==================================================================
93
//
94
// Methods for the org.objectweb.openccm.corba.ApplicationServer.
95
//
96
// ==================================================================
97

98     /**
99      ** Before running the CORBA::ORB.
100      **
101      ** @param args The command line arguments.
102      **
103      ** @return The status.
104      **/

105     public int
106     before_run(String JavaDoc[] args)
107     {
108     // Init the OpenCCM Components runtime.
109
org.objectweb.openccm.Components.Runtime.init();
110
111     // Check command-line arguments.
112
if(args.length < 1)
113     {
114         System.err.println("Usage: java " +
115                    getClass().getName() +
116                    " <serverName>");
117         return -1;
118     }
119
120     // Obtain the name of this server.
121
name_ = args[0];
122     String JavaDoc fileName = args[1];
123
124     // Create the server servant.
125
ServerImpl server = new ServerImpl();
126
127     // Activate it.
128
// TODO: Must be changed!!!
129
org.omg.CORBA.Object JavaDoc ref =
130             server._this_object(org.objectweb.openccm.corba.TheORB.getORB());
131     Server serverRef = ServerHelper.narrow(ref);
132
133     // Obtain the Name Service.
134
org.objectweb.openccm.corba.NamingContext ns =
135         org.objectweb.openccm.corba.TheNameService.getNamingContext();
136
137     // Bind the server object in the name service.
138
ns.rebind(name_, serverRef);
139     
140         // Output the IOR of the ComponentServer.
141
org.objectweb.openccm.corba.TheORB.save_IOR(serverRef, fileName);
142
143     // Return OK.
144
System.out.println("The OpenCCM Java Component Server 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
Popular Tags