The TestTypeClientExtension interface does extend TestTypeExtension.

I DID find something interesting, though. I am generating two seperate JAR's
from two seperate XSD's. The extension xsd imports the base xsd. The
resulting JAR from the extension XSD contains the types from the base xsd. I
tried removing the base XSD from my project and everything worked perfectly.
I then simply moved the extension jar before the base jar, and everything
still worked fine.

So, for me, making sure the extended types come before the base types in the
classpath solved the problem. Now, I am curious to see if this solution can
work with two different extension xsds (client1, client2).


Cory Virok wrote:
> 
> Sounds like the class hierarchy is not translated verbatim when XMLbeans
> generates Java code. Although I don't know how to solve your problem, I
> would
> suggest looking at the generated code to see what the inheritance
> relationships look like. I have a feeling that there are some interfaces
> that
> are being generated on behalf of TestTypeExtension and
> TestTypeClientExtension that do not have the correct "implements"
> relationships...
> 
> Maybe this will help:
> If you see this in the generated code:
> 
> interface TestTypeExtension {...}
> interface TestTypeClientExtension {...}
> 
> and *not*
> 
> interface TestTypeClientExtension extends TestTypeExtension {...}
> 
> you will get class cast exceptions because even though the implementing
> classes have the correct inheritance, the interfaces that you're working
> with
> do not.
> 
> Again... this is all speculation but who knows, maybe this is how it
> works.
> 
> cory
> 
> -----Original Message-----
> From: cmoller [mailto:[EMAIL PROTECTED] 
> Sent: Tuesday, November 27, 2007 6:43 PM
> To: user@xmlbeans.apache.org
> Subject: RE: type and Java Class
> 
> 
> This is EXACTLY the problem I am having. It works find if you declare the
> element as anytype in the XSD, but it does NOT work if you declare it as a
> specific type and then subtype from that.
> 
> 
> 
> Vinh Nguyen (vinguye2) wrote:
>> 
>> Hi,
>> Instead of just getting the extending type's class, is there a way to
>> actually get an instance of that type?  For example, the following will
>> not work:
>> 
>> TestType test = TestDocument.Factory.newTest();
>> test.getTypeExtensions().addNewExtension( testTypeClientExtension );
>> 
>> TestTypeClientExtension ext =
>> (TestTypeClientExtension)test.getTypeExtensions().getExtension(0);  //
>> ClassCastException!
>> 
>> So even if you insert an extending type, the composite object will only
>> return a new instance of the base type.  It doesn't even return the
>> actual object that was inserted.  Hencing, casting will not work.
>> 
>> There seems to be a disjoint in the extension pattern allowed in XML
>> schemas versus how XmlBeans implements the corresponding Java class
>> extension pattern.
>> 
>> 
>>  
>> 
>> -----Original Message-----
>> From: Cory Virok [mailto:[EMAIL PROTECTED] 
>> Sent: Thursday, November 15, 2007 8:05 AM
>> To: user@xmlbeans.apache.org
>> Subject: RE: type and Java Class
>> 
>> 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: user@xmlbeans.apache.org
>> 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:typeExtens
>> ions>
>> <test:extension
>> xsi:type=\"ext:testTypeClientExtension\"/></test:typeExtensions></test:t
>> est>"
>> ;
>> 
>>         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]
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [EMAIL PROTECTED]
>> For additional commands, e-mail: [EMAIL PROTECTED]
>> 
>> 
>> 
> 
> -- 
> View this message in context:
> http://www.nabble.com/xsi%3Atype-and-Java-Class-tf4807282.html#a13984806
> 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]
> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/xsi%3Atype-and-Java-Class-tf4807282.html#a14065036
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]

Reply via email to