|
Hi,
I have been trying to use the SourceGenerator from
within another Java program and think there may be a small problem with setting
the default properties, specifically when calling
BuilderConfiguration.setDefaultProperties() with regards to the
Namespace->Java packages properties. "org.exolab.castor.xml.nspackages",
"org.exolab.castor.builder.nspackages".
I have to modify the values of these properties at
runtime during each call to the SourceGenerator, hence I cannot rely on the
physical builder.properties file, and need to specify namespace->javapackage
mappings at runtime. Here is how I am doing it (shorthand for this
example)
[1] SourceGenerator sg = new
SourceGenerator();
[2] Properties props = new
Properties();
[3a]
props.setProperty("org.exolab.castor.builder.nspackages","http://www.mynamespace=my.java.package);
OR
[3b]
props.setProperty("org.exolab.castor.xml.nspackages","http://www.mynamespace=my.java.package);
[4] sg.setDefaultProperties(props);
[5] sg.setDestDir("mydir");
[6]
sg.generateSource("mysxsdfile.xsd","mytargetpackage");
When this runs, my specified namespace->javaPkg
mappings are not taking effect.
I started debugging the Castor 0.9.5.3 source and
specifically am looking at the implementation of
[391]BuilderConfiguration.setDefaultProperties().
This method properly parses and sorts out the
passed java.util.Properties passed to it, however it just sets the results =
_localProps.
While SourceGenerator is generating source, it
continually makes calls to [493] BuilderConfiguration.lookupPackageByNamespace(
) which consults the _nspackages variable.
Point being is that _nspackages is seeded at
loadtime of SourceGenerator. It is never "refreshed" with updated values if
someone calls BuilderConfiguration.setDefaultProperties().
Shouldn't the _nspackages variable be updated via
[544] BuilderConfiguration.processNamespacePackageMappings() at somepoint after
someone calls setDefaultProperties()?
What I have had to do as a workaround is to make
the processNamespacePackageMappings() public, so that I can call it directly in
my program and pass it the namespace->javaPkg mappings String at runtime.
(replacing lines 2-4 above in my sample program) By doing this my generated Java
classes have the proper imports that I expect.
Can this be fixed or a workaround provided? Am I
looking at this incorrectly?
thanks!
|
-----------------------------------------------------------
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
unsubscribe castor-dev
