<br><br><div class="gmail_quote">2010/11/28 Chris Selwyn <span dir="ltr"><<a href="mailto:chris@selwyn-family.me.uk">chris@selwyn-family.me.uk</a>></span><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div bgcolor="#ffffff" text="#000000">
Hi Wolfgang,<br>
<br>
Thanks for the helpful response.<br>
<br>
I do find myself using "contains" and "memberof" quite a lot
depending on whether I am going "up" or "down" the tree structure.
Is this a performance problem? Is it better to use "from"?<br></div></blockquote><div><br>contains and memberof are OK to use; they are 1st class "citizen" operators.<br>�</div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div bgcolor="#ffffff" text="#000000">
Thanks for the hint about adding the "parent" pointer in the child.
I'll have to think about that one because the schema is actually
shared with external trading partners.<br></div></blockquote><div><br>The addition I propose has no influence on the XML data; it'll just let you generate what you need in you JAXB generated classes. Or a simple XSLT transformation might create the xjc input from the "official" XML schema.<br>
�</div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div bgcolor="#ffffff" text="#000000">
I guess I could have an "external" version and and "internal"
version but then I would have 2 versions to maintain and that is not
very desirable.<br></div></blockquote><div><br>Consider the XSLT proposal.<br>�</div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div bgcolor="#ffffff" text="#000000">
As someone else has asked, I do actually make modifications to the
model that I want to return to the client. So it is not read-only.
That means I would then have to do a post-rule processing pass to
null out the parent pointers (otherwise I would have cycles in the
graph!) before returning the answer. Actually... @XmlTransient will
probably have the desired effect.<br></div></blockquote><div><br>This is an annotation you can add when you start from hand-coded Java. But it shouldn't be a problem to write rules (or Java code) setting all the parent pointer to null before you marshal everything back.<br>
�</div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div bgcolor="#ffffff" text="#000000">
<br>
(Thinks: I wonder whether it would be possible to write a JAXB
plugin to do this stuff and make the generated classes more
"rules-friendly")<br></div></blockquote><div><br>There's no generally applicable procedure, I'd say. <br>�</div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div bgcolor="#ffffff" text="#000000">
<br>
Thanks also for the hint about the code injection plugin. I was not
aware of that. I have just done some investigation into that and I
find that the code-injection plugin is present� in my Glassfish
server but is not named in the
META-INF/services/com.sun.tools.xjc.Plugin file. So I'm not sure
that I can use it without getting a separate installation of JAXB.<br></div></blockquote><div><br>This is a deficiency in some JAXB version that (I think) is distributed with Java 1.6.x. You can add the missing line to the file, and it'll work; or you can get the latest JAXB release and use this, superceding what comes with JDK.<br>
<br>-W<br>�</div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div bgcolor="#ffffff" text="#000000">
<br>
Chris<br>
<br>
<br>
On 28/11/2010 13:12, Wolfgang Laun wrote:
<blockquote type="cite">An XML schema just fitting your XML data will
frequently not result in a class<br>
hierarchy that's well suited for writing rules.<br>
<br>
One point deals with representing the parent-child relationship,
especially<br>
when there are multiple children of a kind, i.e., the parent class
contains a<br>
List<?>. You have this in XML the natural way; you lose it
when you just<br>
insert parents and children.� If extending the XML schema is
possible, you<br>
can add another element with minOccurs="0" to the Child
complexType of<br>
type Parent and set the reference to the current parent when you
walk the<br>
object tree. (You can erase the List<?> in the parent.) This
avoids the<br>
frequent use of the "from" clause in conditions.<br>
<br>
You may also have to handle repeated occurrences of elements that
are<br>
"equal" as objects but appear in full XML text; this is usually
simple to handle<br>
with a temporary Set, but you'll have to add hashCode and equals
to the<br>
JAXB generated classes using the code injection plugin.<br>
<br>
Inserting just the root element is not advisable, as you are well
aware of.<br>
<br>
-W<div><div></div><div class="h5"><br>
<br>
<br>
<br>
<div class="gmail_quote">On 28 November 2010 12:38, Chris Selwyn <span dir="ltr"><<a href="mailto:chris@selwyn-family.me.uk" target="_blank">chris@selwyn-family.me.uk</a>></span>
wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">I am working on a project that is using Drools to
perform validation of<br>
hierarchical XML messages.<br>
<br>
So I have passed the XSDs through JAXB and have a set of
interrelated<br>
Java objects.<br>
One of these objects (naturally) represents the root of the
messages and<br>
the others represent the intermediate and leaf nodes of the
message.<br>
<br>
My question is: Should I traverse the tree and insert each
object into<br>
the working memory or should I just insert the root object
into the<br>
working memory?<br>
<br>
If I insert each object into the memory then I have a lot of
flexibility<br>
about how I write my rules... I can start by focussing on the
particular<br>
part of the message that I want to detect an error in.<br>
However, I then have to perform a whole bunch of "joining"
clauses to<br>
correctly "connect up" to the other objects in the working
memory.<br>
(This is how I am doing it at the moment... I have a mechanism
that uses<br>
the Java Introspector. It identifies by package name which
parts of the<br>
data model get inserted into the WM)<br>
<br>
On the other hand, I could just insert the root object into
the WM. This<br>
means that I would have to write really complicated where
clauses on the<br>
root object but very much simplifies the WM loading process.<br>
<br>
All of the examples that I have seen have a very simple flat<br>
(non-hierarchical) structure that don't really give a hint as
to what a<br>
"best practice" might be.<br>
<br>
Any suggestions/insights welcome :-)<br>
<font color="#888888"><br>
Chris Selwyn<br>
_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org" target="_blank">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
</font></blockquote>
</div>
<br>
<pre><fieldset></fieldset>
_______________________________________________
rules-users mailing list
<a href="mailto:rules-users@lists.jboss.org" target="_blank">rules-users@lists.jboss.org</a>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a>
</pre>
<br>
<fieldset></fieldset>
<br>
</div></div><p color="#000000" align="left">No virus found in
this message.<br>
Checked by AVG - <a href="http://www.avg.com" target="_blank">www.avg.com</a><br>
Version: 10.0.1170 / Virus Database: 426/3284 - Release Date:
11/27/10</p>
</blockquote>
</div>
<br>_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
<br></blockquote></div><br>