commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Agustina Dagnino" <adagn...@fibertel.com.ar>
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

	Example:

------------------------------------------------

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();
		
		myObject.getMyCollection().add(anotherObject);
		
		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
trace:
org.apache.commons.jxpath.JXPathException: No value for xpath: myCollection[attribute='AA']
	at org.apache.commons.jxpath.ri.JXPathContextReferenceImpl.getValue(JXPathContextReferenceImpl.java:318)
	at org.apache.commons.jxpath.ri.JXPathContextReferenceImpl.getValue(JXPathContextReferenceImpl.java:280)
	at MyObject.main(MyObject.java:47)
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,
Agustina





________________________________________
FiberTel, el nombre de la banda ancha http://www.fibertel.com.ar



---------------------------------------------------------------------
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