|
Hi,
i have some troubles to undestand how drools processes FACTS. I have a POJO class resulted from an UnMarshal jaxb processing like this: public MyClass { protected String className = "Class1"; public getClassName(){ return className; } public setClassName(String className){ this.className = className } } Now i have to compose a drl file with a rule like this: when $Class : MyClass() eval ($Class.getClassName() == "Class1") then System.out.println("ok!!!"); end This syntax doesn't rise errors BUT doesn't match the real name... no ok message are printed. when $Class : MyClass (getClassName() == "Class1") then System.out.println("ok!!!"); end This syntax raises me a null pointer exception!!! What's the right syntax? Can i use the accessor methods building drools facts? Thanks a lot! |
|
As soon as you use eval(), you are in Java-land where String
comparisons should not be made using "==". There's nothing wrong with the second form, i.e., you can write (using Drools 5.3.0) MyClass (getClassName() == "Class1") although the simpler form is usually preferred: MyClass( className == "Class1" ) -W On 27/02/2012, aliosha79 <[hidden email]> wrote: > Hi, > i have some troubles to undestand how drools processes FACTS. I have a POJO > class resulted from an UnMarshal jaxb processing like this: > > public MyClass { > > protected String className = "Class1"; > > public getClassName(){ > return className; > } > > public setClassName(String className){ > this.className = className > } > > } > > > Now i have to compose a drl file with a rule like this: > > > when > $Class : MyClass() > eval ($Class.getClassName() == "Class1") > then > System.out.println("ok!!!"); > end > > > This syntax doesn't rise errors BUT doesn't match the real name... no ok > message are printed. > > > when > $Class : MyClass (getClassName() == "Class1") > then > System.out.println("ok!!!"); > end > > This syntax raises me a null pointer exception!!! > > > What's the right syntax? > Can i use the accessor methods building drools facts? > Thanks a lot! > > -- > View this message in context: > http://drools.46999.n3.nabble.com/Drools-facts-using-POJO-accessor-methods-error-tp3780387p3780387.html > Sent from the Drools: User forum mailing list archive at Nabble.com. > _______________________________________________ > rules-users mailing list > [hidden email] > https://lists.jboss.org/mailman/listinfo/rules-users > rules-users mailing list [hidden email] https://lists.jboss.org/mailman/listinfo/rules-users |
|
ok thanks a lot!
|
|
In reply to this post by laune
what would be the right syntax using the second form, if i wanted to use two rows? like the first one?
Something like this? when $Class : MyClass() $Class(className() == "Class1") ....... ? thanks |
|
I'm not sure what you're asking, but I'm you'll find the answer easily enough by
reading the Expert documentation. -W On 27 February 2012 17:59, aliosha79 <[hidden email]> wrote: what would be the right syntax using the second form, if i wanted to use two _______________________________________________ rules-users mailing list [hidden email] https://lists.jboss.org/mailman/listinfo/rules-users |
|
This post was updated on .
Precisely i want to turn this form...
when $Class : MyClass (className() == "Class1") then System.out.println("ok!!!"); end into this: when $Class : MyClass() ...($Class.className() == "Class1") then System.out.println("ok!!!"); end I need to declare the $Class variable separately... is it possible? regards |
|
Now this is an interesting use case.... could you please provide more details on why you're trying to do such a thing? Are you working on some kind of translator/analyzer?
Thanks Davide btw, taking constraints out of patterns does not seem the best way to use a RETE engine.... could you consider something like: when $Class : MyClass() MyClass( this == $Class, className == "Class1" ) then ... or its equivalent, based on unification: when $Class := MyClass( ) $Class := MyClass( className == "Class1" ) then .... |
|
my use case is:
XmlDocument ---> via JaxbUnmarshaller ---> POJO java Document I m implementing a rule editor... This ruleeditor analyzes the xmldocument and graphically allows me to build rules by selecting the document xml tree node... of course i can just build several rules in this way... but for the field which the project is located in, it's sufficient. Now in those xml documents there could be sequences of elements which are turned into java list by Jaxb. The problem is: According to my xml nodes selection (ie the node is a list or not)... i have to be able to write the exact rule. In the rule structure i have to find the constant parts and the variable ones. For a normal node element a possible rule structure is: when $Class : MyClass( property == 123) then do somthing! end For a list instead: when $Class : MyClass ($list :listProperty) ...( this.ListItem.Quantity.Value ==123 ) from $list then do something! end So, i'm trying to find a common form with the minimum variable parts to be changed and to obtain a well written rule for both cases. |
|
Maybe you would be better off leveraging Guvnor for the Rules Editing. Then you would just need to develop a hook that calls JAXB to take an XML Schema to a Pojo Object Model within the Guvnor system.
Brad Davis Red Hat Consulting Email: [hidden email] | c: 980.226.7865 | http://www.redhat.com ----- Original Message ----- From: "aliosha79" <[hidden email]> To: [hidden email] Sent: Monday, February 27, 2012 1:30:41 PM Subject: Re: [rules-users] Drools facts using POJO accessor methods error my use case is: XmlDocument ---> via JaxbUnmarshaller ---> POJO java Document I m implementing a rule editor... This ruleeditor analyzes the xmldocument and graphically allows me to build rules by selecting the document xml tree node... of course i can just build several rules in this way... but for the field which the project is located in, it's sufficient. Now in those xml documents there could be sequences of elements which are turned into java list by Jaxb. The problem is: According to my xml nodes selection (ie the node is a list or not)... i have to be able to write the exact rule. In the rule structure i have to find the constant parts and the variable ones. For a normal node element a possible rule structure is: when $Class : MyClass( property == 123) then do somthing! end For a list instead: when $Class : MyClass ($list :listProperty) ...( this.ListItem.Quantity.Value ==123 ) from $list then do something! end So, i'm trying to find a common form with the minimum variable parts to be changed and to obtain a well written rule for both cases. -- View this message in context: http://drools.46999.n3.nabble.com/Drools-facts-using-POJO-accessor-methods-error-tp3780387p3781622.html Sent from the Drools: User forum mailing list archive at Nabble.com. _______________________________________________ rules-users mailing list [hidden email] https://lists.jboss.org/mailman/listinfo/rules-users _______________________________________________ rules-users mailing list [hidden email] https://lists.jboss.org/mailman/listinfo/rules-users |
| Powered by Nabble | Edit this page |
