commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Dmitri Plotnikov" <dmi...@apache.org>
Subject Re: jxpath - changes in release 1.2 in collection handling?
Date Sat, 18 Dec 2004 05:18:52 GMT
Agustina,

JXPath 1.1 must have had a bug in this area.  The call to context.getValue() 
is supposed to throw an exception when it cannot find the requested xpath, 
unless of course you have called context.setLenient(true), which will make 
it return null in the same situation. That's a general rule - to get null 
for missing paths, call context.setLenient(true) first.

I hope this helps,

- Dmitri

----- Original Message ----- 
From: "Agustina Dagnino" <adagnino@fibertel.com.ar>
To: <commons-user@jakarta.apache.org>
Sent: Thursday, December 16, 2004 10:39 AM
Subject: jxpath - changes in release 1.2 in collection handling?


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



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