public void build(
      final RuleBuildContext context,
      final BoundIdentifiers usedIdentifiers,
      final Declaration[] previousDeclarations,
      final Declaration[] localDeclarations,
      final PredicateConstraint predicate,
      final PredicateDescr predicateDescr,
      final AnalysisResult analysis) {
    MVELDialect dialect = (MVELDialect) context.getDialect(context.getDialect().getId());

    try {
      Map<String, Class<?>> declIds =
          context.getDeclarationResolver().getDeclarationClasses(context.getRule());

      Pattern p = (Pattern) context.getBuildStack().peek();
      if (p.getObjectType() instanceof ClassObjectType) {
        declIds.put("this", ((ClassObjectType) p.getObjectType()).getClassType());
      }

      MVELCompilationUnit unit =
          dialect.getMVELCompilationUnit(
              (String) predicateDescr.getContent(),
              analysis,
              previousDeclarations,
              localDeclarations,
              null,
              context);

      MVELPredicateExpression expr =
          new MVELPredicateExpression(unit, context.getDialect().getId());
      predicate.setPredicateExpression(expr);

      MVELDialectRuntimeData data =
          (MVELDialectRuntimeData)
              context
                  .getPkg()
                  .getDialectRuntimeRegistry()
                  .getDialectData(context.getDialect().getId());
      data.addCompileable(predicate, expr);

      expr.compile(context.getPackageBuilder().getRootClassLoader());
    } catch (final Exception e) {
      context
          .getErrors()
          .add(
              new DescrBuildError(
                  context.getParentDescr(),
                  predicateDescr,
                  e,
                  "Unable to build expression for 'inline-eval' : "
                      + e.getMessage()
                      + "'"
                      + predicateDescr.getContent()
                      + "'\n"
                      + e.getMessage()));
    }
  }
Exemplo n.º 2
0
 public void visitPredicateDescr(final PredicateDescr descr) {
   this.template = new String();
   this.template =
       "<predicate field-name=\""
           + descr.getFieldName()
           + "\" identifier=\""
           + descr.getDeclaration()
           + "\" >"
           + descr.getText()
           + "</predicate>"
           + XmlDumper.eol;
 }
Exemplo n.º 3
0
  /**
   * End leaf
   *
   * @param descr
   * @return
   */
  private PatternEval visitPredicateDescr(PredicateDescr descr) {

    PatternEval predicate = new PatternEval(pattern);
    predicate.setContent(descr.getContent().toString());
    predicate.setClassMethodName(descr.getClassMethodName());
    predicate.setOrderNumber(orderNumber.next());
    predicate.setParentPath(pattern.getPath());
    predicate.setParentType(pattern.getVerifierComponentType());

    data.add(predicate);

    solvers.addPatternComponent(predicate);

    return predicate;
  }