users@jaxb.java.net

Re: jaxb2-reflection library help

From: Kohsuke Kawaguchi <Kohsuke.Kawaguchi_at_Sun.COM>
Date: Tue, 05 Jun 2007 16:22:36 -0700

Hunor Bartha wrote:
> I am trying to use the jaxb2-reflection library to dynamically read
> information about jaxb objects. Could somebody please post some short
> example how to obtain the name of the xml element(node) to which a given
> jaxb object is bound to. I would be interested in the value of the
> /name/ property of the @XmlElement annotation. It seemed
> straightforward at the beginning, but by now i am completely lost
> between the different RuntimeClass* interfaces and implementations.
> For example, if i have the class:
>
> public class Parent{
> @XmlElement(name = "Node1", required = true)
> protected *Node1Type* node;
> }
>
> and at runtime i have an instance of *Node1Type*, how could i obtain the
> "Node1" string from it?

Node1Type maybe used in many classes and bound to different element
names, so such computation is impossible.

If you have a Field object that represents Parent.node and would like to
get to the element name from there, that's more tractable.

-- 
Kohsuke Kawaguchi
Sun Microsystems                   kohsuke.kawaguchi_at_sun.com