Esempio n. 1
0
  private Rule(RuleScript ruleScript, ClassLoader loader, HelperManager helperManager)
      throws ParseException, TypeException, CompileException {
    ParseNode ruleTree;

    this.ruleScript = ruleScript;
    this.helperClass = null;
    this.loader = loader;

    typeGroup = new TypeGroup(loader);
    bindings = new Bindings();
    checked = false;
    triggerClass = null;
    triggerMethod = null;
    triggerDescriptor = null;
    triggerAccess = 0;
    returnType = null;
    accessibleFields = null;
    accessibleMethods = null;
    // this is only set when the rule is created via a real installed transformer
    this.helperManager = helperManager;
    ECAGrammarParser parser = null;
    try {
      String file = getFile();
      ECATokenLexer lexer = new ECATokenLexer(new StringReader(ruleScript.getRuleText()));
      lexer.setStartLine(getLine());
      lexer.setFile(file);
      parser = new ECAGrammarParser(lexer);
      parser.setFile(file);
      Symbol parse = (debugParse ? parser.debug_parse() : parser.parse());
      if (parser.getErrorCount() != 0) {
        String message = "rule " + ruleScript.getName();
        message += parser.getErrors();
        throw new ParseException(message);
      }
      ruleTree = (ParseNode) parse.value;
    } catch (ParseException pe) {
      throw pe;
    } catch (Throwable th) {
      String message = "rule " + ruleScript.getName();
      if (parser != null && parser.getErrorCount() != 0) {
        message += parser.getErrors();
      }
      message += "\n" + th.getMessage();
      throw new ParseException(message);
    }

    ParseNode eventTree = (ParseNode) ruleTree.getChild(0);
    ParseNode conditionTree = (ParseNode) ruleTree.getChild(1);
    ParseNode actionTree = (ParseNode) ruleTree.getChild(2);

    event = Event.create(this, eventTree);
    condition = Condition.create(this, conditionTree);
    action = Action.create(this, actionTree);
    key = null;
  }
Esempio n. 2
0
  /**
   * type check this rule
   *
   * @throws TypeException if the ruele contains type errors
   */
  public void typeCheck() throws TypeException {
    String helperName = ruleScript.getTargetHelper();

    // ensure that we have a valid helper class
    if (helperName != null) {
      try {
        helperClass = loader.loadClass(helperName);
      } catch (ClassNotFoundException e) {
        throw new TypeException(
            "Rule.typecheck : unknown helper class " + helperName + " for rule " + getName());
      }
    } else {
      helperClass = Helper.class;
    }
    if (triggerExceptions != null) {
      // ensure that the type group includes the exception types
      typeGroup.addExceptionTypes(triggerExceptions);
    }

    // try to resolve all types in the type group to classes

    typeGroup.resolveTypes();

    // use the descriptor to derive the method argument types and type any bindings for them
    // that are located in the bindings list

    installParameters((triggerAccess & Opcodes.ACC_STATIC) != 0, triggerClass);

    event.typeCheck(Type.VOID);
    condition.typeCheck(Type.Z);
    action.typeCheck(Type.VOID);
  }
Esempio n. 3
0
  /**
   * typecheck and then compile this rule unless either action has been tried before
   *
   * @return true if the rule successfully type checks and then compiles under this call or a
   *     previous call or false if either operation has previously failed or fails under this call.
   */
  private synchronized boolean ensureTypeCheckedCompiled() {
    if (checkFailed) {
      return false;
    }

    if (!checked) {
      // ensure we don't trigger any code inside the type check or compile
      // n.b. we may still allow recursive triggering while executing
      boolean triggerEnabled = false;
      String detail = "";
      try {
        typeCheck();
        compile();
        checked = true;
        installed();
      } catch (TypeWarningException te) {
        checkFailed = true;
        if (Transformer.isVerbose()) {
          StringWriter stringWriter = new StringWriter();
          PrintWriter writer = new PrintWriter(stringWriter);
          writer.println(
              "Rule.ensureTypeCheckedCompiled : warning type checking rule " + getName());
          te.printStackTrace(writer);
          detail = stringWriter.toString();
          System.out.println(detail);
        }
      } catch (TypeException te) {
        checkFailed = true;
        StringWriter stringWriter = new StringWriter();
        PrintWriter writer = new PrintWriter(stringWriter);
        writer.println("Rule.ensureTypeCheckedCompiled : error type checking rule " + getName());
        te.printStackTrace(writer);
        detail = stringWriter.toString();
        System.out.println(detail);
      } catch (CompileException ce) {
        checkFailed = true;
        StringWriter stringWriter = new StringWriter();
        PrintWriter writer = new PrintWriter(stringWriter);
        writer.println("Rule.ensureTypeCheckedCompiled : error compiling rule " + getName());
        ce.printStackTrace(writer);
        detail = stringWriter.toString();
        System.out.println(detail);
      }

      ruleScript.recordCompile(triggerClass, loader, !checkFailed, detail);
      return !checkFailed;
    }

    return true;
  }
Esempio n. 4
0
 /**
  * retrieve the name of the file containing this rule
  *
  * @return the name of the file containing this rule
  */
 public String getFile() {
   return ruleScript.getFile();
 }
Esempio n. 5
0
 /**
  * retrieve the start line for the rule
  *
  * @return the start line for the rule
  */
 public int getLine() {
   return ruleScript.getLine();
 }
Esempio n. 6
0
 public boolean isInterface() {
   return ruleScript.isInterface();
 }
Esempio n. 7
0
 public boolean isOverride() {
   return ruleScript.isOverride();
 }
Esempio n. 8
0
 public Location getTargetLocation() {
   return ruleScript.getTargetLocation();
 }
Esempio n. 9
0
 public String getTargetMethod() {
   return ruleScript.getTargetMethod();
 }
Esempio n. 10
0
 public String getTargetClass() {
   return ruleScript.getTargetClass();
 }
Esempio n. 11
0
 public String getName() {
   return ruleScript.getName();
 }