}
}
public void parse(Vector<CommandLineArgument[]> commandList) throws Exception {
this.commandList = commandList;
CommandLineArgument lastArg = null;
boolean found = false;
int remainingValueCount = 0;
for (int i = 0; i < args.length; i++) {
if (args[i] == null)
continue;
found = false;
for (int j = 0; j < commandList.size() && !found; j++) {
CommandLineArgument[] extArg = (CommandLineArgument[]) commandList.get(j);
for (int k = 0; k < extArg.length && !found; k++)
if (args[i].compareToIgnoreCase(extArg[k].getName()) == 0) {
// check if previous keyword satisfied its required no.
// of parameters
if (remainingValueCount > 0) {
throw new Exception(
"Missing parameters for keyword '"
+ lastArg.getName() + "'.");
}
// process this keyword
lastArg = extArg[k];
lastArg.setEnabled(true);
found = true;
args[i] = null;
remainingValueCount = lastArg.getNumOfArguments();
}
}
// check if current string is a keyword preceded by '-'
if (args[i] != null && args[i].startsWith("-")) {
continue;
}
// check if there is no more expected param value
if (lastArg != null && remainingValueCount == 0) {
continue;
}
// check if consume remaining for last matched keywords
if (!found && lastArg != null) {
if (lastArg.getPattern() == null
|| lastArg.getPattern().matcher(args[i]).find()) {
lastArg.getArguments().add(args[i]);
if (remainingValueCount > 0) {
remainingValueCount--;
}
args[i] = null;
} else {
throw new Exception(lastArg.getErrorMessage());
}
}
}
// check if the last keyword satified its no. of parameters.
if (lastArg != null && remainingValueCount > 0) {
throw new Exception("Missing parameters for keyword '"
+ lastArg.getName() + "'.");
}
// check if there is some unknown keywords
for (int i = 0; i < args.length; i++) {
if (args[i] != null) {