You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@xmlbeans.apache.org by cmoller <ch...@gmail.com> on 2007/11/14 19:58:26 UTC

xsi:type and Java Class

I am having trouble getting XmlBeans 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>


-- 
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: user-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: user-help@xmlbeans.apache.org


RE: type and Java Class

Posted by Cezar Andrei <ce...@bea.com>.
It seems that you have 2 sets of the same classes in different jars.
Make sure that when you compile the extension xsd you use the base.jar
on the classpath so that you have only one set of compiled schema types
on the classpath.

See archives at
http://www.mail-archive.com/user@xmlbeans.apache.org/msg02498.html

Or compile all schemas at once into a single jar.

Cezar

> -----Original Message-----
> From: cmoller [mailto:chad.moller@gmail.com]
> Sent: Friday, November 30, 2007 8:47 AM
> To: user@xmlbeans.apache.org
> Subject: RE: type and Java Class
> 
> 
> Update:
> 
> This solution works fine so long as your extensions are in a single
XSD.
> Since I am breaking my extensions out, this will only work if the
consumer
> CHOOSES which extension they are going to use and puts ONLY that jar
in
> their classpath (not possible for me).
> 
> Is there a way to force xml beans to keep searching the classpath if
it is
> using the xsd declared type instead of the xml specified type?
> 
> 
> cmoller wrote:
> >
> > 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:chad.moller@gmail.com]
> >> 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:cvirok@vmware.com]
> >>> 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:chad.moller@gmail.com]
> >>> 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: user-unsubscribe@xmlbeans.apache.org
> >>> For additional commands, e-mail: user-help@xmlbeans.apache.org
> >>>
> >>>
> >>>
---------------------------------------------------------------------
> >>> To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
> >>> For additional commands, e-mail: user-help@xmlbeans.apache.org
> >>>
> >>>
---------------------------------------------------------------------
> >>> To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
> >>> For additional commands, e-mail: user-help@xmlbeans.apache.org
> >>>
> >>>
> >>>
> >>
> >> --
> >> 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: user-unsubscribe@xmlbeans.apache.org
> >> For additional commands, e-mail: user-help@xmlbeans.apache.org
> >>
> >>
> >>
---------------------------------------------------------------------
> >> To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
> >> For additional commands, e-mail: user-help@xmlbeans.apache.org
> >>
> >>
> >>
> >
> >
> 
> --
> View this message in context:
http://www.nabble.com/xsi%3Atype-and-Java-
> Class-tf4807282.html#a14067123
> Sent from the Xml Beans - User mailing list archive at Nabble.com.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
> For additional commands, e-mail: user-help@xmlbeans.apache.org


Notice:  This email message, together with any attachments, may contain information  of  BEA Systems,  Inc.,  its subsidiaries  and  affiliated entities,  that may be confidential,  proprietary,  copyrighted  and/or legally privileged, and is intended solely for the use of the individual or entity named in this message. If you are not the intended recipient, and have received this message in error, please immediately return this by email and then delete it.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: user-help@xmlbeans.apache.org


RE: type and Java Class

Posted by cmoller <ch...@gmail.com>.
Update:

This solution works fine so long as your extensions are in a single XSD.
Since I am breaking my extensions out, this will only work if the consumer
CHOOSES which extension they are going to use and puts ONLY that jar in
their classpath (not possible for me). 

Is there a way to force xml beans to keep searching the classpath if it is
using the xsd declared type instead of the xml specified type?


cmoller wrote:
> 
> 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:chad.moller@gmail.com] 
>> 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:cvirok@vmware.com] 
>>> 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:chad.moller@gmail.com]
>>> 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: user-unsubscribe@xmlbeans.apache.org
>>> For additional commands, e-mail: user-help@xmlbeans.apache.org
>>> 
>>> 
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
>>> For additional commands, e-mail: user-help@xmlbeans.apache.org
>>> 
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
>>> For additional commands, e-mail: user-help@xmlbeans.apache.org
>>> 
>>> 
>>> 
>> 
>> -- 
>> 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: user-unsubscribe@xmlbeans.apache.org
>> For additional commands, e-mail: user-help@xmlbeans.apache.org
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
>> For additional commands, e-mail: user-help@xmlbeans.apache.org
>> 
>> 
>> 
> 
> 

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


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: user-help@xmlbeans.apache.org


RE: type and Java Class

Posted by cmoller <ch...@gmail.com>.
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:chad.moller@gmail.com] 
> 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:cvirok@vmware.com] 
>> 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:chad.moller@gmail.com]
>> 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: user-unsubscribe@xmlbeans.apache.org
>> For additional commands, e-mail: user-help@xmlbeans.apache.org
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
>> For additional commands, e-mail: user-help@xmlbeans.apache.org
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
>> For additional commands, e-mail: user-help@xmlbeans.apache.org
>> 
>> 
>> 
> 
> -- 
> 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: user-unsubscribe@xmlbeans.apache.org
> For additional commands, e-mail: user-help@xmlbeans.apache.org
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
> For additional commands, e-mail: user-help@xmlbeans.apache.org
> 
> 
> 

-- 
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: user-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: user-help@xmlbeans.apache.org


RE: type and Java Class

Posted by Cory Virok <cv...@vmware.com>.
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:chad.moller@gmail.com] 
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:cvirok@vmware.com] 
> 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:chad.moller@gmail.com]
> 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: user-unsubscribe@xmlbeans.apache.org
> For additional commands, e-mail: user-help@xmlbeans.apache.org
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
> For additional commands, e-mail: user-help@xmlbeans.apache.org
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
> For additional commands, e-mail: user-help@xmlbeans.apache.org
> 
> 
> 

-- 
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: user-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: user-help@xmlbeans.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: user-help@xmlbeans.apache.org


RE: type and Java Class

Posted by cmoller <ch...@gmail.com>.
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:cvirok@vmware.com] 
> 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:chad.moller@gmail.com]
> 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: user-unsubscribe@xmlbeans.apache.org
> For additional commands, e-mail: user-help@xmlbeans.apache.org
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
> For additional commands, e-mail: user-help@xmlbeans.apache.org
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
> For additional commands, e-mail: user-help@xmlbeans.apache.org
> 
> 
> 

-- 
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: user-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: user-help@xmlbeans.apache.org


RE: type and Java Class

Posted by "Vinh Nguyen (vinguye2)" <vi...@cisco.com>.
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:cvirok@vmware.com] 
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:chad.moller@gmail.com]
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: user-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: user-help@xmlbeans.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: user-help@xmlbeans.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: user-help@xmlbeans.apache.org


RE: type and Java Class

Posted by Cory Virok <cv...@vmware.com>.
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:chad.moller@gmail.com] 
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: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: user-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: user-help@xmlbeans.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: user-help@xmlbeans.apache.org


Re: xsi:type and Java Class

Posted by cmoller <ch...@gmail.com>.
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#a13754008
Sent from the Xml Beans - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: user-help@xmlbeans.apache.org