[Pfc-prolog-cvs] prolix/src/org/asturlinux/frade/prolix/consoleclient ConsoleClient.java,NONE,1.1 In
Status: Beta
Brought to you by:
ivanfrade
From: <iva...@us...> - 2003-06-24 08:18:39
|
Update of /cvsroot/pfc-prolog/prolix/src/org/asturlinux/frade/prolix/consoleclient In directory sc8-pr-cvs1:/tmp/cvs-serv28280/consoleclient Added Files: ConsoleClient.java Interfaz.java Log Message: Added unfinished files of a simple console-mode client --- NEW FILE: ConsoleClient.java --- /** * * Copyright 2003 Ivan Frade * * This file is part of Prolix. * * Prolix is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * Prolix is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Prolix; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * **/ package org.asturlinux.frade.prolix.consoleclient; import java.util.*; import java.rmi.*; import javax.naming.*; import javax.rmi.*; import java.io.*; import javax.ejb.*; import org.asturlinux.frade.prolix.ejb.sessionjb.*; /** * Clase cliente en modo texto de Prolix * */ public class ConsoleClient { private ProlixMain interpreter; public static void main(String args[]) { ConsoleClient console = new ConsoleClient(); console.run(); } /** * Obtain Bean and present menu */ private void run() { try { // Obtain reference to home InitialContext ctx = new InitialContext(); Object o = ctx.lookup( "org/asturlinux/frade/prolix/ejb/sessionjb/ProlixMain" ); ProlixMainHome home = null; home = (ProlixMainHome)PortableRemoteObject.narrow(o, ProlixMainHome.class); // Create the interpreter bean interpreter = home.create(); } catch (NamingException ne) { System.out.println("ERROR: Naming Exception"); return; } catch (CreateException ce) { System.out.println("ERROR creating interpreter "); return; } catch (RemoteException re) { System.out.println("ERROR: Remote Exception creatin interpreter"); return; } String[] optionsMenu = {"Load Program", "Load Consult", "Step", "Exit"}; boolean otherIteration = true; int input; do { switch (Interfaz.writeMenu("Prolix", optionsMenu.length, optionsMenu)) { case 1: program(); break; case 2: consult(); break; case 3: gostep(); break; case 4: otherIteration = false; break; } } while(otherIteration); } /** * * Private methods to actions * */ /** * * Take program from command line and try to load in interpreter * */ private void program() { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); System.out.println("Write some program code in Prolog"); try { String input = new String(in.readLine()); // interpreter.loadProgram(input) } catch (IOException io) { System.out.println("Please, write something with sense"); } } private void consult() { } private void gostep() { } } --- NEW FILE: Interfaz.java --- /** * * Copyright 2003 Ivan Frade * * This file is part of Prolix. * * Prolix is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * Prolix is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Prolix; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * **/ package org.asturlinux.frade.prolix.consoleclient; import java.io.*; public class Interfaz { public static int writeMenu(String title, int opt, String []options) { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); int readed = 0; do { System.out.println("\n\n -= " + title + " =- \n\n "); for (int i = 0 ; i < opt ; i++) System.out.println(" " + (i+1) + ". " + options[i]); System.out.println("Write a number in range [1-" + opt + "], please"); try { String someyouwrite = in.readLine(); readed = Integer.valueOf(someyouwrite).intValue(); } catch (IOException e) { //FIXME null string readed = -10; } } while( readed < 1 || readed > opt); return readed; } } |