public Boot() {
}
public static Properties parseCmdLineArgs(String[] args) throws IllegalArgumentException {
Properties props = new ExtendedProperties();
int i = 0;
while (i < args.length) {
if (args[i].startsWith("-")) {
// Parse next option
// Switch options require special handling
if (args[i].equalsIgnoreCase("-version")) {
logger.log(Logger.INFO, "----------------------------------\n"+Runtime.getCopyrightNotice()+"----------------------------------------");
return null;
}
if (args[i].equalsIgnoreCase("-help")) {
printUsage();
return null;
}
if (args[i].equalsIgnoreCase("-container")) {
props.setProperty(Profile.MAIN, "false");
}
else if(args[i].equalsIgnoreCase("-"+Profile.LOCAL_SERVICE_MANAGER)) {
props.setProperty(Profile.LOCAL_SERVICE_MANAGER, "true");
}
else if (args[i].equalsIgnoreCase("-"+Profile.GUI)) {
props.setProperty(Profile.GUI, "true");
}
else if (args[i].equalsIgnoreCase("-"+Profile.NO_MTP)) {
props.setProperty(Profile.NO_MTP, "true");
}
// Options that can be specified in different ways require special handling
else if (args[i].equalsIgnoreCase("-name")) {
if (++i < args.length) {
props.setProperty(Profile.PLATFORM_ID, args[i]);
}
else {
throw new IllegalArgumentException("No platform name specified after \"-name\" option");
}
}
else if (args[i].equalsIgnoreCase("-mtp")) {
if (++i < args.length) {
props.setProperty(Profile.MTPS, args[i]);
}
else {
throw new IllegalArgumentException("No mtps specified after \"-mtp\" option");
}
}
// The -conf option requires special handling
else if (args[i].equalsIgnoreCase("-conf")) {
if (++i < args.length) {
// Some parameters are specified in a properties file
try {
props.load(args[i]);
}
catch (Exception e) {
if(logger.isLoggable(Logger.SEVERE))
logger.log(Logger.SEVERE, "WARNING: error loading properties from file "+args[i]+". "+e);
}
}
else {
throw new IllegalArgumentException("No configuration file name specified after \"-conf\" option");
}
}
// Default handling for all other properties
else {
String name = args[i].substring(1);
if (++i < args.length) {
props.setProperty(name, args[i]);
}
else {
throw new IllegalArgumentException("No value specified for property \""+name+"\"");
}
}
++i;
}
else {
// Get agents at the end of command line
if (props.getProperty(Profile.AGENTS) != null) {
if(logger.isLoggable(Logger.WARNING))
logger.log(Logger.WARNING,"WARNING: overriding agents specification set with the \"-agents\" option");
}
String agents = args[i];
props.setProperty(Profile.AGENTS, args[i]);
if (++i < args.length) {
if(logger.isLoggable(Logger.WARNING))
logger.log(Logger.WARNING,"WARNING: ignoring command line argument "+args[i]+" occurring after agents specification");
if (agents != null && agents.indexOf('(') != -1 && !agents.endsWith(")")) {
if(logger.isLoggable(Logger.WARNING))
logger.log(Logger.WARNING,"Note that agent arguments specifications must not contain spaces");
}
if (args[i].indexOf(':') != -1) {
if(logger.isLoggable(Logger.WARNING))
logger.log(Logger.WARNING,"Note that agent specifications must be separated by a semicolon character \";\" without spaces");
}
}
break;
}
}
// Consistency check
if ("true".equals(props.getProperty(Profile.NO_MTP)) && props.getProperty(Profile.MTPS) != null) {
if(logger.isLoggable(Logger.WARNING))
logger.log(Logger.WARNING,"WARNING: both \"-mtps\" and \"-nomtp\" options specified. The latter will be ignored");
props.remove(Profile.NO_MTP);
}
return props;
}