blob: 97af4f894712a547f95af1521fa8f9354d1937a8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
|
/**************************************************************************
* AbstractMain
*
* $Revision: 1.67 $
* $Date: 2004/10/25 15:27:35 $
*
* Copyright (C) 2001 CERN - European Organization for Nuclear Research
* All rights reserved.
**************************************************************************/
package com.c2kernel.process;
import java.io.File;
import java.io.FileOutputStream;
import java.io.PrintStream;
import com.c2kernel.utils.FileStringUtility;
import com.c2kernel.utils.Logger;
import com.c2kernel.utils.Resource;
/**************************************************************************
*
* @author $Author: abranson $ $Date: 2004/10/25 15:27:35 $
* @version $Revision: 1.67 $
**************************************************************************/
abstract public class AbstractMain
{
public static boolean runningAsWrapper = false;
/**************************************************************************
*
**************************************************************************/
static protected void usage()
{
System.out.println();
System.out.println("USAGE: com.c2kernel.process.AbstractMain \n" +
" -config <server/client config file> \n" +
" [-connect <LC connect file> ] (or LocalCentre in conf)\n" +
" [-resURL c2kernel/resources] (or KernelResourceURL in conf)\n" +
" [-domResURL domain/resources] (or DomainResourceURL in conf)\n" +
" [-h] [-help] \n" +
" [-logLevel 0-19] \n" +
" [-logFile <path to log file>]");
Logger.die("Initialisation error");
}
/**************************************************************************
* reading and setting the standard c2k input paramaters
**************************************************************************/
static public java.util.Properties readC2KArgs( String[] args )
{
int i = 0;
String configPath = null;
String connectPath = null;
java.util.Properties c2kProps = null;
int logLevel = 0;
PrintStream logStream = System.out;
String centreId = null;
try
{
if( args != null )
{
while( i < args.length )
{
if( args[i].equals("-h") || args[i].equals("-help") )
{
usage();
}
else if(args[i].equals("-config"))
{
if( (i+1) >= args.length )
{
System.out.println("AbstractMain::readC2KArgs() - argument expected " +
"for -config");
usage();
}
System.out.println("Config file: "+args[i+1]);
configPath = args[++i];
}
else if(args[i].equals("-connect"))
{
if( (i+1) < args.length ) // batch file will have no arg if no cmd line arg
{
connectPath = args[++i];
}
}
else if(args[i].equals("-logLevel"))
{
if( (i+1) >= args.length )
{
System.out.println("AbstractMain::readC2KArgs() - argument expected " +
"for -logLevel");
usage();
}
logLevel = Integer.parseInt(args[++i]);
}
else if(args[i].equals("-logFile"))
{
if( (i+1) >= args.length )
{
System.out.println("AbstractMain::readC2KArgs() - argument expected " +
"for -logFile");
usage();
}
logStream = new PrintStream(new FileOutputStream(args[++i], true));
}
else if(args[i].equals("-resURL"))
{
String resString = args[++i];
System.out.println("AbstractMain::readC2KArgs() - Resource location:" +
resString);
Resource.setKernelBaseURL(resString);
}
else if(args[i].equals("-domResURL"))
{
String resString = args[++i];
System.out.println("AbstractMain::readC2KArgs() - Domain resource location:" +
resString);
Resource.setDomainBaseURL(resString);
}
i++;
}
// Set up log stream
Logger.addLogStream(logStream, logLevel);
if (configPath == null) {
System.out.println("No config file specified");
usage();
}
// Load config & connect files into c2kprops
c2kProps = FileStringUtility.loadConfigFile( configPath );
if (connectPath == null) {
// see if LC is listed in the config
Logger.msg(6, "No connect file specified in arguments. Looking in config.");
centreId = c2kProps.getProperty("LocalCentre");
if (centreId!= null) connectPath = "connect/"+centreId+".clc";
}
if (connectPath != null) {
Logger.msg(6, "Connect file: "+connectPath);
if (centreId == null) {
String connectFileName = new File(connectPath).getName();
centreId = connectFileName.substring(0, connectFileName.lastIndexOf(".clc"));
c2kProps.setProperty("LocalCentre", centreId);
}
FileStringUtility.appendConfigFile( c2kProps, connectPath);
}
else {
System.out.println("No connect file specified in args nor config file. Cannot continue.");
usage();
}
}
else
{
System.out.println("AbstractMain::readC2KArgs() - no arguments!");
usage();
}
}
catch( Exception ex )
{
System.out.println("Main::readC2KArgs() - bad arguments! ");
ex.printStackTrace();
usage();
}
Logger.msg(7, "AbstractMain::standardSetUp() - readC2KArgs() DONE.");
return c2kProps;
}
/**************************************************************************
* Required for most of the client & server application
*
* reads arguments
* initialises C2K properties
* initialises ORB
* initialises VirtualTreeManager
* initialises EventValueFactory + ProxyEventValueFactory
* initialises
**************************************************************************/
static protected void standardSetUp(String[] args)
throws Exception
{
//Reads the C2Kernel arguments, and inits the Gateway with them
Gateway.init(readC2KArgs(args));
}
/**************************************************************************
*
**************************************************************************/
static protected void standardTearDown()
throws Exception
{
Gateway.close();
Logger.msg(5, "AbstractMain::standardTearDown() - DONE.");
}
}
|