From: <ly...@us...> - 2004-01-03 10:57:10
|
Update of /cvsroot/jmule/jMule/src/org/jmule/ui/sacli In directory sc8-pr-cvs1:/tmp/cvs-serv16612/src/org/jmule/ui/sacli Modified Files: StandAloneCommandLineUI.java Log Message: first step towards transition to a Plugin/ui comclient Index: StandAloneCommandLineUI.java =================================================================== RCS file: /cvsroot/jmule/jMule/src/org/jmule/ui/sacli/StandAloneCommandLineUI.java,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** StandAloneCommandLineUI.java 12 Nov 2003 23:04:56 -0000 1.13 --- StandAloneCommandLineUI.java 3 Jan 2004 10:57:07 -0000 1.14 *************** *** 28,97 **** import org.jmule.util.MiscUtil; import org.jmule.core.internalCommunications.ComClient; - import org.jmule.core.internalCommunications.DirectComClient; import org.jmule.resource.Messages; import org.jmule.ui.sacli.controller.Command; ! public class StandAloneCommandLineUI extends Thread { ! BufferedReader input; ! CommandLineInterfaceParser clip; ! boolean doClose = false; ! ComClient comClient; ! final static String prompt = "jMule>"; ! public StandAloneCommandLineUI() { ! clip = new CommandLineInterfaceParser(); ! input = new BufferedReader(new InputStreamReader(System.in)); ! comClient = new DirectComClient(); ! System.out.println( ! "\n\n" + Messages.getString("Type 'help' to get a command overview. Welcome, share and enjoy.") + "\n"); ! //printStream = new PrintTeeStream(); ! } ! // Maybe we should just set the System.out and System.err in the TeeCLCommand ! //PrintTeeStream printStream; ! /* ! public PrintTeeStream getPrintTeeStream() { ! return printStream; ! } ! */ ! public void run() { ! while (!doClose) { ! System.out.print(prompt); ! try { ! String line = input.readLine(); ! processLine(line); ! } catch (Exception err) { ! /*printStream*/ ! System.err.println(err.getMessage()); ! //err.printStackTrace(); ! } ! } ! } ! public void processLine(String line) { ! if (!MiscUtil.isStrEmpty(line)) { ! try { ! Command cmd = clip.processLine(line); ! synchronized (this) { ! List outStrings = cmd.execute(comClient); ! MiscUtil.outStringList(outStrings); ! } ! } catch (ParseError perr) { ! //perr.printStackTrace(); ! /*printStream*/ ! System.err.println(perr.getMessage()); ! } catch (Exception err) { // throwed by execute ! // XXX: Don't catch this exception here but pass it on, top to the Main, so we get a full bugMe report ! if (MiscUtil.isStrEmpty(err.getMessage())) { ! System.err.println("Unexpected Exception occured, full stacktrace follows:"); ! err.printStackTrace(); ! } else ! /*printStream*/ ! System.err.println(err.getMessage()); ! } ! } ! } } --- 28,130 ---- import org.jmule.util.MiscUtil; + import org.jmule.core.Plugin; import org.jmule.core.internalCommunications.ComClient; import org.jmule.resource.Messages; import org.jmule.ui.sacli.controller.Command; ! public class StandAloneCommandLineUI extends Thread implements Plugin { ! private static StandAloneCommandLineUI singleton = null; ! BufferedReader input; ! CommandLineInterfaceParser clip; ! boolean doClose = false; ! ComClient comClient; ! final static String prompt = "jMule>"; ! // begin of user changable section ! public static final boolean defaultEnabled = false; ! private boolean enabled = defaultEnabled; ! /** @see org.jmule.core.Plugin#isEnabled() */ ! public boolean isEnabled() { ! return enabled; ! } ! /** @see org.jmule.core.Plugin#setEnabled(boolean) */ ! public void setEnabled(boolean isEnabled) { ! enabled = isEnabled; ! } ! // end of user changable section ! public void setComClient(ComClient com) { ! comClient = com; ! } ! public static StandAloneCommandLineUI getInstance() { ! if (singleton == null) singleton = new StandAloneCommandLineUI(); ! return singleton; ! } ! private StandAloneCommandLineUI() { ! clip = new CommandLineInterfaceParser(); ! input = new BufferedReader(new InputStreamReader(System.in)); ! ! System.out.println( ! "\n\n" + Messages.getString("Type 'help' to get a command overview. Welcome, share and enjoy.") + "\n"); ! ! //printStream = new PrintTeeStream(); ! } ! ! // Maybe we should just set the System.out and System.err in the TeeCLCommand ! //PrintTeeStream printStream; ! /* ! public PrintTeeStream getPrintTeeStream() { ! return printStream; ! } ! */ ! public void run() { ! while (!doClose) { ! System.out.print(prompt); ! try { ! String line = input.readLine(); ! processLine(line); ! } catch (Exception err) { ! /*printStream*/ ! System.err.println(err.getMessage()); ! //err.printStackTrace(); ! } ! } ! } ! ! public void processLine(String line) { ! if (!MiscUtil.isStrEmpty(line)) { ! try { ! Command cmd = clip.processLine(line); ! synchronized (this) { ! List outStrings = cmd.execute(comClient); ! MiscUtil.outStringList(outStrings); ! } ! } catch (ParseError perr) { ! //perr.printStackTrace(); ! /*printStream*/ ! System.err.println(perr.getMessage()); ! } catch (Exception err) { // throwed by execute ! // XXX: Don't catch this exception here but pass it on, top to the Main, so we get a full bugMe report ! if (MiscUtil.isStrEmpty(err.getMessage())) { ! System.err.println("Unexpected Exception occured, full stacktrace follows:"); ! err.printStackTrace(); ! } else ! /*printStream*/ ! System.err.println(err.getMessage()); ! } ! } ! } ! ! /** @see org.jmule.core.Plugin#getShortDescription() */ ! public String getShortDescription() { ! return "Simple Stand alone command line interface for jMule."; ! } ! ! /** @see org.jmule.core.Plugin#getID() */ ! public String getID() { ! return "sacli"; ! } } |