Are you familiar with Betwixt from Apache Jakarta Commons? Betwixt has a very 
convenient way of
loading mapping files. I was wondering if this could be added to Castor as well. 
Basically,
mapping files are loaded according to qualified class name.

For instance, if I had an instance of a class "mypackage.mysubpackage.MyClass" that 
were to be
marshalled or unmrshalled, Castor could look on the classpath for a file
"mypackage/mysubpackage/MyClass.castor.xml" if there was no mapping already loaded for 
this class.
If it exists, it could use this mapping file for the class. This is easily obtained 
via code
similar to the following (within the Marshaller/Unmarshaller classes)...

...
import org.exolab.castor.mapping.Mapping;
import java.io.InputStream;
import java.io.BufferedInputStream;
import java.net.URL;
...
if (noMappingSpecifiedForTheGivenClass)
{
    URL systemResource = URL 
mapping.getClassLoader().getSystemResource(beanClassName.replace('.',
'/') + ".castor.xml");
    if (systemResource != null)
    {
        // read & load mapping file for this specified class...
        InputStream is = new
BufferedInputStream(systemResource.openConnection().getInputStream());
        ...
        is.close();
    }
    else
    {
        // do default marshalling/unmarshalling...
        ...
    }
}
...

This way, all one has to do is partner every class with a mapping file, which is much 
easier to
keep track of within larger projects...

my-jar-file.jar
{
    mypackage/MyClass1.class
    mypackage/MyClass1.castor.xml
    mypackage/MyClass2.class
    mypackage/MyClass2.castor.xml
    mypackage/mysubpackage/MyClass3.class
    mypackage/mysubpackage/MyClass3.castor.xml
    mypackage/mysubpackage/MyClass1.class
    mypackage/mysubpackage/MyClass1.castor.xml
    mypackage/mysubpackage/MyClass2.class
    mypackage/mysubpackage/MyClass2.castor.xml
    mypackage/mysubpackage/MyClass3.class
    mypackage/mysubpackage/MyClass3.castor.xml
}

Thanks!

=====
[EMAIL PROTECTED]

__________________________________
Do you Yahoo!?
Yahoo! Calendar - Free online calendar with sync to Outlook(TM).
http://calendar.yahoo.com

----------------------------------------------------------- 
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
        unsubscribe castor-dev

Reply via email to