public void setOperator( String operator ) { if( this.operator == null ) { this.operator = new OperatorDescr(); } this.operator.setOperator( operator ); }
/** * Creates a new alias for the operator, setting it in the descriptor * class, adding it to the internal Map and returning it as a String * * @param operator * @return */ public String createAlias( OperatorDescr operator ) { String alias = operator.getOperator() + counter++; operator.setAlias(alias); this.aliases.put( alias, operator ); return alias; }
public List<String> getParameters() { return operator != null ? operator.getParameters() : null; }
public void setParameters( List<String> parameters ) { if( this.operator == null ) { this.operator = new OperatorDescr(); } this.operator.setParameters( parameters ); }
public void setNegated( boolean negated ) { if( this.operator == null ) { this.operator = new OperatorDescr(); } this.operator.setNegated( negated ); }
protected static Map<String, EvaluatorWrapper> buildOperators(RuleBuildContext context, Pattern pattern, PredicateDescr predicateDescr, Map<String, OperatorDescr> aliases) { Map<String, EvaluatorWrapper> operators = new HashMap<String, EvaluatorWrapper>(); for ( Map.Entry<String, OperatorDescr> entry : aliases.entrySet() ) { OperatorDescr op = entry.getValue(); Declaration leftDecl = createDeclarationForOperator(context, pattern, op.getLeftString()); Declaration rightDecl = createDeclarationForOperator(context, pattern, op.getRightString()); Target left = leftDecl != null && leftDecl.isPatternDeclaration() ? Target.HANDLE : Target.FACT; Target right = rightDecl != null && rightDecl.isPatternDeclaration() ? Target.HANDLE : Target.FACT; op.setLeftIsHandle( left == Target.HANDLE ); op.setRightIsHandle( right == Target.HANDLE ); Evaluator evaluator = getConstraintBuilder( context ).getEvaluator( context, predicateDescr, ValueType.OBJECT_TYPE, op.getOperator(), false, // the rewrite takes care of negation op.getParametersText(), left, right); EvaluatorWrapper wrapper = getConstraintBuilder( context ).wrapEvaluator( evaluator, leftDecl, rightDecl ); operators.put( entry.getKey(), wrapper ); } return operators; }
protected void rewriteOperator( MVELDumperContext context, StringBuilder sbuilder, String left, OperatorDescr operator, String right ) { String alias = context.createAlias( operator ); operator.setLeftString( left ); operator.setRightString( right ); sbuilder.append( evaluatorPrefix( operator.isNegated() ) ) .append( alias ) .append( ".evaluate( " ) .append( left ) .append( ", " ) .append( right ) .append( " )" ) .append( evaluatorSufix( operator.isNegated() ) ); }
protected void rewriteBasicOperator( StringBuilder sbuilder, String left, OperatorDescr operator, String right) { sbuilder.append( evaluatorPrefix( operator.isNegated() ) ) .append( left ) .append( " " ) .append( operator.getOperator() ) .append( " " ) .append( right ) .append( evaluatorSufix( operator.isNegated() ) ); }
public String getOperator() { return operator != null ? operator.getOperator() : null; }
public RelationalExprDescr(String operator, boolean negated, List<String> parameters, BaseDescr left, BaseDescr right) { this.left = left; this.right = right; this.operator = new OperatorDescr( operator, negated, parameters ); }
public boolean isNegated() { return operator != null ? operator.isNegated() : false; }
OperatorDescr operator, String right ) { Operator op = Operator.determineOperator( operator.getOperator(), operator.isNegated() ); if ( op == Operator.determineOperator( "memberOf", operator.isNegated() ) ) { int lastAndPos = left.lastIndexOf("&&"); if ( lastAndPos > 0 ) { sbuilder.append( evaluatorPrefix( operator.isNegated() ) ) .append( right ) .append( " contains " ) .append( left ) .append( evaluatorSufix( operator.isNegated() ) ); } else if ( op == Operator.determineOperator( "contains", operator.isNegated() ) ) { sbuilder.append( evaluatorPrefix( operator.isNegated() ) ) .append( left ) .append( " contains " ) .append( right ) .append( evaluatorSufix( operator.isNegated() ) ); } else if ( op == Operator.determineOperator( "excludes", operator.isNegated() ) ) { sbuilder.append( evaluatorPrefix( !operator.isNegated() ) ) .append( left ) .append( " contains " ) .append( right ) .append( evaluatorSufix( !operator.isNegated() ) ); } else if ( op == Operator.determineOperator( "matches",
Declaration requiredDeclaration, RelationalExprDescr relDescr) { if (!isMvelOperator(operatorDescr.getOperator())) { EvaluatorDefinition.Target right = getRightTarget( extractor ); EvaluatorDefinition.Target left = (requiredDeclaration.isPatternDeclaration() && !(Date.class.isAssignableFrom( requiredDeclaration.getExtractor().getExtractToClass() ) || Number.class.isAssignableFrom( requiredDeclaration.getExtractor().getExtractToClass() ))) ? EvaluatorDefinition.Target.HANDLE : EvaluatorDefinition.Target.FACT; relDescr, extractor.getValueType(), operatorDescr.getOperator(), relDescr.isNegated(), relDescr.getParametersText(), boolean isUnification = requiredDeclaration != null && requiredDeclaration.getPattern().getObjectType().equals( new ClassObjectType( DroolsQuery.class ) ) && Operator.EQUAL.getOperatorString().equals( operatorDescr.getOperator() ); if (isUnification) { expression = resolveUnificationAmbiguity(expression, declarations, leftValue, rightValue); IndexUtil.ConstraintType constraintType = IndexUtil.ConstraintType.decode(operatorDescr.getOperator()); MVELCompilationUnit compilationUnit = isUnification ? null : buildCompilationUnit(context, pattern, expression, null); return new MvelConstraint(context.getPkg().getName(), expression, declarations, compilationUnit, constraintType, requiredDeclaration, extractor, isUnification);
public String getParametersText() { if ( operator != null && operator.getParameters() != null ) { StringBuilder builder = new StringBuilder(); boolean first = true; for ( String param : operator.getParameters() ) { if ( first ) { first = false; } else { builder.append( "," ); } builder.append( param ); } return builder.toString(); } return null; }