首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 服务器 > 其他服务器 >

想在jbpm的decision节点中使用drools rule进行逻辑判断如何整合下

2012-03-09 
想在jbpm的decision节点中使用drools rule进行逻辑判断怎么整合下?public class decisionaction implement

想在jbpm的decision节点中使用drools rule进行逻辑判断怎么整合下?
public class decisionaction implements DecisionHandler{
private static final long serialVersionUID = 1L;
public String decide(ExecutionContext arg0) throws Exception {
// 对受伤人数进行判断
Object n= (Object) arg0.getVariable("hurtnum");

int num=Integer.parseInt(n.toString());
System.out.println("hurtnum:"+n);
   
//if(num<1){
// go="处理事件";
//}else{
// go="处理受伤";
//}
   
//调用drool规则
DecisionRoolmodel Decision1=new DecisionRoolmodel();
Decision1.setNum(num);
Decision1.setGo("empty");
PackageBuilder builder = new PackageBuilder(); 
try {
builder.addPackageFromDrl( new InputStreamReader( new FileInputStream( "E:\\Eclipse3.2\\workbase\\webapp\\WebContent\\WEB-INF\\classes\\Rules\\rule\\DecisonRool.drl")));
} catch (DroolsParserException e) {
e.printStackTrace();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
RuleBase ruleBase = RuleBaseFactory.newRuleBase(); 
try {
ruleBase.addPackage( builder.getPackage());
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
WorkingMemory workingMemory = ruleBase.newStatefulSession(); 
workingMemory.insert(Decision1);
workingMemory.fireAllRules(); 
System.out.println(Decision1.getGo());
return Decision1.getGo();
}

}
decision的代码就是这个了,就是用DROOLS来代替注释掉的那部分的功能,但是出现了错误
root cause 

java.lang.ClassCastException: Rules.Model.DecisionRoolmodel cannot be cast to Rules.Model.DecisionRoolmodel
Rules.Model.DecisionRoolmodelShadowProxy.setShadowedObject(Unknown Source)
org.drools.reteoo.Rete$ClassObjectTypeConf.getShadow(Rete.java:634)
org.drools.reteoo.Rete.assertObject(Rete.java:164)
org.drools.reteoo.ReteooRuleBase.assertObject(ReteooRuleBase.java:192)

等等。。。
我已经把那个Rules.Model.DecisionRoolmodel 类和流程一起上传到数据库里了,不知是什么问题


[解决办法]
这个错跟你把包放不放到数据库里面是没关系的,是你类型转换出了问题,把整个错误信息贴出来看看
[解决办法]
seam里面有很好的解决方法
<decision name="approval">

<handler class="org.jboss.seam.drools.DroolsDecisionHandler">
<workingMemoryName>orderApprovalRulesWorkingMemory</workingMemoryName>
<assertObjects>
<element>#{customer}</element>
<element>#{order}</element>
<element>#{order.lineItems}</element>
</assertObjects>
</handler>

<transition name="approved" to="ship">
<action class="org.jboss.seam.drools.DroolsActionHandler">
<workingMemoryName>shippingRulesWorkingMemory</workingMemoryName>
<assertObjects>
<element>#{customer}</element>
<element>#{order}</element>
<element>#{order.lineItems}</element>
</assertObjects>
</action>
</transition>

<transition name="rejected" to="cancelled"/>

</decision>

热点排行