I've just updated to the latest CVS version. The problem described
below is fixed there. I used JXPath 1.1 and that version had some
problems with indexed properties.
Simon
Am 31.05.2004 um 15:21 schrieb Simon Raess:
Hi
In the users guide (section 'Collection Subscripts') I've read that
JXPath also supports indexed properties according to the JavaBeans
specification. However, I did not get it to work with indexed
properties unless I add one of the following method:
public Part[] getPart();
public List getPart();
However, I'd just like to add a method
public Part getPart(int index);
This does not work (JXPath 1.1). I give you a short example:
Song
void addPart(Part part);
Part getPart(int index);
Part
String getName();
Let's say I have the following code:
Song song = new Song();
song.addPart(new Part("one"));
song.addPart(new Part("two"));
song.addPart(new Part("three"));
JXPathContext context = JXPathContext.newContext(song);
context.getValue("/part[1]");
I get a NullPointerException, stack trace below:
Exception in thread "main" java.lang.NullPointerException
at
org.apache.commons.jxpath.util.ValueUtils.getCollectionHint(ValueUtils.
java:112)
at
org.apache.commons.jxpath.ri.model.beans.BeanPropertyPointer.isCollecti
on(BeanPropertyPointer.java:201)
at
org.apache.commons.jxpath.ri.model.beans.BeanPropertyPointer.setIndex(B
eanPropertyPointer.java:162)
at
org.apache.commons.jxpath.ri.axes.SimplePathInterpreter.doPredicateInde
x(SimplePathInterpreter.java:675)
at
org.apache.commons.jxpath.ri.axes.SimplePathInterpreter.doPredicate(Sim
plePathInterpreter.java:487)
at
org.apache.commons.jxpath.ri.axes.SimplePathInterpreter.doStepPredicate
sPropertyOwner(SimplePathInterpreter.java:353)
at
org.apache.commons.jxpath.ri.axes.SimplePathInterpreter.doStep(SimplePa
thInterpreter.java:194)
at
org.apache.commons.jxpath.ri.axes.SimplePathInterpreter.interpretSimple
LocationPath(SimplePathInterpreter.java:122)
at
org.apache.commons.jxpath.ri.compiler.Path.getSingleNodePointerForSteps
(Path.java:186)
at
org.apache.commons.jxpath.ri.compiler.LocationPath.computeValue(Locatio
nPath.java:128)
at
org.apache.commons.jxpath.ri.JXPathContextReferenceImpl.getValue(JXPath
ContextReferenceImpl.java:287)
at
org.apache.commons.jxpath.ri.JXPathContextReferenceImpl.getValue(JXPath
ContextReferenceImpl.java:283)
The problem seems to be that in BeanPropertyPointer.isCollection at
line 201 the method pd.getPropertyType() is called but it returns
null. For an indexed property there is the method
getIndexedPropertyType() that returns the correct type (that is 'Part'
in this case).
Is it a bug or merely my limited understanding of JXPath?
Simon
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]