posts - 28,  comments - 13,  trackbacks - 0
          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
          end

          2.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 閱讀(1496) 評論(2)  編輯  收藏 所屬分類: 開源框架


          FeedBack:
          # re: 應用Jboss rules規則引擎,以中文定義業務規則
          2008-04-02 19:11 | oracle
          請問在DRL檔裡能使用中文嗎?
          我試了許多方法好像不行?  回復  更多評論
            
          # re: 應用Jboss rules規則引擎,以中文定義業務規則
          2008-04-04 09:20 | Lib
          規則引擎文件要以UTF-8編碼  回復  更多評論
            
          <2025年6月>
          25262728293031
          1234567
          891011121314
          15161718192021
          22232425262728
          293012345



          我的JavaEye博客
          http://lib.javaeye.com


          常用鏈接

          留言簿(2)

          隨筆分類

          文章分類

          FLASH

          Java

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 翼城县| 江油市| 贵溪市| 贺兰县| 永德县| 河曲县| 滁州市| 溧水县| 高邮市| 札达县| 湟源县| 新河县| 东台市| 武穴市| 余庆县| 潢川县| 丰都县| 博罗县| 玉门市| 山阳县| 武冈市| 南靖县| 巴林左旗| 天水市| 盐亭县| 奉新县| 兰坪| 聂荣县| 灌南县| 宁远县| 河西区| 泸州市| 古浪县| 乾安县| 连城县| 巴南区| 镇巴县| 论坛| 赤峰市| 内黄县| 遂平县|