<br><br><div class="gmail_quote">2010/11/28 Chris Selwyn <span dir="ltr">&lt;<a href="mailto:chris@selwyn-family.me.uk">chris@selwyn-family.me.uk</a>&gt;</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 &quot;contains&quot; and &quot;memberof&quot; quite a lot
    depending on whether I am going &quot;up&quot; or &quot;down&quot; the tree structure.
    Is this a performance problem? Is it better to use &quot;from&quot;?<br></div></blockquote><div><br>contains and memberof are OK to use; they are 1st class &quot;citizen&quot; 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 &quot;parent&quot; pointer in the child.
    I&#39;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&#39;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 &quot;official&quot; 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 &quot;external&quot; version and and &quot;internal&quot;
    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&#39;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
    &quot;rules-friendly&quot;)<br></div></blockquote><div><br>There&#39;s no generally applicable procedure, I&#39;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&#39;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&#39;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&#39;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&lt;?&gt;. 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=&quot;0&quot; 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&lt;?&gt; in the parent.) This
      avoids the<br>
      frequent use of the &quot;from&quot; clause in conditions.<br>
      <br>
      You may also have to handle repeated occurrences of elements that
      are<br>
      &quot;equal&quot; as objects but appear in full XML text; this is usually
      simple to handle<br>
      with a temporary Set, but you&#39;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">&lt;<a href="mailto:chris@selwyn-family.me.uk" target="_blank">chris@selwyn-family.me.uk</a>&gt;</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 &quot;joining&quot;
          clauses to<br>
          correctly &quot;connect up&quot; 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&#39;t really give a hint as
          to what a<br>
          &quot;best practice&quot; 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>