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.
  • ClassCastExcep... Heikki Doeleman
    • RE: Class... Radu Preotiuc-Pietro
      • RE: C... haddati
        • A... BEEKER, ANDREAS (Allianz Deutschland, externer Mitarbeiter)

Reply via email to