Search in sources :

Example 1 with PluginLoader

use of org.openstreetmap.osmosis.core.plugin.PluginLoader in project osmosis by openstreetmap.

the class TaskRegistrar method loadPluginClass.

/**
 * Load the given plugin, old API or new JPF.
 *
 * @param pluginClassName
 *            the name of the class to instantiate
 * @param classLoader
 *            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());
    }
}
Also used : TaskManagerFactory(org.openstreetmap.osmosis.core.pipeline.common.TaskManagerFactory) PluginLoader(org.openstreetmap.osmosis.core.plugin.PluginLoader)

Aggregations

TaskManagerFactory (org.openstreetmap.osmosis.core.pipeline.common.TaskManagerFactory)1 PluginLoader (org.openstreetmap.osmosis.core.plugin.PluginLoader)1