Package org.drools.decisiontable.model

Examples of org.drools.decisiontable.model.Package


     */
    public Package getRuleSet() {
        if ( this._ruleList.isEmpty() ) {
            throw new DecisionTableParseException( "No RuleTable's were found in spreadsheet." );
        }
        final Package ruleset = buildRuleSet();
        return ruleset;
    }
View Full Code Here


    private Package buildRuleSet() {
        final String defaultPackageName = this.defaultPackage != null ? this.defaultPackage.getName() : "rule_table";
        final String rulesetName = getProperties().getProperty( DefaultRuleSheetListener.RULESET_TAG,
                                                                defaultPackageName );
        final Package ruleset = new Package( rulesetName );
        for ( final Iterator it = this._ruleList.iterator(); it.hasNext(); ) {
            ruleset.addRule( (Rule) it.next() );
        }
        final List importList = RuleSheetParserUtil.getImportList( getProperties().getProperty( DefaultRuleSheetListener.IMPORT_TAG ) );
        for ( final Iterator it = importList.iterator(); it.hasNext(); ) {
            ruleset.addImport( (Import) it.next() );
        }
        final List variableList = RuleSheetParserUtil.getVariableList( getProperties().getProperty( DefaultRuleSheetListener.VARIABLES_TAG ) ); // Set the list of variables to
        // be added to the
        // application-data tags
        for ( final Iterator it = variableList.iterator(); it.hasNext(); ) {
            ruleset.addVariable( (Global) it.next() );
        }

        final String functions = getProperties().getProperty( DefaultRuleSheetListener.FUNCTIONS_TAG );
        ruleset.addFunctions( functions );
        return ruleset;
    }
View Full Code Here

    public String compile(final InputStream xlsStream,
                          final InputType type,
                          final RuleSheetListener listener) {
        final DecisionTableParser parser = type.createParser( listener );
        parser.parseFile( xlsStream );
        final Package rulePackage = listener.getRuleSet();
        final DRLOutput out = new DRLOutput();
        rulePackage.renderDRL( out );
        return out.getDRL();
    }
View Full Code Here

     */
    public String compile(final InputStream stream,
                          final String worksheetName) {
        final RuleSheetListener listener = getRuleSheetListener( stream,
                                                                 worksheetName );
        final Package rulePackage = listener.getRuleSet();
        final DRLOutput out = new DRLOutput();
        rulePackage.renderDRL( out );
        return out.getDRL();
    }
View Full Code Here

    public void testWorkbookParse() throws Exception {
        final InputStream stream = RuleWorksheetParseTest.class.getResourceAsStream( "/data/BasicWorkbook.xls" );
        final RuleSheetListener listener = getRuleSheetListener( stream );

        final Package ruleset = listener.getRuleSet();
        assertNotNull( ruleset );

        final Rule firstRule = (Rule) ruleset.getRules().get( 0 );
        assertNotNull( firstRule.getSalience() );
        assertTrue( firstRule.getSalience().intValue() > 0 );

        // System.out.println(ruleset.toXML());

        assertEquals( "myruleset",
                      ruleset.getName() );
        assertEquals( 2,
                      ruleset.getImports().size() );
        assertEquals( 6,
                      ruleset.getRules().size() );

        // check imports
        Import imp = (Import) ruleset.getImports().get( 0 );
        assertEquals( "blah.class1",
                      imp.getClassName() );
        imp = (Import) ruleset.getImports().get( 1 );
        assertEquals( "blah.class2",
                      imp.getClassName() );

        // check rules
        Rule rule = (Rule) ruleset.getRules().get( 0 );
        Condition cond = (Condition) rule.getConditions().get( 0 );
        assertEquals( "Foo(myObject.getColour().equals(red), myObject.size () > 1)",
                      cond.getSnippet() );

        Consequence cons = (Consequence) rule.getConsequences().get( 0 );
        assertNotNull( cons );
        assertEquals( "myObject.setIsValid(Y);",
                      cons.getSnippet() );

        rule = (Rule) ruleset.getRules().get( 5 );
        cond = (Condition) rule.getConditions().get( 1 );
        assertEquals( "myObject.size () > 7",
                      cond.getSnippet() );
        cons = (Consequence) rule.getConsequences().get( 0 );
        assertEquals( "myObject.setIsValid(10-Jul-1974)",
View Full Code Here

TOP

Related Classes of org.drools.decisiontable.model.Package

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.