// Implements to CommandHandler.
public void execute(String[] args) {
// check session.
Session session = Session.getInstance();
if (session.getSessionID() != null) {
System.out.println("You must logout from previous session.");
return;
}
// parse command line parameters.
CommandLine commandLine = null;
try {
commandLine = new PosixParser().parse(new Options(), args);
} catch (ParseException e) {
printUsage(e.getMessage());
return;
}
// retrive login name.
// If login_name contains in command line, retrive from command line,
// otherwise, get it from console.
String loginName = null;
String[] buf = commandLine.getArgs();
if (buf.length > 0)
loginName = buf[0];
else
loginName = ConsoleUtil.readRequiredData("login name");
// get password from console.
String password = ConsoleUtil.readRequiredData("password");
try {
VfsService vfsService = VfsContext.getService();
session.setSessionID(vfsService.login(loginName, password));
String sessionID = session.getSessionID();
VfsFile home = vfsService.getVfsFile(sessionID, "-1", "Home");
if (home == null)
throw new IllegalStateException(
"User home directory not found.");
session.setCurrentDirectory(home);
System.out.println("SessionID = " + session.getSessionID());
System.out.println("Logged in.");
} catch (AuthenticationException e) {
System.out.println("login failed. (" + e.getMessage() + ")");
} catch (SessionException e) {
throw new IllegalStateException(