Пример #1
0
  public void lispFormHandler(LispForm lispForm) {
    StringBuilderAppendable appendable = new StringBuilderAppendable();
    FunctionHandlers.dump(lispForm, appendable, true);

    ClassLoader tempClassLoader = Thread.currentThread().getContextClassLoader();
    try {
      Thread.currentThread()
          .setContextClassLoader(((InternalRuleBase) ruleBase).getRootClassLoader());

      ParserContext context = new ParserContext();

      String namespace = this.session.getAgenda().getFocusName();

      Package pkg = this.ruleBase.getPackage(namespace);
      if (pkg == null) {
        this.packageBuilder.addPackage(createPackageDescr(namespace));
        pkg = this.ruleBase.getPackage(namespace);
      }

      if (pkg != null) {
        // only time this will be null is if we have yet to do any packagedescr work
        try {

          for (Iterator it = pkg.getImports().entrySet().iterator(); it.hasNext(); ) {
            Entry entry = (Entry) it.next();
            String importName = ((ImportDeclaration) entry.getValue()).getTarget();
            if (importName.endsWith("*")) {
              context.addPackageImport(importName.substring(0, importName.length() - 2));
            } else {

              Class cls = ((InternalRuleBase) ruleBase).getRootClassLoader().loadClass(importName);
              context.addImport(cls.getSimpleName(), (Class) cls);
            }
          }

        } catch (Exception e) {
          e.printStackTrace();
        }

        MVELDialectRuntimeData data =
            (MVELDialectRuntimeData) pkg.getDialectRuntimeRegistry().getDialectData("clips");
        this.factory.setNextFactory(data.getFunctionFactory());
      }

      ExpressionCompiler expr = new ExpressionCompiler(appendable.toString());
      Serializable executable = expr.compile(context);

      MVEL.executeExpression(executable, this, this.factory);
    } finally {
      Thread.currentThread().setContextClassLoader(tempClassLoader);
    }
  }
Пример #2
0
 public static void init(ClipsShell shell) {
   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());
 }
Пример #3
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));
  }