|
FileReader fr=new
FileReader("logic.sl");
//parse the logic set
RuleServiceProvider serviceProvider = (RuleServiceProvider)Class.forName("witmate.core.kernel.ServiceProvider").newInstance();
RuleExecutionSet res =
serviceProvider.getRuleAdministrator().getLocalRuleExecutionSetProvider(
null ).createRuleExecutionSet( fr, new Hashtable());
//Register the RuleExecutionSet
serviceProvider.getRuleAdministrator().registerRuleExecutionSet("A
Rule URI", res, null );
//Get a RuleRuntime and invoke the rule
engine.
RuleRuntime ruleRuntime =
serviceProvider.getRuleRuntime();
//Generate inputs
ConstantVariable V1=new ConstantVariable();
V1.name="sex";
V1.type=ConstantValues.DT_STR;
V1.value="female";
ConstantVariable V2=new ConstantVariable();
V2.name="age";
V2.type=ConstantValues.DT_INT;
V2.value=new Integer(20);
Vector in_vars=new Vector();
in_vars.addElement(V1);
in_vars.addElement(V2);
//Create a StatelessRuleSession
StatelessRuleSession statelessRuleSession =
(StatelessRuleSession)
ruleRuntime.createRuleSession(res.getName(),
new Hashtable(), RuleRuntime.STATELESS_SESSION_TYPE);
//Run logic and get result.
Vector results = statelessRuleSession.executeRules(in_vars);
//Release the session.
statelessRuleSession.release();
|