Hi folks,
Hope this topic will be read.
I'm getting a similar problem but using newIstance instead of parse.
Here is my code:
<code>
SchemaTypeLoader stl = XmlBeans.typeLoaderUnion( new SchemaTypeLoader[]
{ x.y.MyPrefixEventNameDocument.type.getTypeSystem(),
XmlBeans.getContextTypeLoader()} ) ;
SchemaType st = stl.findDocumentType(new QName("","EventName","MyPrefix"));
//I don't use namespace
EventName evt = (MyPrefixEventNameDocument)stl.newInstance(st, null);
</code>
The problem is that I have another class a.b.AnotherPrefixEventNameDocument
(same root element in 2 XML buffers), so I'm getting this exception:
java.lang.ClassCastException: a.b.impl.AnotherPrefixEventNameDocumentImpl
Can you help please?? (I'd like to avoid using namespaces if possible :) )
Said
Radu Preotiuc-Pietro wrote:
>
> Heikki,
> You seem to have a good understanding of the issue. The problem here is
> that XmlBeans tries to load the Java classes from the same classloader
> as the Schema types, so if you load the Schema types without a
> classloader, then the Java types cannot be loaded, so you get basically
> XmlObject with runtime type "D=topLevel".
>
> Try replacing
> stl = XmlBeans.typeLoaderUnion ( new SchemaTypeLoader [ ] {
> XmlBeans.getBuiltinTypeSystem ( ), stl } ) ;
>
>
> with
> stl = XmlBeans.typeLoaderUnion( new SchemaTypeLoader [] {
> TopLevelElementDocumentPostFix.type.getTypeSystem(),
> XmlBeans.getContextTypeLoader()} ) ;
>
> Radu
> ________________________________
>
> From: Heikki Doeleman [mailto:[email protected]]
> Sent: Wednesday, November 15, 2006 2:49 AM
> To: [email protected]
> Subject: ClassCastException when parsing using SchemaTypeLoader
>
>
>
> Hi there,
>
> I have 2 jars generated with scomp. In one of them, all the class names
> are postfixed to avoid clashing with class names from the other one
> (because their respective schemas have the same names for top level
> elements, and no namespace).
>
> Now, trying to parse in the usual way leads to a ClassCastException, as
> is described in earlier threads in this newsgroup :
>
> TopLevelElementDocumentPostFix toplevel = TopLevelElementDocumentPostFix
> .Factory.parse ( xml );
>
>
> OK, so to avoid this exception I tried using a SchemaTypeLoader telling
> it which jar to use, as follows :
>
> File[ ] schemaPath = { new File (
> "the-path-to-the-jar/xmltypes-postfixed.jar" ) } ;
>
> SchemaTypeLoader stl = XmlBeans.typeLoaderForResource (
> XmlBeans.resourceLoaderForPath ( schemaPath ) ) ;
> stl = XmlBeans.typeLoaderUnion ( new SchemaTypeLoader [ ] {
> XmlBeans.getBuiltinTypeSystem ( ), stl } ) ;
>
> System.out.println (
> TopLevelElementDocumentPostFix.type.toString ( ) ) ;
> TopLevelElementDocumentPostFix toplevel = (
> TopLevelElementDocumentPostFix )stl.parse ( xml ,
> TopLevelElementDocumentPostFix.type , null ) ;
>
> This last line gives a ClassCastException.
> The output from the System.out is the string "D=topLevel" (i.e. the name
> of the top level element in my xml document).
>
> Does anyone see what I am doing wrong ?
>
> thank you very much,
> Heikki Doeleman
>
> _______________________________________________________________________
> 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.
>
>
--
View this message in context:
http://www.nabble.com/ClassCastException-when-parsing-using-SchemaTypeLoader-tp7355620p24955526.html
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]