Hi,
I am using spring module (with drools) to fire the rules. How can I
setSource at the runtime? I am hard coding a different drl file in
setSource() method yet when the rule is executed it fires the rule based on
.drl set in the applicationContext.xml
My issue is that the drl file name might change frequently and on basis of
that I would like to fire the rules. Is it possible to change the drl name
dynamically at runtime?
Any advice would be great help.
--
Thanks
Ck
http://www.gfour.net
The code is given below
-- code --
public class RuleServiceDrools implements RuleService{
private DefaultRuleSource rs = null;
private Jsr94Template template = null;
public List fireRules(List users) {
final List list = users;
setSource();
// TODO Auto-generated method stub
Object obj = getTemplate().executeStateless("vaccination",null,new
StatelessRuleSessionCallback() {
public Object execute(StatelessRuleSession session) throws
InvalidRuleSessionException, RemoteException {
return session.executeRules(list);
}
});
return (List)obj;
}
public void setSource() {
Resource res = new FileSystemResource("/enfold/rules/vaccination2.drl");
rs = (DefaultRuleSource)getTemplate().getRuleSource();
rs.setSource(res);
}
public DefaultRuleSource getRs() {
return rs;
}
public void setRs(DefaultRuleSource rs) {
rs.setBindUri("what");
this.rs = rs;
}
public Jsr94Template getTemplate() {
return template;
}
public void setTemplate(Jsr94Template template) {
this.template = template;
}
}
-- code end --
applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="ruleServiceProvider"
class="org.springmodules.jsr94.factory.DefaultRuleServiceProviderFactoryBean">
<property name="provider">
<
value>http://drools.org/</value>
</property>
<property name="providerClass">
<value>org.drools.jsr94.rules.RuleServiceProviderImpl</value>
</property>
</bean>
<bean id="ruleRuntime"
class="org.springmodules.jsr94.factory.RuleRuntimeFactoryBean">
<property name="serviceProvider">
<ref local="ruleServiceProvider" />
</property>
</bean>
<bean id="ruleAdministrator"
class="org.springmodules.jsr94.factory.RuleAdministratorFactoryBean">
<property name="serviceProvider">
<ref local="ruleServiceProvider" />
</property>
</bean>
<bean id="ruleSource"
class="org.springmodules.jsr94.rulesource.DefaultRuleSource">
<property name="ruleRuntime">
<ref local="ruleRuntime" />
</property>
<property name="ruleAdministrator">
<ref local="ruleAdministrator" />
</property>
<property name="source">
<value>/enfold/rules/vaccination2.drl</value>
</property>
<property name="bindUri">
<value>vaccination</value>
</property>
</bean>
<bean id="jsr94Template"
class="org.springmodules.jsr94.core.Jsr94Template">
<property name="ruleSource">
<ref local="ruleSource" />
</property>
</bean>
<bean id="ruleService"
class="enfold.rules.service.impl.RuleServiceDrools">
<property name="template">
<ref local="jsr94Template" />
</property>
</bean>
<bean id="memberDao" class="enfold.dao.dummy.MemberDaoDummy"
/>
<bean id="ruleObjectbuilder"
class="enfold.rules.RuleObjectBuilderDatabase">
<property name="memberDao">
<ref local="memberDao"/>
</property>
</bean>
<bean id="service" class="enfold.rules.ServiceImpl">
<property name="ruleObjectbuilder">
<ref local="ruleObjectbuilder"/>
</property>
<property name="ruleService">
<ref local="ruleService"/>
</property>
</bean>
</beans>
--
View this message in context:
http://www.nabble.com/dynamically-get-drl-using-spring-module-tf3778174.h...
Sent from the drools - user mailing list archive at
Nabble.com.