I've done the same thing. Basically, you need to get the SchemaParticle that
corresponds to the XmlObject's schema type, then get the Type of that schema
particle and finally, get the java class associated with that type, (via
getJavaClass().)

I haven't actually tried this code so my apologies if it doesn't work...
XmlObject testTypeExtension =
test.getTest().getTypeExtensions().getExtensionArray()[0];

SchemaType testExtType = testTypeExtension.schemaType();
Class testExtClass = testExtType.getJavaClass();        //the Class you're
interested in

Hope it helps/works!
cory

-----Original Message-----
From: cmoller [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, November 14, 2007 11:05 AM
To: [email protected]
Subject: xsi:type and Java Class


I am having trouble getting XmlBeans 1.0.4 to return the Java class I want
from an XML document. The XSD defines a complex type containing a list of an
abstract type. In another namespace I am defining a concrete extension of
the abstract type. When I parse an xml document containing on of these
lists, it returns references to the abstract type's class, not the concrete
type. If I change the list to a list of anyType instead of the abstract
type, I get back the expected class. Here are my XSD's:

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema";
            targetNamespace="http://domain/test";
            xmlns:test="http://domain/test";
            elementFormDefault="qualified">
    <xsd:complexType name="testType">
        <xsd:sequence>
            <xsd:element name="typeExtensions" minOccurs="0"
type="test:testTypeExtensions"/>
        </xsd:sequence>
    </xsd:complexType>
    <xsd:complexType name="testTypeExtensions">
        <xsd:sequence>
            <!--<xsd:element name="extension" type="test:testTypeExtension"
maxOccurs="unbounded" minOccurs="0"></xsd:element>-->
            <xsd:element name="extension" type="xsd:anyType"
maxOccurs="unbounded" minOccurs="0"></xsd:element>
        </xsd:sequence>
    </xsd:complexType>
    <xsd:complexType name="testTypeExtension" abstract="true">
        <xsd:sequence/>
    </xsd:complexType>
    <xsd:element name="test" type="test:testType"/>
</xsd:schema>

****XSD #2**************************************

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema";
            targetNamespace="http://domain/test/ext";
            xmlns:test="http://domain/test";
            elementFormDefault="qualified">
    <xsd:import namespace="http://domain/test";
schemaLocation="test.xsd"></xsd:import>
    <xsd:complexType name="testTypeClientExtension">
        <xsd:complexContent>
            <xsd:extension base="test:testTypeExtension">
                <xsd:sequence>
                    <xsd:element name="extensionElement"
type="xsd:string"></xsd:element>
                </xsd:sequence>
            </xsd:extension>
        </xsd:complexContent>
    </xsd:complexType>
</xsd:schema>

**** JAVA CODE ******************

Here is the Java code that I am using to check the behavior.

        String xmlText = "<test:test xmlns:test=\"http://domain/test\";
xmlns:ext=\"http://domain/test/ext\";
xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\";><test:typeExtensions>
<test:extension
xsi:type=\"ext:testTypeClientExtension\"/></test:typeExtensions></test:test>"
;

        TestDocument test = (TestDocument) XmlObject.Factory.parse(xmlText);
        XmlObject testTypeExtension =
test.getTest().getTypeExtensions().getExtensionArray()[0];

        System.out.println("testTypeClientExtension.getClass().getName() - "
+ testTypeExtension.getClass().getName());

If I use anyType in the list in the xsd, the system out will display
TestTypeClientExtension as the class. If I use TestTypeExtension, it will
display TestTypeExtension. I want to get back an instance of the class based
on the xsi:type.

Thanks in advance for any help.
-- 
View this message in context:
http://www.nabble.com/xsi%3Atype-and-Java-Class-tf4807282.html#a13754000
Sent from the Xml Beans - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
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]

Reply via email to