public int execute(Object opaque) {
if (! (opaque instanceof DeployerCLParser)) {
throw new IllegalArgumentException("Argument type is [" + opaque.getClass() + "]; expected [" + DeployerCLParser.class + "]");
}
DeployerCLParser parser = (DeployerCLParser) opaque;
ConsoleReader consoleReader = new StreamConsoleReader(System.in, System.out);
CommandMetaData commandMetaData = parser.getCommandMetaData();
CommandArgs commandArgs = parser.getCommandArgs();
if(commandMetaData == CommandFileCommandMetaData.META_DATA) {
multipleCommands = true;
String arg = commandArgs.getArgs()[0];
File source = new File(arg);
if(!source.exists() || !source.canRead() || source.isDirectory()) {
processException(new DeploymentSyntaxException("Cannot read command file "+source.getAbsolutePath()));
} else {
try {
BufferedReader commands = new BufferedReader(new FileReader(source));
String line;
boolean oneFailed = false;
while((line = commands.readLine()) != null) {
line = line.trim();
if(!line.equals("")) {
String[] lineArgs = splitCommand(line);
if(failed) {
oneFailed = true;
}
failed = false;
execute(lineArgs);
}
}
failed = oneFailed;
} catch (IOException e) {
processException(new DeploymentException("Unable to read command file", e));
} finally {
try {
con.close();
} catch (DeploymentException e) {
processException(e);
}
}
}
} else {
DeployCommand dc = commands.get(commandMetaData);
if(dc == null) {
try {
consoleReader.printNewline();
} catch (IOException e) {
}
processException(new DeploymentSyntaxException("No such command: '"+commandMetaData+"'"));
} else {
try {
if (con == null) {
if (parser.isOffline()) {
con = new OfflineServerConnection(kernel, true);
} else {
con = new OnlineServerConnection(parser, consoleReader, deploymentFactory);
}
}