Uploaded image for project: 'Drools'
  1. Drools
  2. DROOLS-664

Implement xpath notation in drools constraints

    XMLWordPrintable

Details

    • Feature Request
    • Resolution: Done
    • Major
    • 6.4.0.Final
    • None
    • None
    • None

    Description

      It is required to allow an xpath notation in drools constraints like the following:

      Person( $pet : /pets ) 
      

      that is formally equivalent to the more verbose:

      Person( $pets : pets )
      $pet : Pet() from $pets
      

      It should be also possible to have conditions filtering the collection like in:

      Person( $pet : /pets[ age == 5 ] )
      

      corresponding to:

      Person( $pets : pets )
      $pet : Pet(age == 5) from $pets
      

      Of course also multiple indirections has to be allowed, so the following:

      Man( $toy : /wife/children/toys )
      

      will be equivalent to:

      $man: Man( $wife: wife )
      $child: Child() from $wife.children
      $toy: Toy() from $child.toys
      

      In this case the xpath notation will also allow to flatten the 2 from nodes in a single one that will internally flatten the collection of collections. Since it is necessary to distinguish the case when we want to iterate a collection from the case when we want to bind the collection as a whole it is possible to mix the collection iteration operator '/' and the simple dereferencing operator '.' as in:

      Man( $toys : /wife/children.toys )
      

      In this last case this pattern binds each List<Toy> for each child as a whole, so this is equivalent to:

      $man: Man( $wife: wife )
      Child( $toys: toys ) from $wife.children
      

      Attachments

        Issue Links

          Activity

            People

              mfusco@redhat.com Mario Fusco
              mfusco@redhat.com Mario Fusco
              Votes:
              1 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: