You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by P....@pilz.ie on 2007/07/16 16:42:02 UTC

JXPath 1.2 - get objects by class

Hi,

Just wondering if it is possible to retrieve all objects of a specific 
class from an object tree including if they are contained somewhere in the 
list.
 
Will this work

Iterator iterator = context.iterate("//com.mycompany.MyObject.new()");

Thanks.

Re: JXPath 1.2 - get objects by class

Posted by Sergey Vladimirov <vl...@gmail.com>.
Parvez,

Try this variant:

//*[@class/name='com.mycompany.MyObject']

Previous variant just checked if there was such objects. This variant should
select them.

-- 
Sergey Vladimirov

Re: JXPath 1.2 - get objects by class

Posted by P....@pilz.ie.
Thanks Scott.

I tried both ways but doesn't seem to work. It does return Iterator with 
one object of Boolean with false value.
Though if I give an invalid class name then it does throw an error that 
class not found.

Any suggestions?

Thanks.

- Parvez




"Scott Heaberlin" <he...@gmail.com> 
17/07/2007 02:44
Please respond to
"Jakarta Commons Users List" <co...@jakarta.apache.org>


To
"Jakarta Commons Users List" <co...@jakarta.apache.org>
cc

Subject
Re: JXPath 1.2 - get objects by class






.new() will instantiate one instance.  Try using getClass() as a
pseudo property (the introspector treats this as a read-only property.
 Something along these lines:

Iterator iterator =
context.iterate("//@class=java.lang.Class.forName('com.mycompany.MyObject')");

You may even be able to get away with
"//@class/name='com.mycompany.MyObject'".

Hope this helps,

-Scott Heaberlin


On 7/16/07, P.Chauhan@pilz.ie <P....@pilz.ie> wrote:
> Hi,
>
> Just wondering if it is possible to retrieve all objects of a specific
> class from an object tree including if they are contained somewhere in 
the
> list.
>
> Will this work
>
> Iterator iterator = context.iterate("//com.mycompany.MyObject.new()");
>
> Thanks.

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org



This email is intended solely for the use of the named addressee(s). Any 
unauthorised disclosure, copying or distribution of the confidential 
information contained therein, or the taking of any action based on it, is 
prohibited. The sender disclaims any liability for the integrity of this 
email. Legally binding declarations must be in written form.

Re: JXPath 1.2 - get objects by class

Posted by Scott Heaberlin <he...@gmail.com>.
.new() will instantiate one instance.  Try using getClass() as a
pseudo property (the introspector treats this as a read-only property.
 Something along these lines:

Iterator iterator =
context.iterate("//@class=java.lang.Class.forName('com.mycompany.MyObject')");

You may even be able to get away with
"//@class/name='com.mycompany.MyObject'".

Hope this helps,

-Scott Heaberlin


On 7/16/07, P.Chauhan@pilz.ie <P....@pilz.ie> wrote:
> Hi,
>
> Just wondering if it is possible to retrieve all objects of a specific
> class from an object tree including if they are contained somewhere in the
> list.
>
> Will this work
>
> Iterator iterator = context.iterate("//com.mycompany.MyObject.new()");
>
> Thanks.

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org