commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Agustina Dagnino" <>
Subject jxpath - changes in release 1.2 in collection handling?
Date Thu, 16 Dec 2004 15:39:39 GMT
I recently changed from jxpath release 1.1 to 1.2 and have found that changes
in the new release make it incompatible with my software.

The main issue is as follows:

	I have an object with a collection.

	Whenever I search for a particular object in the collection I get the following
behaviour (if the object I´m looking for is not present in the collection):
		Release 1.1.- returns a null value
		Release 1.2.- throws a JXPathException



import java.util.ArrayList;
import java.util.Collection;

import org.apache.commons.jxpath.JXPathContext;

 * MyObject
public class MyObject 
	private Collection myCollection ;
	private String attribute ;

	public Collection getMyCollection()
		if( myCollection==null )
			myCollection = new ArrayList();
		return myCollection;
	public void setMyCollection( Collection myCollection )
		this.myCollection = myCollection ;
	public String getAttribute()
		return attribute ;
	public void setAttribute( String attribute )
		this.attribute = attribute ;
	public static void main(String[] args) 
		MyObject myObject = new MyObject();
		MyObject anotherObject = new MyObject();
		JXPathContext context = JXPathContext.newContext(myObject) ;
		System.out.println( context.getValue("myCollection[attribute='AA']") 



release 1.1 produces a null output, while release 1.2 generates this stack
org.apache.commons.jxpath.JXPathException: No value for xpath: myCollection[attribute='AA']
	at org.apache.commons.jxpath.ri.JXPathContextReferenceImpl.getValue(
	at org.apache.commons.jxpath.ri.JXPathContextReferenceImpl.getValue(
	at MyObject.main(
Exception in thread "main"

My first thought was to place the jxpath code inside a try-catch statement.
However by doing this I would be missing out on real exceptions occurring
in the jxpath evaluation. Since all exceptions are re-thrown as a JXPathException
I have no way of differing between a miss and an error. Does anyone have
any ideas as to how to solve this problem?

Many thanks,

FiberTel, el nombre de la banda ancha

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message