KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > corba > runtime > RuntimeMain


1 // ====================================================================
2
//
3
// ECM: The Extensible Container Model
4
// Copyright (C) 2004 THALES
5
// Contact: openccm-ecm@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): Mathieu Vadet.
23
// Initial Funding: IST COACH European project (IST-2001-34445)
24
// http://www.ist-coach.org
25
//
26
// ====================================================================
27

28
29
30 package org.objectweb.corba.runtime;
31
32 /**
33  ** <p>The <tt>RuntimeMain</tt> class allows to boot a CORBA object (implemented using the
34  ** system component framework) using the <tt>Runtime.loadServant</tt> operation. The parameters
35  ** are extracted from the command line information.</p>
36  **
37  ** <p>In its current state, the following information must/may be provided:</p>
38  ** <li>
39  ** <ul>Servant JAR location (mandatory) through the Java <tt>archive.location</tt> system property or
40  ** through the "-ArchiveLocation location" option on the command line.</ul>
41  ** <ul>Servant entrypoint (mandatory) through the Java <tt>archive.entrypoint</tt> system property or
42  ** through the "-ArchiveEntrypoint entrypt" option on the command line.</ul>
43  ** <ul>Initial references (optional) through "-ORBInitRef regname=ior" option on the command line.</ul>
44  ** <ul>System services (optional) through "-SystemService serviceid=entrypoint" option on the command line.</ul>
45  ** <ul>Runtime identity (mandatory) through the Java <tt>runtime.id</tt> system property or
46  ** through the "-RuntimeId rid" option on the command line.</ul>
47  ** </li>
48  **
49  ** @see org.objectweb.corba.runtime.Runtime Runtime
50  **/

51 public class RuntimeMain
52 {
53     static final private String JavaDoc _class_name = "RuntimeMain";
54
55     //
56
// public operation
57
//
58

59     static public RuntimeConfiguration
60     parseConfiguration(String JavaDoc[] args)
61     {
62         String JavaDoc opname = "parseConfiguration";
63
64         RuntimeConfiguration config = new RuntimeConfiguration();
65
66         // obtain initial references passed on the command line
67
// and default system services
68
java.util.Vector JavaDoc virefs = new java.util.Vector JavaDoc();
69         java.util.Vector JavaDoc vservices = new java.util.Vector JavaDoc();
70
71         // obtain archive location and entrypoint
72
// NOTE: may also be set with java properties
73
// get root object archive location and entrypoint from System properties
74
String JavaDoc location = System.getProperty("archive.location");
75         String JavaDoc entrypt = System.getProperty("archive.entrypoint");
76
77         // parse args
78
for (int i=0;i<args.length;i++) {
79             if (args[i].equals("-ORBInitRef")) {
80                 virefs.add(args[i+1]);
81                 i++;
82             }
83
84             if (args[i].equals("-SystemService")) {
85                 vservices.add(args[i+1]);
86                 i++;
87             }
88
89             if (args[i].equals("-ArchiveLocation")) {
90                 location = args[i+1];
91                 i++;
92             }
93
94             if (args[i].equals("-ArchiveEntrypoint")) {
95                 entrypt = args[i+1];
96                 i++;
97             }
98
99             if (args[i].equals("-RuntimeId")) {
100                 // set as a property
101
System.setProperty("runtime.id", args[i+1]);
102                 i++;
103             }
104         }
105     
106         // parse initial references
107
String JavaDoc[] irefs = (String JavaDoc[])virefs.toArray(new String JavaDoc[0]);
108         StringifiedInitialReference[] sirefs = new StringifiedInitialReference[irefs.length];
109
110         int idx = 0;
111         for (int i=0;i<irefs.length;i++) {
112             // normally, an initial reference has the following format:
113
// "<reg_name>=<ref_ior>"
114

115             //String msg = "initial reference found: "+irefs[i];
116
//TheLogger.debug(_class_name, opname, msg);
117

118             // look for the "="
119
idx = irefs[i].indexOf("=");
120             sirefs[i] = new StringifiedInitialReference();
121             sirefs[i].name = irefs[i].substring(0, idx);
122             sirefs[i].ref = irefs[i].substring(idx+1);
123         }
124
125         // store
126
config.stringified_initial_references = sirefs;
127
128         // parse default system services
129
String JavaDoc[] services = (String JavaDoc[])vservices.toArray(new String JavaDoc[0]);
130         String JavaDoc[] service_ids = new String JavaDoc[services.length];
131         String JavaDoc[] service_entrypts = new String JavaDoc[services.length];
132
133         idx = 0;
134         for (int i=0;i<services.length;i++) {
135             // normally, an default system service has the following format:
136
// "<service_id>=<entrypoint>"
137

138             //String msg = "default system service found: "+services[i];
139
//TheLogger.debug(_class_name, opname, msg);
140

141             // look for the "="
142
idx = services[i].indexOf("=");
143             service_ids[i] = services[i].substring(0, idx);
144             service_entrypts[i] = services[i].substring(idx+1);
145         }
146
147         // store
148
config.service_ids = service_ids;
149         config.service_entrypts = service_entrypts;
150
151         // NOTE: if the location is non-local, the archive should be downloaded first
152
// not necessary at this stage, but should be done
153
config.archive_location = location;
154         config.archive_entrypoint = entrypt;
155
156         //
157
return config;
158     }
159
160     //
161
// main
162
//
163

164     static public void
165     main(String JavaDoc[] args)
166     {
167         // log a start message
168
String JavaDoc opname = "main";
169         TheLogger.debug(_class_name, opname, "Loading ...");
170
171         // parse config
172
RuntimeConfiguration config = parseConfiguration(args);
173
174         // check if entrypoint ends with ".main"
175
// in that case, it's not a servant, but a main
176
// NOTE: it's just a dirty code to be able to start main without requiring
177
// servant types and so on
178
if (config.archive_entrypoint.endsWith(".main")) {
179             Runtime.loadMain(config);
180             // log a end message
181
TheLogger.debug(_class_name, opname, "Main loaded");
182         }
183         else {
184             // load servant
185
Servant serv = Runtime.loadServant(config);
186             // log a end message
187
TheLogger.debug(_class_name, opname, "Servant loaded");
188         }
189
190         System.err.println("Launcher waiting for this usefull message ...");
191         System.out.println("... or for this one ? :o(");
192     }
193 }
194
Popular Tags