ParsedOptions ret = new ParsedOptions();
ret.clientArguments = clientArguments;
final int argsLength = args.length;
String appClientConfig = "appclient.xml";
boolean clientArgs = false;
ProductConfig productConfig;
boolean hostSet = false;
for (int i = 0; i < argsLength; i++) {
final String arg = args[i];
try {
if (clientArgs) {
clientArguments.add(arg);
} else if (CommandLineConstants.VERSION.equals(arg) || CommandLineConstants.SHORT_VERSION.equals(arg)
|| CommandLineConstants.OLD_VERSION.equals(arg) || CommandLineConstants.OLD_SHORT_VERSION.equals(arg)) {
productConfig = new ProductConfig(Module.getBootModuleLoader(), SecurityActions.getSystemProperty(ServerEnvironment.HOME_DIR));
System.out.println(productConfig.getPrettyVersionString());
return null;
} else if (CommandLineConstants.HELP.equals(arg) || CommandLineConstants.SHORT_HELP.equals(arg) || CommandLineConstants.OLD_HELP.equals(arg)) {
usage();
return null;
} else if (CommandLineConstants.PROPERTIES.equals(arg) || CommandLineConstants.OLD_PROPERTIES.equals(arg)
|| CommandLineConstants.SHORT_PROPERTIES.equals(arg)) {
// Set system properties from url/file
if (!processProperties(arg, args[++i])) {
return null;
}
} else if (arg.startsWith(CommandLineConstants.PROPERTIES)) {
String urlSpec = parseValue(arg, CommandLineConstants.PROPERTIES);
if (urlSpec == null || !processProperties(arg, urlSpec)) {
return null;
}
} else if (arg.startsWith(CommandLineConstants.SHORT_PROPERTIES)) {
String urlSpec = parseValue(arg, CommandLineConstants.SHORT_PROPERTIES);
if (urlSpec == null || !processProperties(arg, urlSpec)) {
return null;
}
} else if (arg.startsWith(CommandLineConstants.OLD_PROPERTIES)) {
String urlSpec = parseValue(arg, CommandLineConstants.OLD_PROPERTIES);
if (urlSpec == null || !processProperties(arg, urlSpec)) {
return null;
}
} else if (arg.equals(CommandLineConstants.SHORT_HOST) || arg.equals(CommandLineConstants.HOST)) {
if(ret.propertiesFile != null) {
throw AppClientMessages.MESSAGES.cannotSpecifyBothHostAndPropertiesFile();
}
hostSet = true;
String urlSpec = args[++i];
ret.hostUrl = urlSpec;
} else if (arg.startsWith(CommandLineConstants.SHORT_HOST)) {
if(ret.propertiesFile != null) {
throw AppClientMessages.MESSAGES.cannotSpecifyBothHostAndPropertiesFile();
}
hostSet = true;
String urlSpec = parseValue(arg, CommandLineConstants.SHORT_HOST);
ret.hostUrl = urlSpec;
} else if (arg.startsWith(CommandLineConstants.HOST)) {
if(ret.propertiesFile != null) {
throw AppClientMessages.MESSAGES.cannotSpecifyBothHostAndPropertiesFile();
}
hostSet = true;
String urlSpec = parseValue(arg, CommandLineConstants.HOST);
ret.hostUrl = urlSpec;
} else if (arg.startsWith(CommandLineConstants.CONNECTION_PROPERTIES)) {
if(hostSet) {
throw AppClientMessages.MESSAGES.cannotSpecifyBothHostAndPropertiesFile();
}
String fileUrl = parseValue(arg, CommandLineConstants.CONNECTION_PROPERTIES);
ret.propertiesFile = fileUrl;
}else if (arg.startsWith(CommandLineConstants.SYS_PROP)) {
// set a system property
String name, value;
int idx = arg.indexOf("=");
if (idx == -1) {
name = arg.substring(2);
value = "true";
} else {
name = arg.substring(2, idx);
value = arg.substring(idx + 1, arg.length());
}
systemProperties.setProperty(name, value);
SecurityActions.setSystemProperty(name, value);
} else if (arg.startsWith(CommandLineConstants.APPCLIENT_CONFIG)) {
appClientConfig = parseValue(arg, CommandLineConstants.APPCLIENT_CONFIG);
} else {
if (arg.startsWith("-")) {
System.out.println(MESSAGES.unknownOption(arg));
usage();
return null;
}
clientArgs = true;
clientArguments.add(arg);
}
} catch (IndexOutOfBoundsException e) {
System.err.println(MESSAGES.argumentExpected(arg));
usage();
return null;
}
}
String hostControllerName = null; // No host controller unless in domain mode.
productConfig = new ProductConfig(Module.getBootModuleLoader(), SecurityActions.getSystemProperty(ServerEnvironment.HOME_DIR));
ret.environment = new ServerEnvironment(hostControllerName, systemProperties, systemEnvironment, appClientConfig, launchType, null, productConfig);
return ret;
}