commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Rahul Akolkar <rahul.akol...@gmail.com>
Subject Re: [SCXML] Test for node existence with Data()
Date Mon, 23 Mar 2009 17:56:06 GMT
On Mon, Mar 23, 2009 at 9:16 AM, Jaroslav Pullmann
<jaroslav.pullmann@fit.fraunhofer.de> wrote:
>
>
>  Hello,
>
>  while trying to test for the mere existence of a datamodel node it turned
>  out, that Data() yields to different results depending on the availability
>  of an immediate textual content of the node:
>
>
>  1) Example, path does not match, Data() is expected to return null:
>
>  <log label="NULL" expr="Data(data,'objectList/object[@status = 1]') ==
> null" />
>
>  WARNING: Data(): No nodes matching the XPath expression
> "objectList/object[@status = 1]", returning null
>  INFO: NULL: false
>  -> expected: true
>
<snip/>

IIRC, the reason for not returning null here is that the underlying EL
will throw its own exception if further operations (such as the
comparison above) are attempted on the null value. The type coercion
rules used are aimed at allowing simple arithmetic operations (double,
else long, else string) on leaf data nodes.


>  2) Example, same as 1) but tested with empty(), apparently an empty string
> is returned:
>
>  <log label="NULL" expr="empty(Data(data,'objectList/object[@status = 1]'))"
> />
>
>  WARNING: Data(): No nodes matching the XPath expression
> "objectList/object[@status = 1]", returning null
>  INFO: NULL: true
>
<snap/>

Yup.


>
>  3) Example, testing a container with no immediate textual content:
>
>  <log label="EMPTY" expr="empty(Data(data,'objectList/object'))" />
>
>  WARNING: Data(): Multiple nodes matching XPath expression
> "objectList/object", returning first
>  INFO: EMPTY: true
>
<snip/>

You are correct in pointing this out, however, as mentioned above the
coercion rules were really designed for leaf data nodes (more on this
below).


>  4) Example, testing a leaf element with immediate textual content:
>
>  <log label="EMPTY" expr="empty(Data(data,'objectList/object/status'))" />
>
>  WARNING: Data(): Multiple nodes matching XPath expression
> "objectList/object/status", returning first
>  INFO: EMPTY: false
>
<snap/>

Yes, as expected.


>
>  The method apparently invoked in this context: Object
> org.apache.commons.scxml.Builtin#data()
>  calls SCXMLHelper#getNodeValue() to retrieve a textual representation of
> the node. This is done
>  at the level of immediate child nodes, which themselves are not processed
> recursively. According
>  to 1) and 3) there seems to be no test to distiguish whether a node is
> missing at all or it has
>  element only content. For the former I'd expect null as return value,
<snip/>

At the time the decision was made, the general philosophy to avoid EL
blow ups as noted above made sense.


> for
> the latter all text nodes
>  concatenated in a deep frist traversal of all child nodes ?
<snap/>

Possibly. We've generally tried to discourage checking values of
anything other than leaf data nodes i.e. given the proposal, the
following <foo>s will be coerced to the same value, which is
differently strange :-)

  <foo xmlns="">
    A
    <bar>B</bar>
  </foo>

  <foo xmlns="">
    A
    <otherbar>B</otherbar>
  </foo>

-Rahul



>
>   Thank you
>     Jaro
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Mime
View raw message