You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by "Kovgan, Peter" <pe...@sap.com> on 2007/01/01 16:40:06 UTC
Jxpath get object's type by path
Hi!
How can I retrieve type information using jxpath?
I need to determine type of element that resides in specified location.
Something like :
String addressType = <some>.getTypeByPath("/employee/address");
,so
System.out.println(addressType);
prints full qualified class name: com.myapp.Address
Thanks a lot!
Peter Kovgan
RE: Jxpath get object's type by path
Posted by "Kovgan, Peter" <pe...@sap.com>.
Thanks Scott . You are right.
-----Original Message-----
From: Scott Heaberlin [mailto:heabdogg@gmail.com]
Sent: ד, ינואר 03, 2007 6:27
To: Jakarta Commons Users List
Subject: Re: Jxpath get object's type by path
I think you can access the class and name of the type as getClass() is
available on any Object. The xpath would look like:
"./employee/address/class/name"
This should be the rough equivalent of <context
object>.getEmployee().getAddress().getClass().getName()
You could also try specifically invoking those methods in your xpath -
"getName(getClass(employee/address))"
Let's say your root-node object is a Manager object (e.g. it has the
Employee property accessible via getEmployee()):
JXPathContext myContext = JXPathContext.newContext(myManagerObject);
System.out.println("Address type: " +
myContext.getValue("./employee/address/class/name");
Hope this helps,
-Scott Heaberlin
On 1/1/07, Kovgan, Peter <pe...@sap.com> wrote:
>
>
> Hi!
> How can I retrieve type information using jxpath?
>
> I need to determine type of element that resides in specified location.
>
>
> Something like :
>
> String addressType = <some>.getTypeByPath("/employee/address");
>
> ,so
>
> System.out.println(addressType);
>
>
> prints full qualified class name: com.myapp.Address
>
>
>
>
>
> Thanks a lot!
>
> Peter Kovgan
>
>
>
---------------------------------------------------------------------
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
Re: Jxpath get object's type by path
Posted by Scott Heaberlin <he...@gmail.com>.
I think you can access the class and name of the type as getClass() is
available on any Object. The xpath would look like:
"./employee/address/class/name"
This should be the rough equivalent of <context
object>.getEmployee().getAddress().getClass().getName()
You could also try specifically invoking those methods in your xpath -
"getName(getClass(employee/address))"
Let's say your root-node object is a Manager object (e.g. it has the
Employee property accessible via getEmployee()):
JXPathContext myContext = JXPathContext.newContext(myManagerObject);
System.out.println("Address type: " +
myContext.getValue("./employee/address/class/name");
Hope this helps,
-Scott Heaberlin
On 1/1/07, Kovgan, Peter <pe...@sap.com> wrote:
>
>
> Hi!
> How can I retrieve type information using jxpath?
>
> I need to determine type of element that resides in specified location.
>
>
> Something like :
>
> String addressType = <some>.getTypeByPath("/employee/address");
>
> ,so
>
> System.out.println(addressType);
>
>
> prints full qualified class name: com.myapp.Address
>
>
>
>
>
> Thanks a lot!
>
> Peter Kovgan
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org