|
RE: ClassCastException using changeType(): msg#00080text.xml.xmlbeans.user
Radu and folks,
Thanks Radu. Apparently in my larger code I have a build problem causing this to take place. I put together a simple test case which does indeed behave correctly. - so it looks like my problem. For example sake, here is my simple example of abstract complex-type to concrete type using changeType(). The objective is to build aninstance document using the top A element that includes a concrete xsi type of the abstract type in the A namespace, and utilized both the extension element in the concrete extension. Feel free to use this in documentation, as I think there could be an example like this. Abstract complex type schema: <?xml version="1.0" encoding="UTF-8"?> <xs:schema targetNamespace="http://namespace.a" elementFormDefault="qualified" attributeFormDefault="unqualified" version="2.0" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:a="http://namespace.a"> <xs:element name="ATop" type="a:ATopType"/> <xs:complexType name="ATopType"> <xs:sequence> <xs:element name="A" type="a:AType" minOccurs="0" maxOccurs="unbounded"/> </xs:sequence> </xs:complexType> <xs:complexType name="AType" abstract="true"> <xs:sequence> <xs:element name="ADescription" minOccurs="0"> <xs:simpleType> <xs:restriction base="xs:string"> <xs:minLength value="1"/> </xs:restriction> </xs:simpleType> </xs:element> </xs:sequence> </xs:complexType> </xs:schema> Concrete extension schema of "AType". Seperate namespace. <?xml version="1.0" encoding="UTF-8"?> <xs:schema targetNamespace="http://namespace.b" elementFormDefault="qualified" attributeFormDefault="unqualified" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:b="http://namespace.b" xmlns:a="http://namespace.a"> <xs:import namespace="http://namespace.a" schemaLocation="./a.xsd"/> <xs:complexType name="BType"> <xs:complexContent> <xs:extension base="a:AType"> <xs:sequence> <xs:element name="BDescription" minOccurs="0"> <xs:simpleType> <xs:restriction base="xs:string"> <xs:minLength value="1"/> </xs:restriction> </xs:simpleType> </xs:element> </xs:sequence> </xs:extension> </xs:complexContent> </xs:complexType> </xs:schema> Test driver: package xmlbeanstest; import a.namespace.*; import b.namespace.*; import org.apache.xmlbeans.*; public class Test{ public static void main(String args[]) { ATopDocument _d=ATopDocument.Factory.newInstance(); ATopType atop_type=_d.addNewATop(); AType a_type=atop_type.addNewA(); System.out.println("a_type before: "+a_type.schemaType()); //a_type=(AType)a_type.changeType(BType.type); BType b_type=(BType)a_type.changeType(BType.type); System.out.println("a_type after: "+a_type.schemaType()); b_type.setADescription("adescription"); b_type.setBDescription("bdescription"); System.out.println(_d.toString()); } } Output: a_type before: T=AType@http://namespace.a a_type after: T=AType@http://namespace.a <ATop xmlns="http://namespace.a" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <A xsi:type="nam:BType" xmlns:nam="http://namespace.b"> <ADescription>adescription</ADescription> <nam:BDescription>bdescription</nam:BDescription> </A> </ATop> Again, I am still having trouble with my real code, but now convinced it should work. thanks for your time and keep up the good work on this. Scott ------------ Scott R. Hinkelman, Senior Software Engineer IBM Software Group / Emerging Technologies Cross-Industry Foundation Standards Strategy Office: 512.823.8097 (TL 793.8097) Cell: 512.415.8490
Hi Scott, I have reviewed my post ([1]) and indeed I don't know why I used .schemaType() in there, it should have been .type, apologies (.type will return the static SchemaType associated to the class in question, while .schemaType() will return rhe runtime SchemaType of an object instance). But beyond that, I just tried the example again, and it works for me. Can you share the code that you are using? Radu
From: Scott Hinkelman [mailto:srh@xxxxxxxxxx] Sent: Friday, January 07, 2005 11:23 AM To: user@xxxxxxxxxxxxxxxxxxx Subject: Re: ClassCastException using changeType() Girish/all,
I have the similar error of ClassCastException. In my case, my jar included two class files for the same type in two different namespaces. My issue was resolved, when I used the full package name with the class. for example. com.girsh.schema.Order order. - Girish On Fri, 7 Jan 2005 13:06:22 -0500, Murphy, Eric <erimurph@xxxxxxxxxxxxxxxxxxx> wrote: > > Scott - > > I had this problem which was caused by the situation described in my earlier > email titled ' Generated .jar files cause conflict' sent to the list on > Jan.5. Essentially there were two objects of the same name and same > namespace in two different jar files. I was asking for an object in one > package but an object with the same name but different package was being > returned. > > Eric > > > ________________________________ > From: Scott Hinkelman [mailto:srh@xxxxxxxxxx] > Sent: Thursday, January 06, 2005 11:55 AM > To: user@xxxxxxxxxxxxxxxxxxx > Subject: ClassCastException using changeType() > > > > > Hello XMLBeans experts. > I essentially have the same situation discussed in the post [1] concerning > polymorphism. > However, I get a runtime ClassCastExecption during the operation containing > changeType(). > Also, I have seen several uses of changeType() with parameters of > <class>.type, <class>.type(), > and as in the post <class>.schemaType(). The only one I can get to compile > is <class>.type, which > is where my exception occurs. > > I am using JDK 1.5 and a svn pull of Trunk on 1/6/05. > > If anyone can shed light on why I get that cast exception I would be very > appreciative. > > [1] > http://nagoya.apache.org/eyebrowse/ReadMsg?listName=user@xxxxxxxxxxxxxxxxxxx&msgId=1852352 > > thanks, > Scott > --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscribe@xxxxxxxxxxxxxxxxxxx For additional commands, e-mail: user-help@xxxxxxxxxxxxxxxxxxx |
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | RE: ClassCastException using changeType(): 00080, Scott Hinkelman |
|---|---|
| Next by Date: | Prefix question: 00080, Dogan Atay |
| Previous by Thread: | RE: ClassCastException using changeType()i: 00080, Scott Hinkelman |
| Next by Thread: | RE: ClassCastException using changeType(): 00080, Radu Preotiuc-Pietro |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |