Thanks Ajith for the quick response.

I have tried to use the instanceof to test if the instance is USAddress, but the test returns false. Without that, the type cast is not safe as the Address list can have items of either Address or USAddress. My question here is should the java instance created from XML be of type USAddress even though the signature is Address. Is there anyway to make this happen?

Thanks,
-Bo
Ajith Ranabahu wrote:
Hi,
The reason here is that you have set the type of the addresses element
to be 'Address' rather than USAddress (the code generator would put
the reference for the Address rather than the USAddress). However
since the xsi:type attribute is present the deserializer should create
the right object and you can just use a type cast to get to the right
object.

HTH

Ajith

On 1/2/07, Bo Xie <[EMAIL PROTECTED]> wrote:
Hi there,

  I am new to axis2 with XMLBean data binding, please help me with the
following issue.

I modified the quickstart sample XMLBean program to try a WSDL with the following types. The type US-Address is a derived from type Address. I would like to create a service operation updateAddresses to change addresses of a company based on a symbol. The addresses is an array that can take either
Address or USAddress instances.

          <xs:complexType name="Address">
                <xs:sequence>
<xs:element name="name" type="xs:string" minOccurs="0"/>
                     <xs:element name="street" type="xs:string"/>
                    <xs:element name="city" type="xs:string"/>
                </xs:sequence>
            </xs:complexType>


            <xs:complexType name="US-Address">
                <xs:complexContent>
                    <xs:extension base="ipo:Address">
                        <xs:sequence>
<xs:element name="state" type="ipo:US-State"/>
                            <xs:element name="zip"
type="xs:positiveInteger"/>
                        </xs:sequence>
                    </xs:extension>
                </xs:complexContent>
            </xs:complexType>

         <xs:element name="updateAddresses">
                <xs:complexType>
                    <xs:sequence>
                        <xs:element name="symbol" type="xs:string"
nillable="true"/>
                        <xs:element name="addresses" type="ipo:Address"
maxOccurs="unbounded"/>
                    </xs:sequence>
                </xs:complexType>

I used WSDL2JAVA with XMLBean data binding to generate the skeleton
and stub code. All looks great and the SOAP exchange looks fine too.

      In the client code, I created one instance if USAddress and one
instance of Address and put them into the addresses list. In the SOAP
request message, the instances are as  shown as follows below. Note,
xsi-type for the instance indicate the correct types which is nice.
 <soapenv:Body>
 <updateAddresses xmlns="http://quickstart.samples/xsd";>

 <symbol>XYZ</symbol>
 <addresses
xmlns:xsi="http;//www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="
http://quickstart.samples/xsd"; xsi:type="xsd:US-Address">
 <name>company name</name>
 <city>Sunnyvale</city>
 <state>CA</state>

 <zip>94087</zip>
 </addresses>
 <addresses
xmlns:xsi="http;//www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://quickstart.samples/xsd
" xsi:type="xsd:Address">
 <name>company name</name>
 <city>Hong Kong</city>
 </addresses>
 </updateAddresses>
 </soapenv:Body>


The problem is when the XML object mapped into java object on the service side, all the XML address object passed to the skeleton are all of Address
type. I would expect one instance be Address type, another be USAddress
type. Since xsi-type in the SOAP message has the right type, why the XMLBean object is not created as the derived type? Is there any option in WSDL2JAVA
to make this work?

   From the XMLBean Address java object, how can I access the xsi-type
attribute that was available in the XML string?

   If I am not heading the right direction, can anyone suggest some
alternatives?

 Thanks for your time!

-Bo






---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to