* the ClassLoader to use
*/
@SuppressWarnings("unchecked")
private void loadPluginClass(final String pluginClassName, final ClassLoader classLoader) {
Class<?> untypedPluginClass;
PluginLoader pluginLoader;
Map<String, TaskManagerFactory> pluginTasks;
// Load the plugin class.
try {
untypedPluginClass = classLoader.loadClass(pluginClassName);
} catch (ClassNotFoundException e) {
throw new OsmosisRuntimeException("Unable to load plugin class (" + pluginClassName + ").", e);
}
// Verify that the plugin implements the plugin loader interface.
if (!PluginLoader.class.isAssignableFrom(untypedPluginClass)) {
throw new OsmosisRuntimeException("The class (" + pluginClassName + ") does not implement interface ("
+ PluginLoader.class.getName() + "). Maybe it's not a plugin?");
}
Class<PluginLoader> pluginClass = (Class<PluginLoader>) untypedPluginClass;
// Instantiate the plugin loader.
try {
pluginLoader = pluginClass.newInstance();
} catch (InstantiationException e) {
throw new IllegalArgumentException("Unable to instantiate plugin class (" + pluginClassName + ").", e);
} catch (IllegalAccessException e) {
throw new IllegalArgumentException("Unable to instantiate plugin class (" + pluginClassName + ").", e);
}
// Obtain the plugin task factories with their names.
pluginTasks = pluginLoader.loadTaskFactories();
// Register the plugin tasks.
for (Entry<String, TaskManagerFactory> taskEntry : pluginTasks.entrySet()) {
factoryRegister.register(taskEntry.getKey(), taskEntry.getValue());
}