//**************************************************************** // TRABAJO ISBC : INTEGRACION JAVA-JESS. CASO DEL ELEVADOR //**************************************************************** // // Fichero: ReteISBC.java // Autor: David Portolés Rodríguez // Proposito: Contiene una extension de la clase Rete para // simplificar la interaccion Java-Jess // //**************************************************************** package ISBC_JESS; import jess.*; import java.io.*; public class ReteISBC extends Rete { //almacena si se desea obtener los mensajes boolean verbose = false; // !!!!!!!!CONSULTAR !!!!!!!!!!!! // esto lo uso para sacar mensajes // Podria utilizarse cualquiera de los que almacena la clase Rete // (errStream..) // Tb podria sacarlos siempre por la System.err private ReteDisplay rd; public ReteISBC() { super((ReteDisplay) System.err); rd = (ReteDisplay) System.err; } public ReteISBC(ReteDisplay p0) { super(p0); rd = p0; } public void cargaReglas(String fileName) throws Exception { FileInputStream fis; try { fis = new FileInputStream(fileName); Jesp j = new Jesp(fis, this); try { do { try { j.parse(false); } catch (ReteException re) { re.printStackTrace(rd.stderr()); } } while (fis.available() > 0); } catch (IOException ioe) { rd.stderr().println("Error: fin de fichero no previsto."); throw(ioe); } } catch (FileNotFoundException fnfe) { rd.stderr().println("Error: fichero no encontrado."); throw (fnfe); } /* FileInputStream fis = new FileInputStream(fileName); Jesp j = new Jesp(fis, this); do { j.parse(false); } while (fis.available() > 0); */ } public void executeCommandAndRun1 (String p0) throws ReteException { this.executeCommand(p0); this.executeCommand("(run 1)"); } public boolean executeFacts() { try { this.executeCommand("(facts)"); } catch (ReteException ret) { System.err.println("Error: no se puede ver hechos en Rete."); ret.printStackTrace(rd.stderr()); return false; } return true; } public boolean executeRules() { try { this.executeCommand("(rules)"); } catch (ReteException ret) { System.err.println("Error: no se puede ver reglas en Rete."); ret.printStackTrace(rd.stderr()); return false; } return true; } public void setReglas(boolean b) { this.watchRules(b); } public void setHechos(boolean b) { this.watchFacts(b); } public void setCompilaciones(boolean b) { this.watchCompilations(b); } public void setDisparos(boolean b) { this.watchActivations(b); } public void setVerbose(boolean b) { verbose = b; } public boolean getVerbose() { return verbose; } }