You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@xmlbeans.apache.org by haddati <ha...@gmail.com> on 2009/08/13 18:51:15 UTC

RE: ClassCastException when parsing using SchemaTypeLoader

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:hdoeleman@amadeus.com] 
> Sent: Wednesday, November 15, 2006 2:49 AM
> To: user@xmlbeans.apache.org
> 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: user-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: user-help@xmlbeans.apache.org


Re: AW: ClassCastException when parsing using SchemaTypeLoader

Posted by haddati <ha...@gmail.com>.
Thank you for your answer but I'd like to avoid using paths to jars files
also (the project will be deployed somewhere else in a server and I don't
know whese jars will be).

Nothing easier?

Said



BEEKER, ANDREAS (Allianz Deutschland AG) wrote:
> 
> Hi Heikki,
> 
> I had a similar problem:
> http://www.mail-archive.com/user@xmlbeans.apache.org/msg03316.html 
> 
> ... which we solved like this:
> http://www.mail-archive.com/user@xmlbeans.apache.org/msg03319.html
> 
> So basically, we don't have the schema resources in the context
> classloader
> and load them explicitly.
> 
> Write me a private mail, if you want to have the source code
> of our XmlBeanFactory.
> 
> Best wishes,
> Andreas
> 
> 
> -----Urspr?ngliche Nachricht-----
> Von: haddati [mailto:haddati@gmail.com] 
> Gesendet: Donnerstag, 13. August 2009 18:51
> An: user@xmlbeans.apache.org
> Betreff: RE: ClassCastException when parsing using SchemaTypeLoader
> 
> 
> 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:hdoeleman@amadeus.com] 
>> Sent: Wednesday, November 15, 2006 2:49 AM
>> To: user@xmlbeans.apache.org
>> 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.
>> 
>> 
> 
> -- 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
> For additional commands, e-mail: user-help@xmlbeans.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/ClassCastException-when-parsing-using-SchemaTypeLoader-tp7355620p24967453.html
Sent from the Xml Beans - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: user-help@xmlbeans.apache.org


AW: ClassCastException when parsing using SchemaTypeLoader

Posted by "BEEKER, ANDREAS (Allianz Deutschland, externer Mitarbeiter)" <ex...@allianz.de>.
Hi Heikki,

I had a similar problem:
http://www.mail-archive.com/user@xmlbeans.apache.org/msg03316.html 

... which we solved like this:
http://www.mail-archive.com/user@xmlbeans.apache.org/msg03319.html

So basically, we don't have the schema resources in the context classloader
and load them explicitly.

Write me a private mail, if you want to have the source code
of our XmlBeanFactory.

Best wishes,
Andreas


-----Urspr?ngliche Nachricht-----
Von: haddati [mailto:haddati@gmail.com] 
Gesendet: Donnerstag, 13. August 2009 18:51
An: user@xmlbeans.apache.org
Betreff: RE: ClassCastException when parsing using SchemaTypeLoader


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:hdoeleman@amadeus.com] 
> Sent: Wednesday, November 15, 2006 2:49 AM
> To: user@xmlbeans.apache.org
> 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.
> 
> 

-- 

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: user-help@xmlbeans.apache.org