1.rulesWithDSL.drl文件的定義:
package?com.mip.biz.operatebill.rules;

import?com.mip.biz.operatebill.objects.ValueBean;
import?org.apache.commons.lang.StringUtils;
import?com.mip.core.utils.Log;

global?com.mip.biz.operatebill.services.RulesService?operateRulesService;

expander?rules.dsl;
????

/**?*//**
?*?判斷操作項目內容中是否存在相應的標記字符串
?*/

function?boolean?itemContains(String?content,String?flag)
{
????boolean?res?=?StringUtils.contains(content,flag);
????return?res;
}

/**?*//**
?*?判斷操作項目內容中是否存在相應的標記字符串
?*/

function?boolean?judge(String?content,String?action,String?dev)
{
????
????//判斷指定的設備是否存在
????Log.debug("content:"+content);
????String[]?splitDevname?=?dev.split("或");????
????boolean?exitsDevname?=?false;

????for(int?i=0;i<splitDevname.length;i++)
{????
????????String?oneDevname?=?splitDevname[i];
????????//Log.debug("oneDevname:"+oneDevname);
????????exitsDevname?=?StringUtils.contains(content,oneDevname);
????????if(exitsDevname)?break;
????}????
????Log.debug("exitsDevName:"+exitsDevname);

????String[]?splitAction?=?action.split("或");
????boolean?exitsAction?=?false;

????for(int?i=0;i<splitAction.length;i++)
{
????????String?oneAction?=?splitAction[i];
????????//Log.debug("oneAction:"+oneAction);
????????exitsAction?=?StringUtils.contains(content,oneAction);
????????if(exitsAction)?break;
????}
????Log.debug("exitsAction:"+exitsAction);
????????
????return?exitsAction?&&?exitsDevname;
}

rule?"拉閘操作時設置“操作標志”為RULES_IS_OPEN_SWITCH(2)"
????when?
????????"本次操作如果"?"拉或拉開或斷開"?"某某"?"刀閘或開關"
????then?
????????"設置標記為:"2
end
rule?"合閘操作時設置“操作標志”為RULES_IS_CLOSE_SWITCH(3)"
????when?
????????"本次操作如果"?"合或合上"?"某某"?"刀閘或開關"
????then?
????????"設置標記為:"3
end
rule?"拉或拉開##地刀操作設置“操作標志”為RULES_IS_OPEN_SWITCH_FLOOR(4)"
????when?
????????"本次操作如果"?"拉或拉開或斷開"?"某某"?"地刀"
????then?
????????"設置標記為:"4
end
rule?"合或合上##地刀操作設置“操作標志”為RULES_IS_CLOSE_SWITCH_FLOOR(5)"
????when?
????????"本次操作如果"?"合或合上"?"某某"?"地刀"
????then?
????????"設置標記為:"5
end
rule?"安裝地線操作時設置“操作標志”為RULES_IS_FIX_FLOOR_LINE(6)"
????when?
????????"本次操作如果"?"安裝"?"某某"?"地線"
????then?
????????"設置標記為:"6
end
rule?"拆除地線操作時設置“操作標志”為RULES_IS_UNFIX_FLOOR_LINE(7)"
????when?
????????"本次操作如果"?"拆除"?"某某"?"地線"
????then?
????????"設置標記為:"7
end2.rules.dsl文件的定義
[when]"本次操作如果" {action} "某某" {dev}=vb:ValueBean(itemc:content->(judge(itemc,{action},{dev})))
[then]"設置標記為:"{level}=operateRulesService.setResult(vb,new Long({level}));
3.RulesServiceImpl類
package?com.mip.biz.operatebill.services.imp;

import?org.drools.WorkingMemory;

import?com.mip.biz.operatebill.objects.ValueBean;
import?com.mip.biz.operatebill.services.RulesService;
import?com.mip.core.jbossrules.DroolsTemplate;


/**?*//**
?*?<p>?
?*?處理操作票中的一引起邏輯規則
?*?</p>
?*?@author?Libin
?*?@date?Mar?17,?2007
?*?@version?4.0
?*
?*?@see?AnotherClass
?*/

