* Loads all generator descriptors.
*/
private void loadGenerators()
{
// Load the standard mappings for the standard XML driver
XMLDriver xmlDriver = XMLDriver.getInstance();
try
{
xmlDriver.loadMappings(standardMappedClasses);
}
catch (XMLDriverException e)
{
ExceptionUtil.printTrace(e);
return;
}
generatorList = new ArrayList();
ClassLoader classLoader = getClass().getClassLoader();
String classesDir = Application.getRootDir() + StringUtil.FOLDER_SEP + CockpitConstants.GENERATOR + StringUtil.FOLDER_SEP + "classes";
if (new File(classesDir).isDirectory())
{
// Generator classes directory exists, set up class loader
XClassLoaderConfiguration config = new XClassLoaderConfiguration();
config.setName("Generator template class loader");
config.setParentClassLoader(getClass().getClassLoader());
config.addRepository(classesDir);
try
{
classLoader = new XClassLoader(config);
}
catch (Exception e)
{
ExceptionUtil.printTrace(e);
return;
}
}
ResourceMgr resMgr = ResourceMgr.getDefaultInstance();
String resourcePattern = CockpitConstants.GENERATOR + "/*.xml";
Resource[] resources = null;
try
{
resources = resMgr.findResources(resourcePattern);
}
catch (ResourceMgrException e)
{
return;
}
if (resources.length == 0)
return;
for (int i = 0; i < resources.length; i++)
{
Generator generator = null;
try
{
generator = (Generator) xmlDriver.deserializeResource(Generator.class, resources[i]);
}
catch (XMLDriverException e)
{
ExceptionUtil.printTrace(e);
continue;
}
generator.setGeneratorMgr(this);
generator.setClassLoader(classLoader);
// Create a generator-local XML driver and load the standard mappings
XMLDriver generatorXmlDriver = new XMLDriver(classLoader);
try
{
generatorXmlDriver.loadMappings(standardMappedClasses);
generator.setXmlDriver(generatorXmlDriver);
}
catch (XMLDriverException e)
{
ExceptionUtil.printTrace(e);
continue;
}
// Create the customizer if required
try
{
generator.createCustomizer();
}
catch (Exception e)
{
ExceptionUtil.printTrace(e);
continue;
}
// Load the XML files specified by the customizer
try
{
// Load the mapping for specific generator settings defined by the customizer of the generator
GeneratorCustomizer customizer = generator.getCustomizer();
if (customizer != null)
{
Class [] dependentClasses = customizer.getDependentSettingsClasses();
if (dependentClasses != null)
{
for (int iClasses = 0; iClasses < dependentClasses.length; ++iClasses)
{
generatorXmlDriver.loadMapping(dependentClasses [iClasses]);
}
}
Class settingsClass = customizer.getSettingsClass();
if (settingsClass != null)
{
generatorXmlDriver.loadMapping(settingsClass);
}
}
}
catch (XMLDriverException e)
{