users@jaxb.java.net

Re: Observation regarding jax2b reflection API

From: Kishore G <kishoreg_at_javector.com>
Date: Fri, 17 Feb 2006 20:49:31 +0530

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.

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.

Can you please help me.

Thanks,
Kishore G
----- Original Message -----
From: "Kohsuke Kawaguchi" <kohsuke.kawaguchi_at_sun.com>
To: "Kishore G" <kishoreg_at_javector.com>
Cc: <users_at_jaxb.dev.java.net>
Sent: Friday, February 03, 2006 11:22 PM
Subject: Re: Observation regarding jax2b reflection API


>
> I hope you don't mind my CC-ing this e-mail to JAXB users list. That's
> where we'd like discussions like this to happen.
>
> Kishore G wrote:
>> I am Kishore G from India. I have been using the reflection API provided
>> by you and would like to thank you very much for giving such a wonderful
>> library. I just came up with a problem while using the API
>
> Thanks for the kind words. If possible, can you tell me bit about what you
> use it for? I'm interested in knowing how it's used.
>
>> //consider the following code snipper assume i get typeInfo correctly
>> RuntimeClassInfo typeInfo;
>> typeInfo.getProperty("price");
>>
>> what i feel is that this method should actually take a QName as the input
>> parameter in order to accomodate for the name space. This works fine if
>> there is only one element by name "price". Consider a case where we have
>> test:price and also oag:price under the same element then
>> typeInfo.getProperty("price") will always return the same property.
>
> Actually, I think this is correct. The getProperty method takes a name of
> the property, which is more like a Java field name. And therefore it's a
> string, not a QName.
>
> One property may hold values for multiple element names, or just one, or
> any, and similarly a property might be for an attribute (which can be
> thought of a separate symbol space altogether), and then finally a
> property might be for PCDATA. So it doesn't make sense to use element
> QName as the unique identifier of a property.
>
>> Please let me know if my understanding is right or is there any other way
>> to do it.
>
> That said, maybe all you are asking is a convenience method that, given an
> element name, identifies the property that such an element will go. If so,
> doing something like that wouldn't be too difficult, and it's something we
> can consider.
>
> --
> Kohsuke Kawaguchi
> Sun Microsystems kohsuke.kawaguchi_at_sun.com
>