users@jaxb.java.net

Re: Observation regarding jax2b reflection API

From: Kohsuke Kawaguchi <Kohsuke.Kawaguchi_at_Sun.COM>
Date: Tue, 28 Feb 2006 10:20:53 -0800

Kishore G wrote:
> Hi Kohsuke,
>
> I am facing the following problem with jaxb 2.0 reflection library.
> I have this xsd
> <xs:element name="PurchaseOrder">
> <xs:complexType>
> <xs:sequence>
> <xs:element ref="test:BillTo"/>
> <xs:element ref="test:Items"/>
> </xs:sequence>
> </xs:complexType>
> </xs:element>
>
> when i try to get the propertyinfo for "BillTo" it returns null, but it
> works when i change the xsd to
> <xs:element name="PurchaseOrder">
> <xs:complexType>
> <xs:sequence>
> <xs:element ref="test:billTo"/>
> <xs:element ref="test:Items"/>
> </xs:sequence>
> </xs:complexType>
> </xs:element>
> and try to get the propertyInfo for billTo.
>
> Please let me know if my observation is correct.

Yes. I remember someone else asking a similar question, but the
getProperty does not take the tag name as a parameter (which I thought
is obvious given that tagnames are qnames, whereas property names are
strings) Property names and tag names are different, although they are
often related because the former is often computed from the latter.

If you'd like to get a property that will hold a particular tag name,
you need to loop through properties and find it. We talked about this,
right? I suggested maybe we can have such a convenience method on the
reflection library.

I'll expand the javadoc of PropertyInfo.getName() to state that it's not
meant to be tag names or anything like that.

> Also I have another problem when I try to get the schemaType of a element
> using its elementName.
> public static QName getPropertySchemaType(Object sourceJaxbObject, QName
> xmlName) throws SOAException {
> RuntimeTypeInfoSet model =
> JAXBModelFactory.create(sourceJaxbObject.getClass());
> RuntimeClassInfo ci = (RuntimeClassInfo)
> model.getTypeInfo(sourceJaxbObject.getClass());
> return ci.getProperty(xmlName.getLocalPart()).getSchemaType();
> }
> I verified that ci.getProperty(xmlName.getLocalPart()) this is not null
> but the method returns null.

I also clarified javadoc. You should get the type names from
NonElement.getTypeName().


-- 
Kohsuke Kawaguchi
Sun Microsystems                   kohsuke.kawaguchi_at_sun.com