[ 
https://issues.apache.org/jira/browse/XMLBEANS-346?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12764198#action_12764198
 ] 

Cezar Andrei commented on XMLBEANS-346:
---------------------------------------

Each compilation generates in the jar file a new SchemaTypeSystem in the form 
of .xsb files. Even if the java classes are in different packages, they do make 
use of data in the SchemaTypeSystems, if this data uses the same local names 
and the same namespaces it will colide and XMLBeans will find only the resource 
which uses that name first on the classpath, hence the exception.

In order to make use of such schemas (i.e. multiple schemas using the same 
qnames for different elements/attributes/types etc) you need to manage yourself 
the SchemaTypeSystems. See javadoc for class org.apache.xmlbeans.XmlBeans, 
methods:
    typeLoaderForClassLoader(ClassLoader loader)
    typeLoaderForResource(ResourceLoader resourceLoader)
    typeLoaderUnion(SchemaTypeLoader[] typeLoaders)
    typeSystemForClassLoader(ClassLoader loader, String stsName) 

1. create resource loader from the jar you target
resourceLoader1 = XMLBeans.resourceLoaderForPath(File[] path) 
2. load TypeSystem from the jar you target
   stl1 = XMLBeans. typeLoaderForResource(resourceLoader1);
3. use stl1 to parse/generate XmlObjects
  stl1.parse()  / stl1.newInstance()
4. do the same for the other schemas with a different set of resourceLoader and 
stl, make sure they don't mix.

It's a little more complicated but doable.

> Getting ClassCastException if the same root element exist in different XSD
> --------------------------------------------------------------------------
>
>                 Key: XMLBEANS-346
>                 URL: https://issues.apache.org/jira/browse/XMLBEANS-346
>             Project: XMLBeans
>          Issue Type: Bug
>          Components: XmlObject
>    Affects Versions: Version 2.2
>         Environment: Windows xp operating system , jdk 1.4, WebLogic Server. 
>            Reporter: rajasekhar juluri
>
> HI All!
>    
>    I created the below XSD with two different packages.
>    1)   Package structure as follows      
>             -> test.xmlbeans.one 
>             -> test.xmlbeans.two
>      <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"; 
> elementFormDefault="qualified">
>       <xs:element name="cXML">
>               <xs:complexType>
>                       <xs:sequence>
>                               <xs:element ref="HEADER"/>
>                       
>                       </xs:sequence>
>                       
>               </xs:complexType>
>       </xs:element>
>       
>       <xs:element name="HEADER">
>              <xs:complexType>
>                       <xs:sequence>   
>                               <xs:element ref="From"/>
>                               <xs:element ref="To"/>
>                               <xs:element ref="Sender"/>
>                       </xs:sequence>
>               </xs:complexType>
>       </xs:element>
>      </xs:schema> 
>   
>    2)   jar file generated successfully. While executing the below program i 
> found ClassCastException.  
>        
>     java.lang.ClassCastException: test.xmlbeans.one.CXMLDocumentImpl
>                at 
> test.xmlbeans.two.CXMLDocument$Factory.parse(CXMLDocument.java)              
>  
>        
>        This is the sample program 
>             
>            class TextXMlBeans{
>                 public static void main(String arg[]) trhows Exception{
>                 test.xmlbeans.two.CXMLDocument cxml = 
> test.xmlbeans.two.CXMLDocument.Factory.parse(new File(fileName), opt);
>              
>                }
>              }
>  
> Thanks,
> Rajasekhar

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@xmlbeans.apache.org
For additional commands, e-mail: dev-h...@xmlbeans.apache.org

Reply via email to