⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 conditionhandler.java

📁 drools 一个开放源码的规则引擎
💻 JAVA
字号:
package org.drools.io;

import java.util.HashSet;

import org.drools.rule.Declaration;
import org.drools.rule.Rule;
import org.drools.smf.ConditionFactory;
import org.drools.smf.Configuration;
import org.drools.smf.FactoryException;
import org.drools.smf.SemanticModule;
import org.drools.spi.Condition;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;

/**
 * @author mproctor
 * 
 * TODO To change the template for this generated type comment go to Window -
 * Preferences - Java - Code Style - Code Templates
 */
class ConditionHandler extends BaseAbstractHandler
    implements
    Handler
{
    ConditionHandler(RuleSetReader ruleSetReader)
    {
        this.ruleSetReader = ruleSetReader;

        if ( (this.validParents == null) && (validPeers == null) )
        {
            this.ruleSetReader = ruleSetReader;
            this.validParents = new HashSet( );
            this.validParents.add( Rule.class );

            this.validPeers = new HashSet( );
            this.validPeers.add( Declaration.class );
            this.validPeers.add( Condition.class );
            this.validPeers.add( null );

            this.allowNesting = false;
        }
    }

    public Object start(String uri,
                        String localName,
                        Attributes attrs) throws SAXException
    {
        ruleSetReader.startConfiguration( localName,
                                          attrs );
        return null;
    }

    public Object end(String uri,
                      String localName) throws SAXException
    {
        Configuration config = this.ruleSetReader.endConfiguration( );
        SemanticModule module = this.ruleSetReader.lookupSemanticModule( uri,
                                                                         localName );

        ConditionFactory factory = module.getConditionFactory( localName );
        Condition[] conditions;
        try
        {
            Rule rule = (Rule) this.ruleSetReader.getParent( Rule.class );
            conditions = factory.newCondition( rule,
                                              this.ruleSetReader.getFactoryContext( ),
                                              config );

            for (int i = 0; i < conditions.length; i++)
            {
                rule.addCondition( conditions[i] );
            }
        }
        catch ( FactoryException e )
        {		
            throw new SAXParseException( "error constructing condition",
                                         this.ruleSetReader.getLocator( ),
                                         e );
        }
        return conditions[conditions.length-1];
    }

    public Class generateNodeFor()
    {
        return Condition.class;
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -