Package org.drools.lang.descr

Examples of org.drools.lang.descr.ReturnValueRestrictionDescr


        map.put( "b",
                 b );
        declarationResolver.setDeclarations( map );
        context.setDeclarationResolver( declarationResolver );

        final ReturnValueRestrictionDescr returnValueDescr = new ReturnValueRestrictionDescr( "=" );
        returnValueDescr.setContent( "a + b" );

        final MVELReturnValueBuilder builder = new MVELReturnValueBuilder();

        final List[] usedIdentifiers = new ArrayList[2];
        final List list = new ArrayList();
View Full Code Here


        assertEquals( 1,
                      col.getConstraint().getDescrs().size() );
        assertEquals( "Foo",
                      col.getObjectType() );
        final FieldConstraintDescr fld = (FieldConstraintDescr) col.getConstraint().getDescrs().get( 0 );
        final ReturnValueRestrictionDescr retval = (ReturnValueRestrictionDescr) fld.getRestrictions().get( 0 );

        assertEquals( "a + b",
                      retval.getContent() );
        assertEquals( "name",
                      fld.getFieldName() );
        assertEquals( "==",
                      retval.getEvaluator() );

        assertFalse( parser.hasErrors() );
    }
View Full Code Here

        return true;
    }

    private Declaration[] getDeclarationsForReturnValue(RuleBuildContext context, RelationalExprDescr relDescr, String operator, String value2) {
        Pattern pattern = (Pattern) context.getBuildStack().peek();
        ReturnValueRestrictionDescr returnValueRestrictionDescr = new ReturnValueRestrictionDescr( operator,
                                                                                                   relDescr.isNegated(),
                                                                                                   relDescr.getParametersText(),
                                                                                                   value2 );

        Map<String, Class< ? >> declarationsMap = getDeclarationsMap( returnValueRestrictionDescr,
                context,
                true );
        Class< ? > thisClass = null;
        if ( pattern.getObjectType() instanceof ClassObjectType ) {
            thisClass = ((ClassObjectType) pattern.getObjectType()).getClassType();
        }

        Map<String, Class< ? >> globals = context.getPackageBuilder().getGlobals();
        AnalysisResult analysis = context.getDialect().analyzeExpression( context,
                returnValueRestrictionDescr,
                returnValueRestrictionDescr.getContent(),
                new BoundIdentifiers( declarationsMap,
                        globals,
                        null,
                        thisClass ) );
        if ( analysis == null ) {
View Full Code Here

        map.put( "b",
                 b );
        declarationResolver.setDeclarations( map );
        context.setDeclarationResolver( declarationResolver );

        final ReturnValueRestrictionDescr returnValueDescr = new ReturnValueRestrictionDescr( "=" );
        returnValueDescr.setContent( "a + b" );

        final MVELReturnValueBuilder builder = new MVELReturnValueBuilder();

        final Declaration[] previousDeclarations = new Declaration[]{a, b};
        final Declaration[] localDeclarations = new Declaration[]{};
        final String[] requiredGlobals = new String[]{};

        final ReturnValueRestriction returnValue = new ReturnValueRestriction( extractor,
                                                                               previousDeclarations,
                                                                               localDeclarations,
                                                                               requiredGlobals,
                                                                               context.getConfiguration().getEvaluatorRegistry().getEvaluator( ValueType.PINTEGER_TYPE,
                                                                                                                                               Operator.EQUAL ) );
        AnalysisResult analysis = context.getDialect().analyzeExpression( context,
                                                                          returnValueDescr,
                                                                          returnValueDescr.getContent(),
                                                                          new BoundIdentifiers( declarationResolver.getDeclarationClasses( (Rule) null ), new HashMap(), null, Cheese.class ) );
        context.getBuildStack().push( patternB );
        builder.build( context,
                       analysis.getBoundIdentifiers(),
                       previousDeclarations,
View Full Code Here

            // execute it as a return value
            restriction = buildRestriction( context,
                                            (Pattern) context.getBuildStack().peek(),
                                            extractor,
                                            new ReturnValueRestrictionDescr( operator,
                                                                             relDescr.isNegated(),
                                                                             relDescr.getParametersText(),
                                                                             value2 ) );
            // fall back to original dialect
            context.setDialect( dialect );
View Full Code Here

                // execute it as a return value
                restriction = buildRestriction( context,
                                                (Pattern) context.getBuildStack().peek(),
                                                extractor,
                                                new ReturnValueRestrictionDescr( operator,
                                                                                 relDescr.isNegated(),
                                                                                 relDescr.getParametersText(),
                                                                                 rightValue ),
                                                aliases );
                // fall back to original dialect
View Full Code Here

                // execute it as a return value
                restriction = buildRestriction( context,
                                                (Pattern) context.getBuildStack().peek(),
                                                extractor,
                                                new ReturnValueRestrictionDescr( operator,
                                                                                 relDescr.isNegated(),
                                                                                 relDescr.getParametersText(),
                                                                                 rightValue ),
                                                aliases );
                // fall back to original dialect
View Full Code Here

        packageDescr.addGlobal( new GlobalDescr( "map",
                                                 "java.util.Map" ) );

        final FieldConstraintDescr returnValue = new FieldConstraintDescr( "price" );
        returnValue.addRestriction( new ReturnValueRestrictionDescr( "==",
                                                                     "x" ) );

        pattern.addConstraint( returnValue );

        // There is no m this should produce errors.
View Full Code Here

        packageDescr.addGlobal( new GlobalDescr( "map",
                                                 "java.util.Map" ) );

        final FieldConstraintDescr returnValue = new FieldConstraintDescr( "price" );
        returnValue.addRestriction( new ReturnValueRestrictionDescr( "==",
                                                                     "(( (Integer) map.get( new Integer( x )) ).intValue() * y)" ) );

        pattern.addConstraint( returnValue );

        ruleDescr.setConsequence( "update(stilton);" );
View Full Code Here

        packageDescr.addGlobal( new GlobalDescr( "map",
                                                 "java.util.Map" ) );

        final FieldConstraintDescr returnValue = new FieldConstraintDescr( "price" );
        returnValue.addRestriction( new ReturnValueRestrictionDescr( "==",
                                                                     expression ) );

        pattern.addConstraint( returnValue );

        ruleDescr.setConsequence( "update(stilton);" );
View Full Code Here

TOP

Related Classes of org.drools.lang.descr.ReturnValueRestrictionDescr

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.