Hello Keith
Your work-around loaded both mapping files correctly. But the work-around is no
solution for me because the common-binding.xml is not used with every binding
file. So I tried to find another solution and I think that I've found the fault
that I've made.
The loading of the mapping.dtd is the problem. Because I defined it as SYSTEM
(<!DOCTYPE mapping SYSTEM "mapping.dtd">) Castor tries to load it from the
install directory of eclipse. Castor throws a MappingException in the Method
loadMappingInternal() but the Exception is ignored in the Method unmarshalled()
in the Mapping class.
public void unmarshalled (Object object) {
if (object instanceof Include) {
Include include = (Include) object;
try {
loadMappingInternal( include.getHref() );
}
catch ( Exception except ) {
//-- ignore error, it'll get reported
//-- later when we re-process the
//-- includes of the parent Mapping in
//-- loadMappingInternal
}
}
}
Castor tries to load the includes in the parent Mapping class. But the method
_state.processed() returns true for the include elements because the state was
set before the iteration over the includes. So the error wasn't reported and
the include file wasn't correctly loaded.
// Load all the included mapping by reference
//-- note: this is just for processing any
//-- includes which may have previously failed
//-- using the IncludeListener...and to
//-- report any potential errors.
Enumeration includes = loaded.enumerateInclude();
while ( includes.hasMoreElements() ) {
Include include = (Include) includes.nextElement();
if (!_state.processed( include.getHref() )) {
try {
loadMappingInternal( include.getHref() );
}
catch ( Exception except ) {
throw new MappingException( except );
}
}
}
I've changed the definition of the DOCTYPE to
<!DOCTYPE mapping PUBLIC "-//EXOLAB/Castor Mapping DTD Version 1.0//EN"
"http://castor.org/mapping.dtd">
And that solved the problem with the loading of the mapping file.
Thanks a lot for your help.
Greetings Christian
-----Ursprüngliche Nachricht-----
Von: Keith Visco [mailto:[EMAIL PROTECTED]
Gesendet: Dienstag, 25. April 2006 23:50
An: [email protected]
Betreff: Re: [castor-user] [XML] Problem with mapping file
Christian,
I'm not sure what the problem would be in resolving the included mapping,
however you could try the following as a work-around:
Mapping mapping = new Mapping();
mapping.loadMapping(commonMappingURL);
mapping.loadMapping(mashalBindingURL);
If I recall correctly, that should load both mapping files.
--Keith
Zeiler Christian, Bedag wrote:
> Hello
>
> I'm using castor 0.9.9.1 with a mapping file (AB-binding.xml). The
> mapping file has an include element that points to another mapping
> file with the mapping definition of the common classes in my project.
> The problem is that Castor can't find the mapping file so it uses the
> default mapping during the Marshalling. I load the mapping file during
> the runtime of my program with the following code and URL:
>
> Mapping mapping = new Mapping();
> mapping.loadMapping(marshalBindingURL);
>
> http://127.0.0.1:8080/binding/AB-binding.xml
>
> Here is the mapping file with the include element. The file
> common-binding.xml is in the same directory.
>
> <?xml version="1.0" encoding="UTF-8"?>
> <!DOCTYPE mapping SYSTEM "mapping.dtd">
> <mapping>
> <include href="common-binding.xml"/>
> <class name="my.ABList" auto-complete="false">
> <map-to xml="AListe"/>
> <field name="AListe" type="java.util.Collection"
> required="false" direct="false" transient="false">
> <bind-xml name="A" location="AListe" node="element"
> reference="false"/>
> </field>
> <field name="BListe" type="java.util.Collection"
> required="false" direct="false" transient="false">
> <bind-xml name="B" location="BListe" node="element"
> reference="false"/>
> </field>
> </class>
> </mapping>
>
> If I run my program with this file it produces a XML file like the
> following one. The elements from the master mapping file have the
> right name but all elements from the common-binding.xml have wrong
> element names. If I change the value from the href attribute to
> http://127.0.0.1:8080/binding/common-binding.xml everything works fine
> and my program creates the correct XML file. But this is no solution
> to me because I must serve several test levels.
>
> <?xml version="1.0" encoding="UTF-8"?>
> <ABListe xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:noNamespaceSchemaLocation="http://127.0.0.1:8080/schema/my-schema.
> xs
> d">
> <AListe>
> <A>
> <element-number-one>value</element-number-one>
> <element-number-two>value</element-number-two>
> ...
> ...
> ...
> </A>
> </AListe>
> </ABListe>
>
> I would really appreciate it if somebody can help me.
>
> Best regards
> Christian
>
>
> -------------------------------------------------
> If you wish to unsubscribe from this list, please
> send an empty message to the following address:
>
> [EMAIL PROTECTED]
> -------------------------------------------------
>
>
> -------------------------------------------------
> If you wish to unsubscribe from this list, please
> send an empty message to the following address:
>
> [EMAIL PROTECTED]
> -------------------------------------------------
>
>
-------------------------------------------------
If you wish to unsubscribe from this list, please
send an empty message to the following address:
[EMAIL PROTECTED]
-------------------------------------------------
-------------------------------------------------
If you wish to unsubscribe from this list, please
send an empty message to the following address:
[EMAIL PROTECTED]
-------------------------------------------------