An XML schema just fitting your XML data will frequently not result in a class
hierarchy that's well suited for writing rules.
One point deals with representing the parent-child relationship, especially
when there are multiple children of a kind, i.e., the parent class contains a
List<?>. You have this in XML the natural way; you lose it when you just
insert parents and children. If extending the XML schema is possible, you
can add another element with minOccurs="0" to the Child complexType of
type Parent and set the reference to the current parent when you walk the
object tree. (You can erase the List<?> in the parent.) This avoids the
frequent use of the "from" clause in conditions.
You may also have to handle repeated occurrences of elements that are
"equal" as objects but appear in full XML text; this is usually simple to handle
with a temporary Set, but you'll have to add hashCode and equals to the
JAXB generated classes using the code injection plugin.
Inserting just the root element is not advisable, as you are well aware of.
-W
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
_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users