001: /*
002: * Copyright (C) 2001, 2002 Robert MacGrogan
003: *
004: * This library is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License as published by the Free Software Foundation; either
007: * version 2.1 of the License, or (at your option) any later version.
008: *
009: * This library is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: * Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public
015: * License along with this library; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: *
018: *
019: * $Archive: SourceJammer$
020: * $FileName: Client.java$
021: * $FileID: 4192$
022: *
023: * Last change:
024: * $AuthorName: Rob MacGrogan$
025: * $Date: 4/23/03 5:04 PM$
026: * $Comment: Replaced GPL header with LGPL header.$
027: *
028: * $KeyWordsOff: $
029: */
030:
031: package org.sourcejammer.client.commandline;
032:
033: import org.sourcejammer.util.*;
034: import org.sourcejammer.client.SourceJammerClient;
035:
036: /**
037: * Title: SourceJammer 1.1
038: * Description:
039: * Copyright: Copyright (c) 2002
040: * @author Rob MacGrogan
041: * @version $Revision: 1.4 $
042: */
043: /**
044: * This is the main class for the Command Line client.
045: */
046: public class Client {
047:
048: public static final String PROMPT = "sj ";
049:
050: public Client() {
051: }
052:
053: public static void main(String[] args) {
054: try {
055: //First, initialize local AppConfig using string arg.
056: String sConfPath = null;
057: String sServerURL = null;
058: if (args.length > 0) {
059: sConfPath = args[0];
060: }
061: if (args.length > 1) {
062: sServerURL = args[1];
063: } else {
064: throw new ConfigurationException(
065: "2nd argument must be server URL.");
066: }
067:
068: AppConfig.getInstance(sConfPath);
069: SourceJammerClient.getInstance(sConfPath);
070:
071: CommandLineInterpreter oInterpreter = new CommandLineInterpreter(
072: sServerURL);
073: CommandLine oCmd = new CommandLine();
074:
075: oCmd.println("SourceJammer CommandLine Client. V "
076: + SourceJammerClient.VERSION);
077: oCmd.println("For a list of commands, type help.");
078: oCmd.println("");
079:
080: boolean bExit = false;
081: while (!bExit) {
082: String sCommand = oCmd.getUserInput(PROMPT);
083: if (sCommand != null && !sCommand.equals("")) {
084: String sMessage = oInterpreter
085: .sendCommand(sCommand);
086: if (sMessage != null && !sMessage.equals("")) {
087: if (sMessage
088: .equals(CommandLineInterpreter.TERM_MESSAGE)) {
089: oCmd.println("Exiting . . .");
090: bExit = true;
091: } else {
092: oCmd.println(sMessage);
093: }
094: }
095: }
096: }
097:
098: } catch (Exception ex) {
099: ex.printStackTrace();
100: }
101: }
102: }
|