Just like in java world where you can compile only one java class/interface with the same name and package, or use only the first class with the same name and package on the classpath, in the schema world only one schema type with a given name and target namespace can be compiled at one point, and if compiled separately only the first one on the classpath can be used.

 

Also, just like in java one can use two different classes that have the same name and package but it will take more effort to accomplish this, they have to be loaded in two different classloaders.

 

So you have three options:

  1. The best way is to have different names or namespaces for all your types, if possible. This is the most usual case, and XMLBeans is optimized for this case.
  2. Use multiple classloaders that have different classpathes, each one having only one non-colliding set of schema types.
  3. Use different SchemaTypeLoaders creating new xbeans. This can be accomplished in one single classloader, if .xsdconfig files are user to avoid java name collisions. SchemaTypeLoaders are the equivalent of classloaders for schema types. So each SchemaTypeLoader will have to contain only one set of non-colliding schema types, i.e. be loaded from one jar.

 

Code for using option 3:

        // get a SchemaTypeLoader from an array of directories or jar files

        File[] schemaPath = null;

        SchemaTypeLoader stl = XmlBeans.typeLoaderForResource(XmlBeans.resourceLoaderForPath(schemaPath));

 

        // include the built-in type system

        stl = XmlBeans.typeLoaderUnion(new SchemaTypeLoader[]{XmlBeans.getBuiltinTypeSystem(), stl});

 

        // parse the document in the given

        a.b.c.RETURNDATADocument doc = (a.b.c.RETURNDATADocument)stl.parse("xml", null, null);

 

        // or create a new one, given a schemaType

        SchemaType st = stl.findDocumentType(new QName("a.b.c", "RETURNDATA"));

        a.b.c.RETURNDATADocument newDoc = (a.b.c.RETURNDATADocument)stl.newInstance(st, null);

 

I hope this helps or at least gives you more details on what’s going on.

 

Cezar

 

 


From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
Sent: Wednesday, May 25, 2005 9:26 AM
To: [email protected]
Subject: RE: ClassCastException

 

I discovered that the problem is not the scema or the xml, but the classpath.

I have many schemas and none of them have namespace declared. I can't change this because the schemas are coming form a service provider.

Approx. all the tags in schemas have the same name. You can find <RETURNDATA> and <DATA> in each schema. The first time i tried to generate the jar i got the "multiple occurences" error.

So i wrote a .xsdconfig for each schema, thus every schema have it's own package like: a.b.c.RETURNDATADocument or x.y.z.RETURNDATADocument

After the classCastException i added for each .xsdconfig file a _$ suffix where $ in (1, ...20).

So now all the classes are a.b.c.RETURNDATADocument_1, ...etc

If i try to parse a a.b.c.RETURNDATADocument_1 first , and it's jar in the first one in CLASSPATH it will work, but if i try after this to parse a x.y.z.RETURNDATADocument_2 i receive ClassCAstException.

If i put the jars in another order, the first operation will give ClassCast

 

PLease give me a clue at least!!



On Wed May 25 4:52 , 'Don Stewart' <[EMAIL PROTECTED]> sent:

Can you post the whole schema as I cannot see from the schema supplied the whole problem.

 

Thanks

 

Don

 


From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
Sent: 25 May 2005 10:37
To: [email protected]
Subject: Re: ClassCastException

I made a small test: i used xmlbeans to generate a sample xml file then i tried to parse it. I received ClassCastException again!!! Please help me!!



On Wed May 25 2:38 , <[EMAIL PROTECTED]> sent:

Hi!

I'm receiving a ClassCastException when i'm trying to parse a VALID xml file.I'm sure the xmlbeans.jar is the right one and the schema and xml file are OK. PLease give me a clue. I pasted here a piece form xml file and xml schema

Code:

fr.xxx.yyy.zzz.RETURNDATADocument rd = fr.xxx.yyy.zzz.RETURNDATADocument.Factory
     .parse(new File("xxxx.xml"));

Schema:

<?xml version="1.0" encoding="UTF-8"?>

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">

<xsd:annotation>

<xsd:documentation xml:lang="en">

Results of Hotel Details request, for a given Hotel Code.

Any error messages in "MESSAGE" element with

text "Error" followed by the error description

</xsd:documentation>

</xsd:annotation>

<xsd:element name="RETURNDATA">

<xsd:complexType>

 

-----------XML:

<?xml version='1.0' encoding='UTF-8'?>

<RETURNDATA type='HDR' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:noNamespaceSchemaLocation='http://xx.yy.zz/aaa/HotelDetailRequestV4Rcv.xsd'>

<MESSAGE>Details of the requested Hotel</MESSAGE>

<DATA HOTEL_CODE='AUS' COUNTRY_CODE='AUS' CITY_CODE='SZG' PRINCIPAL_CODE='TRAVCO' BOARD_BASIS_CODE='BB' CATEGORY_CODE='HOT'>

<HOTEL_NAME>Austrotel</HOTEL_NAME>

<COUNTRY_NAME>AUS</COUNTRY_NAME>

............

</DATA>

</RETURNDATA>


--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]


--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]


--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to