osdir.com
mailing list archive F.A.Q. -since 2001!



Subject: RE: ClassCastException when parsing using
SchemaTypeLoader - msg#00024

List: text.xml.xmlbeans.user

Mail Archive Navigation:
by Date: Prev Next Date Index by Thread: Prev Next Thread Index

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:hdoeleman@xxxxxxxxxxx]
Sent: Wednesday, November 15, 2006 2:49 AM
To: user@xxxxxxxxxxxxxxxxxxx
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.

Thread at a glance:

Previous Message by Date:

selectPath() select the wrong nodes

Hi,This is the code I try:ExtensionsType ext = entities.getExtensions(); // xml bean for SAML's Extension element String X509_QUERY = "declare namespace shibmd='urn:mace:shibboleth:metadata:1.0' " +                     "declare namespace ds='http://www.w3.org/2000/09/xmldsig#' " +                    "$this//shibmd:KeyAuthority/ds:KeyInfo/ds:X509Data"; XmlObject [] objs = ext.selectPath(X509_QUERY);and tried:  String X509_QUERY = "declare namespace ds='http://www.w3.org/2000/09/xmldsig#' " +                     "$this//ds:X509Data"; Both result an XmlAnyType which has content "<ds:X509Certificate .." (i.e. the child of ds:X509Data). I would expect an array of X509Data objects.Any idea?Thanks

Next Message by Date:

RE: Accepting any URL on the default namespace declaration

Let me see if I got this straight. You want that regardless of the namespace in the document, XmlBeans to consider it as having no namespace at all. If this is correct, I have to say I find it pretty strange. You can do two things:   1. Try using .setLoadUseXMLReader() and pass in a Reader that doesn't use namespaces 2. Write a SAX filter that strips the namespace before passing the events to XMLBeans; this is not as difficult as it may sound.   I suppose that we could always add an option for XMLBeans to do this automatically; but first, is this a good characterization of what you had in mind?   Radu From: Webber, David (NIH/OD) [C] [mailto:webberd@xxxxxxxxxx] Sent: Thursday, November 16, 2006 9:01 AMTo: user@xxxxxxxxxxxxxxxxxxxSubject: Accepting any URL on the default namespace declaration Just trying to puzzle out the XmlOptions for the Factory.parse – the FAQ and the Javadoc gives some parameters – but no guide to their usage / purpose.  Not always clear from the name of the parameter.   What I’m attempting to do is to have the namespace declaration URL be ##any – instead of enforced to be a specific URL value.   E.g.   <myxml xmlns=”foobar.com/mustbe/this/that”>   <test/> </myxml>   Where the namespace URL is forced to match the value put in targetNamesSpace in the XSD that was used to generate the XMLBeans.   I want to relax that check and allow any URL to be used for the default namespace.   Thanks,   David Webber   http://drrw.net   _______________________________________________________________________ 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.

Previous Message by Thread:

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

Next Message by Thread:

Accepting any URL on the default namespace declaration

Just trying to puzzle out the XmlOptions for the Factory.parse – the FAQ and the Javadoc gives some parameters – but no guide to their usage / purpose.  Not always clear from the name of the parameter.   What I’m attempting to do is to have the namespace declaration URL be ##any – instead of enforced to be a specific URL value.   E.g.   <myxml xmlns=”foobar.com/mustbe/this/that”>   <test/> </myxml>   Where the namespace URL is forced to match the value put in targetNamesSpace in the XSD that was used to generate the XMLBeans.   I want to relax that check and allow any URL to be used for the default namespace.   Thanks,   David Webber   http://drrw.net  
blog comments powered by Disqus

Home | News | Sitemap | FAQ | advertise | OSDir is an Inevitable website. GBiz is too!