Return-Path: Delivered-To: apmail-jakarta-commons-user-archive@www.apache.org Received: (qmail 60665 invoked from network); 31 May 2004 13:20:35 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 31 May 2004 13:20:35 -0000 Received: (qmail 78203 invoked by uid 500); 31 May 2004 13:20:31 -0000 Delivered-To: apmail-jakarta-commons-user-archive@jakarta.apache.org Received: (qmail 78074 invoked by uid 500); 31 May 2004 13:20:30 -0000 Mailing-List: contact commons-user-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Jakarta Commons Users List" Reply-To: "Jakarta Commons Users List" Delivered-To: mailing list commons-user@jakarta.apache.org Received: (qmail 78059 invoked by uid 99); 31 May 2004 13:20:30 -0000 Received: from [213.165.64.20] (HELO mail.gmx.net) (213.165.64.20) by apache.org (qpsmtpd/0.27.1) with SMTP; Mon, 31 May 2004 06:20:29 -0700 Received: (qmail 13500 invoked by uid 65534); 31 May 2004 13:20:11 -0000 Received: from unknown (EHLO [192.168.21.50]) (213.213.164.144) by mail.gmx.net (mp018) with SMTP; 31 May 2004 15:20:11 +0200 X-Authenticated: #21282572 Mime-Version: 1.0 (Apple Message framework v618) Content-Transfer-Encoding: 7bit Message-Id: <7554BFB6-B305-11D8-B531-000393030394@gmx.ch> Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed To: Jakarta Commons Users List From: Simon Raess Subject: [JXPath] Indexed Properties Date: Mon, 31 May 2004 15:21:43 +0200 X-Mailer: Apple Mail (2.618) X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N 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