[rules-users] java.lang.ClassCastException error
kissro at lidp.com
kissro at lidp.com
Mon Sep 10 12:49:57 EDT 2007
I have created a .drl file that contains the following rule:
rule "Underwriting Rule 1"
dialect "mvel"
when
p : Policy( premium < "50.00" )
then
p.setStatus( 32 );
end
The code below processes the rule:
public void main(Policy inputPolicy) throws Exception
{
RuleBase ruleBase = buildPackage();
StatefulSession session = ruleBase.newStatefulSession();
session.insert(inputPolicy);
session.fireAllRules();
}
private RuleBase buildPackage () throws IOException, Exception
{
final PackageBuilder builder = new PackageBuilder();
builder.addPackageFromDrl( new InputStreamReader(
UnderwritingRule.class.getResourceAsStream(
"/underwriting.drl" ) ) );
final RuleBase ruleBase = RuleBaseFactory.newRuleBase();
ruleBase.addPackage( builder.getPackage() );
return ruleBase;
}
The code and rule above process just fine, without any errors.
Using the BRMS web interface, I've created a rule and compiled it into a
package. The rule created via BRMS looks like this:
rule "Underwriting Rule 1"
dialect "mvel"
when
p : Policy( premium < "50.00" )
then
p.setStatus( 32 );
end
I've deployed the rule package and the code below processes it:
public void main(Policy inputPolicy) throws Exception
{
RuleBase ruleBase = loadRuleBase();
StatefulSession session = ruleBase.newStatefulSession();
session.insert(inputPolicy);
session.fireAllRules();
}
private RuleBase loadRuleBase() throws IOException, Exception
{
RuleAgent.newRuleAgent("/brmsunderwritingrules.properties");
RuleBase ruleBase = agent.getRuleBase();
return ruleBase;
}
Now, when I run the above code, I get an error -
ERROR [STDERR] RuleAgent(default) INFO Configuring with
newInstance=true, secondsToRefresh=30
ERROR [STDERR] RuleAgent(default) INFO Configuring package provider :
DirectoryScanner scanning dir: \deployed\rules found 1
file(s).
INFO [STDOUT] Error - java.lang.ClassCastException: java.util.HashSet
In the 2nd sample of code, I'm using a rule package and am using the
RuleAgent to load the rule base but I don't know why I getting the
java.lang.ClassCastException error. Does anyone know why?
Rod
More information about the rules-users
mailing list