Esempio n. 1
0
  @Before
  public void setUp() {
    FunctionHandlers handlers = FunctionHandlers.getInstance();
    handlers.registerFunction(new PlusFunction());
    handlers.registerFunction(new MinusFunction());
    handlers.registerFunction(new MultiplyFunction());
    handlers.registerFunction(new ModifyFunction());
    handlers.registerFunction(new CreateListFunction());
    handlers.registerFunction(new PrintoutFunction());
    handlers.registerFunction(new PrognFunction());
    handlers.registerFunction(new IfFunction());
    handlers.registerFunction(new LessThanFunction());
    handlers.registerFunction(new LessThanOrEqFunction());
    handlers.registerFunction(new MoreThanFunction());
    handlers.registerFunction(new MoreThanOrEqFunction());
    handlers.registerFunction(new EqFunction());
    handlers.registerFunction(new SwitchFunction());
    // handlers.registerFunction( new DeffunctionFunction() );
    handlers.registerFunction(new ReturnFunction());
    handlers.registerFunction(new RunFunction());
    handlers.registerFunction(new BindFunction());
    handlers.registerFunction(new NewFunction());
    handlers.registerFunction(new SetFunction());
    handlers.registerFunction(new GetFunction());
    handlers.registerFunction(new CallFunction());
    handlers.registerFunction(new AssertFunction());

    this.shell = new ClipsShell();

    this.baos = new ByteArrayOutputStream();
    shell.addRouter("t", new PrintStream(baos));
  }
Esempio n. 2
0
  @Before
  public void setUp() {

    this.shell = new ClipsShell();
    this.baos = new ByteArrayOutputStream();
    PrintStream p = new PrintStream(baos);
    shell.addRouter("t", p);
  }
Esempio n. 3
0
  public static void main(String[] args) throws Exception {
    ClipsShell shell = new ClipsShell();
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    shell.addRouter("t", new PrintStream(out));

    StringBuffer buf = new StringBuffer();
    System.out.print("Drools>");

    StringBuffer sessionLog = new StringBuffer();
    while (true) {
      byte name[] = new byte[256];

      System.in.read(name);
      String cmd = (new String(name)).trim();

      if (cmd.equals("(exit)") || cmd.equals("(quit)")) {
        sessionLog.append(cmd);
        break;
      }
      buf.append(cmd);

      if (isBalancedBrackets(buf)) {
        String exp = buf.toString();
        if (exp.startsWith("(save ")) {
          String file = getFileName(exp);
          System.out.println("Saving transcript to [" + file + "]");
          writeFile(file, sessionLog);
          sessionLog = new StringBuffer();
          System.out.print("Drools>");
        } else {
          sessionLog.append(cmd + "\n");

          if (exp.startsWith("(load ")) {
            String file = getFileName(exp);
            System.out.println("Loading transcript from [" + file + "]");
            exp = loadFile(file);
          }

          shell.eval(exp);
          String output = new String(out.toByteArray());
          if (output != null && output.trim().length() > 0) {
            System.out.println(output);
          }
          out.reset();
          System.out.print("Drools>");
          buf = new StringBuffer();
        }
      }
    }

    System.out.println("Goodbye, and good luck !");
  }