[rules-users] What should I insert into the working memory?

Chris Selwyn chris at selwyn-family.me.uk
Sun Nov 28 06:38:55 EST 2010


I am working on a project that is using Drools to perform validation of 
hierarchical XML messages.

So I have passed the XSDs through JAXB and have a set of interrelated 
Java objects.
One of these objects (naturally) represents the root of the messages and 
the others represent the intermediate and leaf nodes of the message.

My question is: Should I traverse the tree and insert each object into 
the working memory or should I just insert the root object into the 
working memory?

If I insert each object into the memory then I have a lot of flexibility 
about how I write my rules... I can start by focussing on the particular 
part of the message that I want to detect an error in.
However, I then have to perform a whole bunch of "joining" clauses to 
correctly "connect up" to the other objects in the working memory.
(This is how I am doing it at the moment... I have a mechanism that uses 
the Java Introspector. It identifies by package name which parts of the 
data model get inserted into the WM)

On the other hand, I could just insert the root object into the WM. This 
means that I would have to write really complicated where clauses on the 
root object but very much simplifies the WM loading process.

All of the examples that I have seen have a very simple flat 
(non-hierarchical) structure that don't really give a hint as to what a 
"best practice" might be.

Any suggestions/insights welcome :-)

Chris Selwyn



More information about the rules-users mailing list