> To give an example of what I need, in the rules mentioned below, what do > I need to do to pass one/multiple parameter(s) to the method "killCell" > and how should I define that in the xml and xsd.
You need to change the xsd to allow the killCell element to have text children elements. I've no idea if you're familiar with XML Schema, but I usually point people to www.w3schools.com as that has some reasonable introductions into how to do this. If you don't care how this works, then you can just replace the following line: <xs:element name="killCell"/> with: <xs:element name="killCell" type="xs:string" /> That should do it for the xsd -- you'll now be able to place text in your killCell element. Alternatively you could change your xsd to accept an attribute instead. Having altered the xsd, the next step is to alter the Consequence, which for the conway example is org.drools.examples.conway.rules.dsl.KillCellConsequence. You'll probably need to feed in a Declaration (a reference for accessing an object that has been asserted against the working memory), in which case the ConwayConsequenceFactory (in the same package) also needs to be altered, to pass the Declaration of your parameter into the Consequence (in the constructor could be easiest). Then to act on the parameter, the invoke method (which is called every time the consequence is activated) should be changed. Using the Declaration set in construction, the actual object can be retrieved from the Tuple passed into the invoke method. What you do from this point is up to you. I haven't gone into too much detail about the Factory and the Consequence objects, because playing around with the Conway example will show you much more than words in an email could show you. Better just to point you to the right places and let you investigate from there. Is this clear? I'm not sure I've made it any clearer, but happy to answer more questions. I've recently implemented a non-trivial DSL, so this stuff is rather fresh in my mind. Regards, Dave On 11/9/05, saurabh shukla <[EMAIL PROTECTED]> wrote: > Hi All, > > I am trying been playing around with drools and I wanted to know if any > one can give me an example of a rule written in pure DSL like in conway > which passes a parameter to a function/method which is part of a > condition or an action. > > I have pasted conway.xsd and conway.dsl.drl below. > > To give an example of what I need, in the rules mentioned below, what do > I need to do to pass one/multiple parameter(s) to the method "killCell" > and how should I define that in the xml and xsd. > > > > TIA > Saurabh > > > =============== Rules Files ============================ > > <?xml version="1.0"?> > > <rule-set name="conway" > xmlns="http://drools.org/rules" > xmlns:conway="http://drools.org/semantics/conway" > xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" > xs:schemaLocation="http://drools.org/rules rules.xsd > http://drools.org/semantics/conway conway.xsd"> > > <rule name="Kill The Overcrowded"> > <conway:condition cellName="cell"> > <conway:cellIsAlive/> > <conway:cellIsOverCrowded/> > </conway:condition> > > <conway:actions cellName="cell"> > <conway:killCell/> > </conway:actions> > </rule> > > <rule name="Kill The Lonely"> > <conway:condition cellName="cell"> > <conway:cellIsAlive/> > <conway:cellIsLonely/> > </conway:condition> > > <conway:actions cellName="cell"> > <conway:killCell/> > </conway:actions> > </rule> > > <rule name="Give Birth"> > <conway:condition cellName="cell"> > <conway:cellIsDead/> > <conway:cellIsRipeForBirth/> > </conway:condition> > > <conway:actions cellName="cell"> > <conway:giveBirthToCell/> > </conway:actions> > </rule> > </rule-set> > > ==============Schema definition =================== > > <?xml version="1.0" encoding="UTF-8"?> > <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" > targetNamespace="http://drools.org/semantics/conway" > elementFormDefault="qualified" > xmlns:conway="http://drools.org/semantics/conway" > xmlns:rules="http://drools.org/rules"> > > <xs:import namespace="http://drools.org/rules" > schemaLocation="rules.xsd"/> > > <xs:element name="condition" > substitutionGroup="rules:abstractCondition"> > <xs:complexType> > <xs:all> > <xs:element ref="conway:cellIsAlive" minOccurs="0" > maxOccurs="1"/> > <xs:element ref="conway:cellIsDead" minOccurs="0" > maxOccurs="1"/> > <xs:element ref="conway:cellIsOverCrowded" > minOccurs="0" maxOccurs="1"/> > <xs:element ref="conway:cellIsRipeForBirth" > minOccurs="0" maxOccurs="1"/> > <xs:element ref="conway:cellIsLonely" minOccurs="0" > maxOccurs="1"/> > </xs:all> > <xs:attribute name="cellName" type="xs:string"/> > </xs:complexType> > </xs:element> > > <xs:element name="actions" > substitutionGroup="rules:abstractConsequence"> > <xs:complexType> > <xs:sequence> > <xs:choice> > <xs:element ref="conway:killCell"/> > <xs:element ref="conway:giveBirthToCell"/> > </xs:choice> > </xs:sequence> > <xs:attribute name="cellName" type="xs:string"/> > </xs:complexType> > </xs:element> > > <xs:element name="killCell"/> > <xs:element name="giveBirthToCell"/> > <xs:element name="cellIsAlive"/> > <xs:element name="cellIsDead"/> > <xs:element name="cellIsOverCrowded"/> > <xs:element name="cellIsLonely"/> > <xs:element name="cellIsRipeForBirth"/> > > </xs:schema> >
