rule "First Rule"
when
ClassA( stringAttr == "xyz" )
ClassB( intAttr > 50 )
then
// do some java code
end
In this example, where is the call made to the getStringAttr() and getIntAttr()
methods on instances of ClassA and ClassB ??
rule "First Rule"
when
objA : ClassA( stringAttr == "xyz" )
objB : ClassB( intAttr > 50 )
then
// do some java code
System.out.println(objA);
System.out.println(objB);
end
Here, are objA and objB Boolean ?
________________________________
From: Edson Tirelli [mailto:[EMAIL PROTECTED]
Sent: Thu 4/13/2006 3:47 PM
To: [email protected]
Subject: Re: [drools-user] The DRL notation vs. jbossrules Rule Language - ?
All,
Find in the following link, the documentation that is being built
for drools 3.
http://labs.jboss.com/portal/jbossrules/docs
On a quick explanation, the new syntax would be:
------------
rule "name"
ATTRIBUTES
when
LHS
then
RHS
end
------------
ATTRIBUTES: those are rule attributes like salience, duration, etc, in a
similar way Drools 2.x uses.
LHS: this is the left hand side of the rule. This is the previous
"parameter" + "condition" statements. (see bellow)
RHS: this is the right hand side of the rule. This is the consequence,
the same way in drools 2.
I think the simple way to explain LHS is to make a conversion example:
<rule name="First Rule">
<parameter identifier="objA">
<class>ClassA</class>
</parameter>
<parameter identifier="objB">
<class>ClassB</class>
</parameter>
<java:condition> objA.getStringAttr().equals("xyz") </java:condition>
<java:condition> objB.getIntAttr() > 50 </java:condition>
<java:consequence>
// some java code
</java:consequence>
</rule>
The above rule when converted to Drools 3 would became:
rule "First Rule"
when
ClassA( stringAttr == "xyz" )
ClassB( intAttr > 50 )
then
// do some java code
end
If you need a reference to the actual object matched in each "column"
(more or less what Drools 2 call parameter), you can bind it in the
following way:
rule "First Rule"
when
objA : ClassA( stringAttr == "xyz" )
objB : ClassB( intAttr > 50 )
then
// do some java code
System.out.println(objA);
System.out.println(objB);
end
In the documentation you will find syntax diagrams that can help you
understand all possible syntaxes and all the new operators/features
drools 3 has.
[]s
Edson
Ronald van Kuijk wrote:
>AINAE, but it could be as simple as 'replacing' condition with when and
>consequence with then, but I'll let the experts tell me.
>
>Ronald
>
>2006/4/13, Dmitry Goldenberg <[EMAIL PROTECTED]>:
>
>
>>I don't understand the relationship between the XML-based DRL notation and
>>this new lingo with "when" / "then".
>>
>>With the DRL notation, my understanding is that you write an XML structure
>>like the one I'm including below. How does this change with the when/then
>>notation? Thanks.
>>
>>
>><?xml version="1.0"?>
>>
>><rule-set name="SamplePolicyRuleSet"
>>
>> xmlns="http://drools.org/rules"
>>
>> xmlns:java="http://drools.org/semantics/java"
>>
>> xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"
>>
>> xs:schemaLocation="http://drools.org/rules rules.xsd
>>http://drools.org/semantics/java java.xsd">
>>
>>
>>
>> <!-- Imports -->
>>
>> <java:import>java.lang.Object</java:import>
>>
>> <java:import>java.lang.String</java:import>
>>
>> <!-- Utility functions -->
>>
>> <java:functions>
>>
>> public boolean f1(com.weblayers.platform.rule.PolicyExecContextcontext)
>>
>> {
>>
>> return ...;
>>
>> }
>>
>> public boolean f2(com.weblayers.platform.rule.PolicyExecContextcontext)
>>
>> {
>>
>> return ...;
>>
>> }
>>
>> </java:functions>
>>
>>
>>
>> <!-First Rule: IF (P1 AND P2) THEN RETURN OK -->
>>
>> <rule name="First Rule">
>>
>> <!-- Rule parameters -->
>>
>> <parameter identifier="context">
>>
>> <class>MyContext</class>
>>
>> </parameter>
>>
>>
>>
>> <!-- Rule Conditions -->
>>
>> <java:condition>
>>
>> f1() && f2()
>>
>> </java:condition>
>>
>>
>>
>> <!-- Rule Consequences -->
>>
>> <java:consequence>
>>
>> context.setReturn(Constants.OK);
>>
>> </java:consequence>
>>
>> </rule>
>>
>>
>>
>> <!-Second Rule: IF (!(P1 AND P2)) THEN RETURN FAILURE -->
>>
>> <rule name="Second Rule">
>>
>> <!-- Rule parameters -->
>>
>> <parameter identifier="context">
>>
>> <class>MyContext</class>
>>
>> </parameter>
>>
>>
>>
>> <!-- Rule Conditions -->
>>
>> <java:condition>
>>
>> !(f1() && f2())
>>
>> </java:condition>
>>
>>
>>
>> <!-- Rule Consequences -->
>>
>> <java:consequence>
>>
>> context.setVerdict(Constants.FAIL);
>>
>> </java:consequence>
>>
>> </rule>
>>
>>
>>
>></rule-set>
>>
>>
>>
>>
>>
>>
>>
>
>
>
--
---
Edson Tirelli
Auster Solutions do Brasil
@ www.auster.com.br
+55 11 5096-2277 / +55 11 9218-4151