* @throws IOException
* if any IOException occurs preparing the source generator.
*/
private SourceGenerator createSourceGenerator() throws IOException {
// Create our source generator
final SourceGenerator sourceGen;
if (_fieldInfoFactoryName != null) {
FieldInfoFactory factory = new FieldInfoFactory(_fieldInfoFactoryName);
sourceGen = new SourceGenerator(factory);
} else {
sourceGen = new SourceGenerator();
}
// Do we have a castorbuilder.properties file?
if (_propertyFileName != null) {
if (!(new File(_test.getTestFile(), _propertyFileName)).exists()) {
fail("Test properties file '" + _propertyFileName + "' does not exist; check TestDescriptor.xml");
}
Properties prop = new Properties();
prop.load(_test.getClassLoader().getResourceAsStream(_propertyFileName));
sourceGen.setDefaultProperties(prop);
} else {
//don't forget to reset the properties
sourceGen.setDefaultProperties(null);
}
// Do we have a binding file?
if (_bindingFileName != null && _bindingFileName.length() >0) {
File bindingFile = new File(_outputRootFile, _bindingFileName);
if ( !bindingFile.exists()) {
fail("Unable to find the specified binding file: " + _bindingFileName);
}
verbose("using binding file: " + bindingFile.getAbsolutePath());
InputSource source = new InputSource(new FileReader(bindingFile));
source.setSystemId(bindingFile.getAbsolutePath());
sourceGen.setBinding(source);
}
// Final configuration of our source generator
sourceGen.setEqualsMethod(true);
sourceGen.setTestable(true);
sourceGen.setSuppressNonFatalWarnings(true);
sourceGen.setFailOnFirstError(true);
sourceGen.setGenerateImportedSchemas(_genFromImported);
sourceGen.setDestDir(_outputRootFile.getAbsolutePath());
return sourceGen;
}