[rules-users] declare variable
fakhfakh ismail
ismail_info2005 at yahoo.fr
Tue May 15 03:45:32 EDT 2007
hello
first thank you for your help.
But I don't know how declare the wariable.
workingMemory.setGlobal("L", new java.util.List());
the code used to execute my rule is :
public List fireRules(List dataObjects, InputStream rules) throws Exception {
// obtain the rule service provider
RuleServiceProviderManager.registerRuleServiceProvider(
"org.drools.jsr94.rules.RuleServiceProviderImpl",
org.drools.jsr94.rules.RuleServiceProviderImpl.class);
RuleServiceProvider service =
RuleServiceProviderManager.getRuleServiceProvider(
"org.drools.jsr94.rules.RuleServiceProviderImpl");
// load the rule adminstrator
RuleAdministrator admin = service.getRuleAdministrator();
// load the rules and register them
RuleExecutionSet res1 =
admin.getLocalRuleExecutionSetProvider( null ).
createRuleExecutionSet( rules, null );
rules.close();
String bindUri = "res:://sample.drl";
admin.registerRuleExecutionSet(bindUri, res1, null);
// obtain a rule runtime object from the rule service provider
RuleRuntime runtime = service.getRuleRuntime();
// create a stateless object from the Rule Runtime
StatelessRuleSession session = (StatelessRuleSession)
runtime.createRuleSession(bindUri, null, RuleRuntime.STATELESS_SESSION_TYPE);
List resultRules = session.executeRules(dataObjects);
//session.
session.release();
// workingMemory.setGlobal("L", new java.util.List());
return resultRules;
}
please help me,
best regards
Ismail
Scott Reed <sreed at spamcop.net> a écrit : fakhfakh ismail's message received 5/14/2007 3:48 PM:
> Hello,
> first sorry for my bad english.
> I want to declare a variable of type List
>
> rule "userrole"
>
> when
> $user1: User (userid1: userId)
> $user2: User (userId == userid1)
> then
> List L = new ArrayList();
> if (L.contains($user1.getname())== false)
> {
> L.add($user1.getname());
> System.out.println("hello");
> }
> end
>
> the problem is everytime the List don't save all element every execution
> the variable list is intialised as empty is there other place to
> declare List?
> (I try after when but error of parsing)
You need to declare the List in your Java code, set it as a Drools global, and declare it in the DRL
file:
In yourjava.java:
-----------
workingMemory.setGlobal("L", new java.util.List());
-----------
in yourdrl.drl:
-----------
global java.util.List L;
rule "userrole"
when
$user1: User (userid1: userId)
$user2: User (userId == userid1)
then
if (L.contains($user1.getname())== false)
{
L.add($user1.getname());
System.out.println("hello");
}
end
-----------
Wouldn't it be great to have a "static" section in the DRL syntax for temporaries like this?
_______________________________________________
rules-users mailing list
rules-users at lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users
---------------------------------
Ne gardez plus qu'une seule adresse mail ! Copiez vos mails vers Yahoo! Mail
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20070515/c611252b/attachment.html
More information about the rules-users
mailing list