Dmitri,

I will send you fresh stacktraces later,
but what is the main issue with a completely fail-safe, fool-proof approach as my example that catches everything?
Well, okay, besides having to create a an exception context each and every access... but as it is now, I have to do that outside of getValue() anyhow.

We're using jxpath in a cocoon environment together with OJB
and OJB uses introspection with reflection and lazy db queries
to travers the object graphs.

btw, thanks for an otherwise excellent package :)

Bj�rn




Dmitri Plotnikov wrote:
Bjorn,

There is code in JXPath that is supposed to take care of this issue.
For some reason it is not working for you.

Could you do me a favor: upgrade to the latest build, run the test and
send me the stack trace for the exception thrown by the accessor.  I
should be able to reproduce the problem and then fix it based on the
stack trace.

Thank you,

- Dmitri


--- Bjorn Bength <[EMAIL PROTECTED]> wrote:

We have a problem with getValue() and the lenient setting.
in our app we cant allow any exceptions thrown by this method,
hence we used setLenient(true);
However, our bean objects can throw many different kinds of
exceptions
while traversing getters (attributes), such as nullpointer and reflection exceptions.
If we patch the getValue() method in file
org/apache/commons/jxpath/ri/JXPathContextReferenceImpl.java
to catch all exceptions like so (see below), it all works okay for
us.
Probably we would want to patch the other getValue() method
and iterate() methods, too.

Note, i only tested this on a nightly build from about 2-3 weeks ago.
maybe there already is a better solution to this, but I really wish
the lenient setting be respected.

/bjorn



public Object getValue(String xpath, Expression expr){
try {
Object result = expr.computeValue(getRootContext());
if (result instanceof EvalContext) {
EvalContext ctx = (EvalContext) result;
result = ctx.getSingleNodePointer();
if (!lenient && result == null) {
throw new JXPathException("No value for xpath: "
+ xpath);
}
}
if (result instanceof NodePointer) {
result = ((NodePointer) result).getValuePointer();
if (!lenient && !((NodePointer) result).isActual())
{
// We need to differentiate between pointers representing
// a non-existing property and ones representing
a property
// whose value is null. In the latter case, the

pointer
// is going to have isActual == false, but its
parent,
// which is a non-node pointer identifying the
bean property,
// will return isActual() == true.
NodePointer parent = ((NodePointer) result).getParent();
if (parent == null
|| !parent.isContainer()
|| !parent.isActual()) {
throw new JXPathException("No value for
xpath: " + xpath);
}
}
result = ((NodePointer) result).getValue();
}
return result;

} catch (Throwable t) {
if (lenient) {
return null;
} else {
if (t instanceof JXPathException) {
throw (JXPathException)t;
} else {
throw new JXPathException("Error getting value
for xpath: " + xpath +
": " + t.toString());
}
}
}
}



--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail:
<mailto:[EMAIL PROTECTED]>


__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>


--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to