Package org.drools.lang.descr

Examples of org.drools.lang.descr.RuleDescr


        assertEquals( 1,
                      desc.getRules().size() );
        assertEquals( 1,
                      packageAttrs.size() );

        RuleDescr rule = (RuleDescr) desc.getRules().get( 0 );
        List ruleAttrs = rule.getAttributes();
        assertEquals( 1,
                      ruleAttrs.size() );

        assertEquals( "mvel",
                      ((AttributeDescr) ruleAttrs.get( 0 )).getValue() );
View Full Code Here


                }
            }

            // iterate and compile
            for ( final Iterator it = packageDescr.getRules().iterator(); it.hasNext(); ) {
                RuleDescr ruleDescr = (RuleDescr) it.next();
                if ( isEmpty( ruleDescr.getNamespace() ) ) {
                    // make sure namespace is set on components
                    ruleDescr.setNamespace( packageDescr.getNamespace() );
                }

                Map<String, AttributeDescr> pkgAttributes = packageAttributes.get( packageDescr.getNamespace() );
                inheritPackageAttributes( pkgAttributes,
                                          ruleDescr );

                if ( isEmpty( ruleDescr.getDialect() ) ) {
                    ruleDescr.addAttribute( new AttributeDescr( "dialect",
                                                                pkgRegistry.getDialect() ) );
                }
                addRule( ruleDescr );
            }
        }

        compileAll();
        try {
            reloadAll();
        } catch ( Exception e ) {
            this.results.add( new DialectError( "Unable to wire compiled classes, probably related to compilation failures:" + e.getMessage() ) );
        }
        updateResults();

        // iterate and compile
        if ( this.ruleBase != null ) {
            for ( final Iterator it = packageDescr.getRules().iterator(); it.hasNext(); ) {
                RuleDescr ruleDescr = (RuleDescr) it.next();
                pkgRegistry = this.pkgRegistryMap.get( ruleDescr.getNamespace() );
                this.ruleBase.addRule( pkgRegistry.getPackage(),
                                       pkgRegistry.getPackage().getRule( ruleDescr.getName() ) );
            }
        }
    }
View Full Code Here

    }

    private String processRules(final List rules) {
        String ruleList = "";
        for ( final Iterator iterator = rules.iterator(); iterator.hasNext(); ) {
            final RuleDescr ruleDescr = (RuleDescr) iterator.next();
            String rule = "<rule name=\"" + ruleDescr.getName() + "\">" + XmlDumper.eol;
            final String attribute = processAttribute( ruleDescr.getAttributes().values() );
            String lhs = "";
            if ( ruleDescr.getLhs().getDescrs() != Collections.EMPTY_LIST ) {
                lhs = "<lhs>" + processDescrList( ruleDescr.getLhs().getDescrs() ) + "</lhs>";
            } else {

                lhs = "<lhs> </lhs>";
            }

            final String rhs = "<rhs>" + replaceIllegalChars( (String) ruleDescr.getConsequence() ) + "</rhs>" + XmlDumper.eol;
            rule += attribute;
            rule += lhs;
            rule += rhs;
            rule += "</rule>";
            ruleList += rule;
View Full Code Here

        final Object parent = parser.getParent();

        if ( !andDescr.getDescrs().isEmpty() ) {
            if ( parent instanceof RuleDescr || parent instanceof QueryDescr ) {
                final RuleDescr ruleDescr = (RuleDescr) parent;
                ruleDescr.setLhs( andDescr );
            } else if ( parent instanceof MultiPatternDestinationDescr ) {
                final MultiPatternDestinationDescr mpDescr = (MultiPatternDestinationDescr) parent;
                mpDescr.setInput( andDescr );
            } else if ( parent instanceof ConditionalElementDescr ) {
                final ConditionalElementDescr ceDescr = (ConditionalElementDescr) parent;
View Full Code Here

        emptyAttributeCheck( localName,
                             "name",
                             ruleName,
                             parser );

        final RuleDescr ruleDescr = new RuleDescr( ruleName.trim() );

        return ruleDescr;
    }
View Full Code Here

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

        final RuleDescr ruleDescr = (RuleDescr) parser.getCurrent();

        final AndDescr lhs = ruleDescr.getLhs();

        if ( lhs == null ) {
            throw new SAXParseException( "<rule> requires a LHS",
                                         parser.getLocator() );
        }

        NodeList list = element.getElementsByTagName( "rhs" );
        if ( list.getLength() == 0 ) {
            throw new SAXParseException( "<rule> requires a <rh> child element",
                                         parser.getLocator() );
        }

        ruleDescr.setConsequence( ((org.w3c.dom.Text)list.item( 0 ).getChildNodes().item( 0 )).getWholeText() );

        NodeList attributes = element.getElementsByTagName( "rule-attribute" );
        for ( int i = 0, length = attributes.getLength(); i < length; i++ ) {
            final String name = ((Element) attributes.item( i )).getAttribute( "name" );
            emptyAttributeCheck( "rule-attribute",
                                 "name",
                                 name,
                                 parser );

            final String value = ((Element) attributes.item( i )).getAttribute( "value" );

            ruleDescr.addAttribute( new AttributeDescr( name,
                                                        value ) );
        }

        ((PackageDescr) parser.getData()).addRule( ruleDescr );
View Full Code Here

    implements
    RuleDescrBuilder {

    protected RuleDescrBuilderImpl(PackageDescrBuilder parent) {
        super( parent,
               new RuleDescr() );
    }
View Full Code Here

        if ( children.isEmpty() ) { // Sorting not necessary
            return;
        }

        while ( !roots.isEmpty() ) {
            RuleDescr root = roots.remove(0);
            sorted.put(root.getName(), root);
            List<RuleDescr> childz = children.remove(root.getName());
            if ( childz != null) {
                roots.addAll( childz );
            }
        }
View Full Code Here

            // TODO: process annotations

            // process pattern
            Package pkg = pkgRegistry.getPackage();
            DialectCompiletimeRegistry ctr = pkgRegistry.getDialectCompiletimeRegistry();
            RuleDescr dummy = new RuleDescr( wd.getName() + " Window Declaration" );
            dummy.addAttribute( new AttributeDescr( "dialect", "java" ) );
            RuleBuildContext context = new RuleBuildContext( this,
                                                             dummy,
                                                             ctr,
                                                             pkg,
                                                             ctr.getDialect( pkgRegistry.getDialect() ) );
View Full Code Here

        final Object parent = parser.getParent();

        if ( !orDescr.getDescrs().isEmpty() ) {
            if ( parent instanceof RuleDescr || parent instanceof QueryDescr ) {
                final RuleDescr ruleDescr = (RuleDescr) parent;
                ruleDescr.getLhs().addDescr( orDescr );
            } else if ( parent instanceof MultiPatternDestinationDescr ) {
                final MultiPatternDestinationDescr mpDescr = (MultiPatternDestinationDescr) parent;
                mpDescr.setInput( orDescr );
            } else if ( parent instanceof ConditionalElementDescr ) {
                final ConditionalElementDescr ceDescr = (ConditionalElementDescr) parent;
View Full Code Here

TOP

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

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.