Package org.drools.compiler.lang.descr

Examples of org.drools.compiler.lang.descr.ConnectiveDescr


public class ConnectiveDescrTest {

    @Test
    public void testBuildExpression() {
        ConnectiveDescr descr1 = new ConnectiveDescr(RestrictionConnectiveType.OR);
        descr1.setPrefix( "name" );
        descr1.add( "== 'darth'" );
        descr1.add( "== 'bobba'" );
       
        StringBuilder sb = new StringBuilder();
        descr1.buildExpression( sb );
        assertEqualsIgnoreWhitespace("name == 'darth' || == 'bobba'", sb.toString());
       
        ConnectiveDescr descr2 = new ConnectiveDescr(RestrictionConnectiveType.AND);
        descr2.setPrefix( "name" );
        descr2.add( "!= 'luke'" );
        sb = new StringBuilder();
        descr2.buildExpression( sb );
        assertEqualsIgnoreWhitespace("name != 'luke'", sb.toString());       
        descr2.add( "!= 'yoda'" );       
       
        ConnectiveDescr descr3 = new ConnectiveDescr(RestrictionConnectiveType.AND);
        descr3.add( descr1 );
        descr3.add( descr2 );
       
        sb = new StringBuilder();
        descr3.buildExpression( sb );
        assertEqualsIgnoreWhitespace("(name == 'darth' || == 'bobba') && (name != 'luke' && != 'yoda')", sb.toString());       
       
        ConnectiveDescr descr4 = new ConnectiveDescr(RestrictionConnectiveType.AND);
        descr4.setPrefix( "age" );
        descr4.add( "!= 33" );
        descr4.add( "!= 34" )
       
        ConnectiveDescr descr5 = new ConnectiveDescr(RestrictionConnectiveType.OR);
        descr5.add( descr3 );
        descr5.add( descr4 );       
       
        sb = new StringBuilder();
        descr5.buildExpression( sb );
        assertEqualsIgnoreWhitespace("((name == 'darth' || == 'bobba') && (name != 'luke' && != 'yoda')) || (age != 33 && != 34)", sb.toString());       
      
    }   
View Full Code Here


                        final ExtensibleXmlParser parser) throws SAXException {
        parser.startElementBuilder( localName,
                                    attrs );
       
        if ( localName.startsWith( RestrictionConnectiveHandler.OR ) ) {
            return new ConnectiveDescr(RestrictionConnectiveType.OR);   
        } else if ( localName.startsWith( RestrictionConnectiveHandler.AND ) ) {
            return new ConnectiveDescr(RestrictionConnectiveType.AND);  
        } else {
            throw new SAXParseException( "<" + localName + "> should have'",
                                         parser.getLocator() );
        }
       
View Full Code Here

                      final String localName,
                      final ExtensibleXmlParser parser) throws SAXException {
        final Element element = parser.endElementBuilder();
       
        Object op = parser.getParent();
        ConnectiveDescr c = (ConnectiveDescr) parser.getCurrent();
       
        if ( op instanceof PatternDescr ) {
            StringBuilder sb = new StringBuilder();
            c.buildExpression( sb );
                 
            ExprConstraintDescr expr = new ExprConstraintDescr( );
            expr.setExpression( sb.toString() );
             
            final PatternDescr patternDescr = (PatternDescr)op; 
            patternDescr.addConstraint( expr );   
        } else {       
            ConnectiveDescr p = (ConnectiveDescr)op;
            p.add( c );
        }
        return c;
    }
View Full Code Here

                      final ExtensibleXmlParser parser) throws SAXException {       
        final Element element = parser.endElementBuilder();
        final String expression =((org.w3c.dom.Text)element.getChildNodes().item( 0 )).getWholeText();
        emptyContentCheck( localName, expression, parser );
       
        ConnectiveDescr c = (ConnectiveDescr) parser.getParent();
        String s = ( (String) parser.getCurrent()) + "(" + expression + ")";

        c.add( s );
        return null;       
    }
View Full Code Here

        final String fieldName = attrs.getValue( "field-name" );
        emptyAttributeCheck( localName,
                             "field-name",
                             fieldName,
                             parser );
        final ConnectiveDescr connective = new ConnectiveDescr( RestrictionConnectiveType.AND );
        connective.setParen( false );

        connective.setPrefix( fieldName );

        return connective;
    }
View Full Code Here

    public Object end(final String uri,
                      final String localName,
                      final ExtensibleXmlParser parser) throws SAXException {
        final Element element = parser.endElementBuilder();

        final ConnectiveDescr c = (ConnectiveDescr) parser.getCurrent();

        Object p = parser.getParent();
        if ( p instanceof PatternDescr ) {
            StringBuilder sb = new StringBuilder();
            c.buildExpression( sb );

            ExprConstraintDescr expr = new ExprConstraintDescr();
            expr.setExpression( sb.toString() );

            final PatternDescr patternDescr = (PatternDescr) parser.getParent();
View Full Code Here

    public Object end(final String uri,
                      final String localName,
                      final ExtensibleXmlParser parser) throws SAXException {
        final Element element = parser.endElementBuilder();
       
        ConnectiveDescr c = (ConnectiveDescr) parser.getParent();
        String s = (String) parser.getCurrent();

        c.add( s );
        return null;
    }
View Full Code Here

    public Object end(final String uri,
                      final String localName,
                      final ExtensibleXmlParser parser) throws SAXException {
        final Element element = parser.endElementBuilder();
       
        ConnectiveDescr c = (ConnectiveDescr) parser.getParent();
        String s = (String) parser.getCurrent();

        c.add( s );
        return null;
    }
View Full Code Here

        final Element element = parser.endElementBuilder();
        final String expression =((org.w3c.dom.Text)element.getChildNodes().item( 0 )).getWholeText();

        emptyContentCheck( localName, expression, parser );

        ConnectiveDescr c = (ConnectiveDescr) parser.getParent();
        String s = ( (String) parser.getCurrent()) + expression;

        c.add( s );
        return null;     
    }
View Full Code Here

TOP

Related Classes of org.drools.compiler.lang.descr.ConnectiveDescr

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.