KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > ccm > runtime > ComponentRuntimeMain


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.ccm.runtime;
31
32 import org.objectweb.corba.runtime.*;
33
34 /**
35  ** <p></p>
36  **/

37 public class ComponentRuntimeMain
38 {
39     static final private String JavaDoc _class_name = "ComponentRuntimeMain";
40
41     //
42
// public operations
43
//
44

45     static public ComponentRuntimeConfiguration
46     parseConfiguration(String JavaDoc[] args)
47     {
48         final String JavaDoc opname = "parseConfiguration";
49         ComponentRuntimeConfiguration config = new ComponentRuntimeConfiguration();
50
51         // parse command line
52
String JavaDoc uuid = null;
53         String JavaDoc suuids = null;
54         String JavaDoc rid = null;
55         String JavaDoc riorfile = null;
56         java.util.Vector JavaDoc virefs = new java.util.Vector JavaDoc();
57
58         for (int i=0;i<args.length;i++) {
59             if (args[i].equals("-ComponentUUID")) {
60                 uuid= args[i+1];
61                 i++;
62             }
63
64             if (args[i].equals("-ServiceUUIDs")) {
65                 suuids= args[i+1];
66                 i++;
67             }
68
69             if (args[i].equals("-RuntimeId")) {
70                 rid = args[i+1];
71                 i++;
72                 // NOTE: set it as a property also as it's used in the TheLogger class
73
java.lang.System.getProperties().setProperty("runtime.id", rid);
74             }
75
76             if (args[i].equals("-RuntimeIORFile")) {
77                 riorfile = args[i+1];
78                 i++;
79             }
80
81             if (args[i].equals("-ORBInitRef")) {
82                 virefs.add(args[i+1]);
83                 i++;
84             }
85
86         }
87     
88         // parse initial references
89
String JavaDoc[] irefs = (String JavaDoc[])virefs.toArray(new String JavaDoc[0]);
90         org.coach.ECM.DegeneratedServiceRef[] dsrefs = new org.coach.ECM.DegeneratedServiceRef[irefs.length];
91         StringifiedInitialReference[] sirefs = new StringifiedInitialReference[irefs.length];
92
93         int idx = 0;
94         for (int i=0;i<irefs.length;i++) {
95             // normally, an initial reference has the following format:
96
// "<reg_name>=<ref_ior>"
97

98             String JavaDoc msg = "initial reference found: "+irefs[i];
99             TheLogger.debug(_class_name, opname, msg);
100
101             // look for the "="
102
idx = irefs[i].indexOf("=");
103             dsrefs[i] = new org.coach.ECM.DegeneratedServiceRef();
104             dsrefs[i].corba_type = "unknown";
105             dsrefs[i].orb_registration_name = irefs[i].substring(0, idx);
106             dsrefs[i].initial_reference = irefs[i].substring(idx+1);
107
108             sirefs[i] = new StringifiedInitialReference();
109             sirefs[i].name = dsrefs[i].orb_registration_name;
110             sirefs[i].ref = dsrefs[i].initial_reference;
111         }
112
113         // store
114
config.implementation_uuid = uuid;
115         config.runtime_id = rid;
116         config.runtime_iorfile = riorfile;
117         config.dservice_refs = dsrefs;
118         config.initial_references = sirefs;
119
120         // check if some service uuids are set
121
if (suuids==null) {
122             return config;
123         }
124
125         // break the string
126
java.util.Vector JavaDoc vuuids = new java.util.Vector JavaDoc();
127         idx = suuids.indexOf(',');
128         String JavaDoc pattern = "";
129         while (idx!=-1) {
130             pattern = suuids.substring(0, idx);
131             if (!pattern.equals("")) {
132                 vuuids.add(pattern);
133             }
134
135             suuids = suuids.substring(idx+1);
136             idx = suuids.indexOf(',');
137         }
138
139         vuuids.add(suuids);
140
141         // store
142
config.service_uuids = (String JavaDoc[])vuuids.toArray(new String JavaDoc[0]);
143         return config;
144     }
145
146     //
147
// main
148
//
149

150     static public void
151     main(String JavaDoc[] args)
152     {
153         final String JavaDoc opname = "main";
154         // log a start message
155
TheLogger.log(_class_name, opname, "Loading home");
156
157         // parse config
158
ComponentRuntimeConfiguration config = parseConfiguration(args);
159
160         // load servant
161
ComponentRuntime.loadHome(config);
162
163         // log a end message
164
TheLogger.log(_class_name, opname, "Home loaded");
165
166         System.err.println("Launcher waiting for this usefull message ...");
167         System.out.println("... or for this one ? :o(");
168     }
169 }
170
Popular Tags