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>