Package org.drools.examples.conway.rules

Source Code of org.drools.examples.conway.rules.RuleBaseFactory

/**
*
*/
package org.drools.examples.conway.rules;

import org.drools.RuleBase;
import org.drools.examples.conway.CellGrid;
import org.drools.examples.helloworld.HelloWorldExample;
import org.drools.io.RuleBaseLoader;
import org.drools.io.RuleSetLoader;

import java.net.URL;

/**
* @author <a href="mailto:brown_j@ociweb.com">Jeff Brown</a>
* @version $Id: RuleBaseFactory.java,v 1.4 2005/11/25 02:35:33 mproctor Exp $
*/
public class RuleBaseFactory
{

    private static RuleBaseFactory ourInstance      = new RuleBaseFactory( );
    private static final String    DEFAULT_DRL_FILE = "conway.java.drl";

    private RuleBase               ruleBase;

    public static RuleBaseFactory getInstance()
    {
        return ourInstance;
    }

    private RuleBaseFactory()
    {
        try
        {
            String conwayDrlFile = System.getProperty( "conway.drl.file" );
            if ( conwayDrlFile == null )
            {
                System.err.println( "conway.drl.file system property not specified. using default: " + DEFAULT_DRL_FILE );
                conwayDrlFile = DEFAULT_DRL_FILE;
            }
            System.out.println( "loading drl file: " + conwayDrlFile );
           
            RuleSetLoader ruleSetLoader = new RuleSetLoader();          
            ruleSetLoader.addFromUrl( CellGrid.class.getResource( conwayDrlFile ) );           
           
            RuleBaseLoader ruleBaseLoader = new RuleBaseLoader();
            ruleBaseLoader.addFromRuleSetLoader(ruleSetLoader);
            ruleBase = ruleBaseLoader.buildRuleBase();               
        }
        catch ( Exception e )
        {
            throw new RuntimeException( "Unable To Initialise RuleBaseFactory:\n" + e.getMessage() );
        }
    }

    public static RuleBase getRuleBase()
    {
        return ourInstance.ruleBase;
    }
}
TOP

Related Classes of org.drools.examples.conway.rules.RuleBaseFactory

TOP
Copyright © 2018 www.massapi.com. 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.