commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Simon Raess <co...@gmx.ch>
Subject [JXPath] Indexed Properties
Date Mon, 31 May 2004 13:21:43 GMT
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.j 
ava:112)
	at  
org.apache.commons.jxpath.ri.model.beans.BeanPropertyPointer.isCollectio 
n(BeanPropertyPointer.java:201)
	at  
org.apache.commons.jxpath.ri.model.beans.BeanPropertyPointer.setIndex(Be 
anPropertyPointer.java:162)
	at  
org.apache.commons.jxpath.ri.axes.SimplePathInterpreter.doPredicateIndex 
(SimplePathInterpreter.java:675)
	at  
org.apache.commons.jxpath.ri.axes.SimplePathInterpreter.doPredicate(Simp 
lePathInterpreter.java:487)
	at  
org.apache.commons.jxpath.ri.axes.SimplePathInterpreter.doStepPredicates 
PropertyOwner(SimplePathInterpreter.java:353)
	at  
org.apache.commons.jxpath.ri.axes.SimplePathInterpreter.doStep(SimplePat 
hInterpreter.java:194)
	at  
org.apache.commons.jxpath.ri.axes.SimplePathInterpreter.interpretSimpleL 
ocationPath(SimplePathInterpreter.java:122)
	at  
org.apache.commons.jxpath.ri.compiler.Path.getSingleNodePointerForSteps( 
Path.java:186)
	at  
org.apache.commons.jxpath.ri.compiler.LocationPath.computeValue(Location 
Path.java:128)
	at  
org.apache.commons.jxpath.ri.JXPathContextReferenceImpl.getValue(JXPathC 
ontextReferenceImpl.java:287)
	at  
org.apache.commons.jxpath.ri.JXPathContextReferenceImpl.getValue(JXPathC 
ontextReferenceImpl.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: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Mime
View raw message