|
RE: ClassCastException using changeType(): msg#00113text.xml.xmlbeans.user
Radu,
Hm, I think I know what's happening, I'll try to guess based on the information that you provide: When you first compile SchemaConcreteA,B,C you automatically pull in SchemaAbstractBase, because it is needed in order to resolve the base type references. That creates some SchemaTypes with an identity (set a) When you subsequently compile SchemaReferencesAbstractBase you automatically pull SchemaAbstractBase in again, because it is needed. This creates another set of types, including the types in SchemaAbstractBase, but with a different identity (set b). Now, unfortunately the SchemaAbstractBase types in (a) are different than SchemaAbstractBase types in (b), therefore your SchemaConcreteA,B,C don't extend the latter. There are good reasons for this design decision. Basically, when you have a reference to a type that can be found either in the set of current Schemas that you compile or in a set of already compiled Schemas, we always resolve the reference internally. Also, if you want to declare a new type with a name equal to that of another type that was compiled previously, we let you do it, we have to. Have you confirmed that the problem still occurs if all the Schemas are compiled simultaneously? If it still does, all I said earlier is just general info. As to why you can use only the last SchemaConcrete in your other case, it must be some peculiarity which I can't detect from the set of information you provide in this e-mail. In any case, xsb files are never clobbered, though it is the case that a runtime QName lookup for a particular entity will find the first entity with that name and kind (element, type etc) available on the classpath, just as in Java, so there is an obscuring effect going on, which you would expect. Hope this makes sense Radu
From: Scott Hinkelman [mailto:srh@xxxxxxxxxx] Sent: Tuesday, January 11, 2005 8:13 AM To: user@xxxxxxxxxxxxxxxxxxx Subject: RE: ClassCastException using changeType() 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: | Problems trying to use annotation support in v2: 00113, Jim McMaster |
|---|---|
| Next by Date: | RE: Problems trying to use annotation support in v2: 00113, Radu Preotiuc-Pietro |
| Previous by Thread: | RE: ClassCastException using changeType()i: 00113, Radu Preotiuc-Pietro |
| Next by Thread: | RE: ClassCastException using changeType(): 00113, Radu Preotiuc-Pietro |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |