Hi Bo, Sorry for getting back so late. I missed your mail from my email pool.
I indeed used axis2 1.1 and with xbean-2.2.0.jar that is shipped with the release. This is what I did to prove that polymorphism in XML works. My schema defines three complex types - BaseAddress, USAddress, and UKAddress. The second item extends first and the third item extends second. There is an element called 'UpdateCustomerAddress' that includes, by signature, type BaseAddress unbounded. The element could be used in the WSDL messages, but I didn't want go there. Now I complied the schema using the schema compiler tool from XML beans. (It makes no difference whether you use WSDL2Java of axis2 or directly compile using scomp of XML beans). I then wrote a test class, which uses the XML beans classes generated classes, to verify the runtime object type for the address property in UpdateCustomerAddress document. Please refer to the attachment for the schema and test class. In essence, the test class creates an XML programmatically, which contains a BaseAddress, an USAddress, and UKAddress all bound to the addresses property. Then it dumps the objects into XML, re-parses it, and examines the objects using instanceof operator to ensure that the types are correctly created. The test output is also in the attachment. TIP: I am not sure if this is significant, but ensure that your schema's elementFormDefault is "qualified" I hope this helps you. Ramesh On 1/9/07, Bo Xie <[EMAIL PROTECTED]> wrote:
Hi Ramesh,
Did you by any chance use Axis2 1.1.1 instead of 1.1 for your testing?
If you indeed used 1.1 only, can you give some details on how did you test
the instanceof? BTW, I opened AXIS2-1938 for this issue before saw your last
reply.
Thanks,
-Bo
On 1/5/07, Bo Xie <[EMAIL PROTECTED]> wrote:
> Hi Ramesh,
>
> It is comforting to know it actually works. Thanks for trying it out.
>
> I was using axis2. 1.1 and I just reinstall the axis2 1.1 and tried it
again, still get the same problem. I have two question.
> 1. When you mentioned XML Bean 2.2.0, it is the one xbean-2.2.0.jar
comes with the axis2 package, not an outside jar, right?
> 2. Do you mind share the test wsdl and the source file that you did
the instanceof test. I would like to see if I am not doing the right thing
using the generated object. Did you see the xsi:type in the soap message for
both directions?
>
> Thanks,
> -Bo
>
>
>
> On 1/5/07, Ramesh Gurunathan < [EMAIL PROTECTED]> wrote:
> > Hi Guys,
> >
> > I tested this today against axis2 1.1 [XML beans 2.2.0]. It actually
> > works. The instanceof check passes. I then switched to Debug
> > perspective to introspect the object type, everything looks perfect.
> >
> > Bo - Try again and see if you can duplicate the problem in axis2 1.1
> >
> > Ramesh
> >
> > On 1/4/07, Ajith Ranabahu <[EMAIL PROTECTED]> wrote:
> > > Hi,
> > >
> > > > Hi Ajith,
> > > >
> > > > The Address class only has getter and setter for name, city etc.
No
> > > > getAddress. Do you see this ignoring of xsi:type in creating
instance as a
> > > > bug?
> > >
> > > Yep. It is a bug. But AFAIK it was reported to be working. In any case
> > > you can file a Jira with your schema.
> > >
> > > Ajith
> > >
> > >
---------------------------------------------------------------------
> > > To unsubscribe, e-mail:
[EMAIL PROTECTED]
> > > For additional commands, e-mail: [EMAIL PROTECTED]
> > >
> > >
> >
> >
---------------------------------------------------------------------
> > To unsubscribe, e-mail:
[EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> >
>
>
Test.out
Description: Binary data
package com.xyz.fw.remote.common;
import java.math.BigInteger;
import junit.framework.TestCase;
import org.apache.xmlbeans.XmlException;
import org.apache.xmlbeans.XmlOptions;
import com.xyz.fw.remote.types.BaseAddress;
import com.xyz.fw.remote.types.UKAddress;
import com.xyz.fw.remote.types.USAddress;
import com.xyz.fw.remote.types.UpdateCustomerAddressDocument;
public class TestXMLPolymorphism extends TestCase
{
public void testXMLPolymorphism() throws XmlException
{
UpdateCustomerAddressDocument doc = UpdateCustomerAddressDocument.Factory.newInstance();
UpdateCustomerAddressDocument.UpdateCustomerAddress updateAddress = doc.addNewUpdateCustomerAddress();
BaseAddress baseAddress = updateAddress.addNewAddress();
baseAddress.setStreet("Base street");
USAddress usAddress = (USAddress) updateAddress.addNewAddress().changeType(USAddress.type);
usAddress.setStreet("US street");
usAddress.setZip(new BigInteger("12345"));
UKAddress ukAddress = (UKAddress) updateAddress.addNewAddress().changeType(UKAddress.type);
ukAddress.setStreet("UK street");
ukAddress.setZip(new BigInteger("67890"));
ukAddress.setProvince("Chinatown");
XmlOptions opt = (new XmlOptions()).setSavePrettyPrint();
String xml = doc.xmlText(opt);
System.out.println("XML output:\n" + xml);
System.out.println("Re-parsing XML..");
doc = UpdateCustomerAddressDocument.Factory.parse(xml);
System.out.println("XML output:\n" + doc.xmlText(opt));
BaseAddress[] addresses = doc.getUpdateCustomerAddress().getAddressArray();
for(int i=0, len= addresses.length; i < len; i++) {
System.out.println("Address at the index " + i + " is a " + addressType(addresses[i]));
}
}
private String addressType(BaseAddress address)
{
if(address instanceof UKAddress) {
return "UK-Address";
} else if (address instanceof USAddress) {
return "US-Address";
} else {
return "Base-Address";
}
}
}
<?xml version="1.0" encoding="UTF-8"?> <!-- Defines common types --> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fdfTypes="http://www.xyz.com/fdf/types" xmlns="http://www.xyz.com/fdf/types" targetNamespace="http://www.xyz.com/fdf/types" elementFormDefault="qualified" attributeFormDefault="qualified"> <!-- Test Types --> <xs:complexType name="BaseAddress"> <xs:sequence> <xs:element name="street" type="xs:string"/> </xs:sequence> </xs:complexType> <xs:complexType name="USAddress"> <xs:complexContent> <xs:extension base="BaseAddress"> <xs:sequence> <xs:element name="zip" type="xs:positiveInteger"/> </xs:sequence> </xs:extension> </xs:complexContent> </xs:complexType> <xs:complexType name="UKAddress"> <xs:complexContent> <xs:extension base="USAddress"> <xs:sequence> <xs:element name="province" type="xs:string"/> </xs:sequence> </xs:extension> </xs:complexContent> </xs:complexType> <xs:element name="UpdateCustomerAddress"> <xs:complexType> <xs:sequence> <xs:element name="Addresses" type="BaseAddress" maxOccurs="unbounded"/> </xs:sequence> </xs:complexType> </xs:element> </xs:schema>
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