public?class?RulesServiceImpl?implements?RulesService?
{


????/**?*//**?Drools的封裝便利函數,返回WorkingMemory?*/
????private?DroolsTemplate?operateReluesTemplate;
????

????/**?*//**
?????*?A?judge?function
?????*?<p>?運行規則?</p>
?????*?@param?valueBean
?????*/

????public?void?runRules(ValueBean?valueBean)
{
????????WorkingMemory?wm?=?operateReluesTemplate.getWorkingMemory(valueBean);
????????//注入本類,提供各種簡便函數供規則中使用

????????if(wm.getGlobal(OPERATE_RULES_SERVICE_NAME)==null)
{
????????????wm.setGlobal(OPERATE_RULES_SERVICE_NAME,?this);
????????}
????????wm.fireAllRules();????????
????}
????

????/**//*?(非?Javadoc)
?????*?@see?com.mip.biz.operatebill.services.RulesService#setResult(com.mip.biz.operatebill.objects.ValueBean,?java.lang.Long)
?????*/

????public?void?setResult(ValueBean?valueBean,?Long?result)?
{
????????//?TODO?Auto-generated?method?stub

????????switch(result.intValue())
{
????????????//拉閘操作
????????????case?RULES_IS_OPEN_SWITCH:
????????????????valueBean.setOpenSwitch(new?Boolean(true));
????????????????valueBean.setStress(new?Boolean(true));
????????????????break;
????????????//合閘操作
????????????case?RULES_IS_CLOSE_SWITCH:
????????????????valueBean.setCloseSwitch(new?Boolean(true));
????????????????valueBean.setStress(new?Boolean(true));
????????????????break;????????????????
????????????//拉地刀閘操作
????????????case?RULES_IS_OPEN_SWITCH_FLOOR:
????????????????valueBean.setOpenSwitchFloor(new?Boolean(true));
????????????????valueBean.setStress(new?Boolean(true));
????????????????break;
????????????//合地刀閘操作
????????????case?RULES_IS_CLOSE_SWITCH_FLOOR:
????????????????valueBean.setCloseSwitchFloor(new?Boolean(true));
????????????????valueBean.setStress(new?Boolean(true));
????????????????break;????
????????????//裝地線操作
????????????case?RULES_IS_FIX_FLOOR_LINE:
????????????????valueBean.setFixFloorLine(new?Boolean(true));
????????????????valueBean.setStress(new?Boolean(true));
????????????????break;
????????????//拆地線操作
????????????case?RULES_IS_UNFIX_FLOOR_LINE:
????????????????valueBean.setUnfixFloorLine(new?Boolean(true));
????????????????valueBean.setStress(new?Boolean(true));
????????????????break;????
????????}
????????valueBean.setResult(result);
????}
????

????/**//*?(非?Javadoc)
?????*?@see?com.mip.biz.operatebill.services.RulesService#isStress(com.mip.biz.operatebill.objects.ValueBean)
?????*/

????public?boolean?isStress(ValueBean?valueBean)?
{
????????//?TODO?Auto-generated?method?stub
????????return?valueBean.getStress();
????}



????/**//*?(非?Javadoc)
?????*?@see?com.mip.biz.operatebill.services.RulesService#isCloseSwith(com.mip.biz.operatebill.objects.ValueBean)
?????*/

????public?boolean?isCloseSwitch(ValueBean?valueBean)?
{
????????//?TODO?Auto-generated?method?stub
????????return?valueBean.getCloseSwitch();
????}


????public?boolean?isCloseSwitchFloor(ValueBean?valueBean)?
{
????????//?TODO?Auto-generated?method?stub
????????return?valueBean.getCloseSwitchFloor();
????}


????public?boolean?isOpenSwitchFloor(ValueBean?valueBean)?
{
????????//?TODO?Auto-generated?method?stub
????????return?valueBean.getOpenSwitchFloor();
????}
????

????/**//*?(非?Javadoc)
?????*?@see?com.mip.biz.operatebill.services.RulesService#isOpenSwitch(com.mip.biz.operatebill.objects.ValueBean)
?????*/

????public?boolean?isOpenSwitch(ValueBean?valueBean)?
{
????????//?TODO?Auto-generated?method?stub
????????return?valueBean.getOpenSwitch();
????}

????

????public?void?setOperateReluesTemplate(DroolsTemplate?operateReluesTemplate)?
{
????????this.operateReluesTemplate?=?operateReluesTemplate;
????}


????public?boolean?isFixFloorLine(ValueBean?valueBean)?
{
????????//?TODO?Auto-generated?method?stub
????????return?valueBean.getFixFloorLine();
????}


????public?boolean?isUnfixFloorLine(ValueBean?valueBean)?
{
????????//?TODO?Auto-generated?method?stub
????????return?valueBean.getUnfixFloorLine();
????}
}

posted on 2007-03-19 19:41
Lib 閱讀(1489)
評論(2) 編輯 收藏 所屬分類:
開源框架