Search in sources :

Example 1 with Plugin

use of org.openksavi.sponge.plugin.Plugin in project sponge by softelnet.

the class DefaultPluginManager method createPluginStub.

/**
 * Creates a plugin stub.
 *
 * @param pluginName a plugin name.
 * @param knowledgeBaseName a knowledge base name.
 * @param pluginClassName a plugin class name.
 * @return a plugin stub.
 */
protected Plugin createPluginStub(String pluginName, String knowledgeBaseName, String pluginClassName) {
    try {
        Plugin plugin = new KnowledgeBasePluginStub(knowledgeBaseName, pluginClassName);
        plugin.setName(pluginName);
        return plugin;
    } catch (Throwable e) {
        throw SpongeUtils.wrapException(pluginName, e);
    }
}
Also used : KnowledgeBasePluginStub(org.openksavi.sponge.core.plugin.KnowledgeBasePluginStub) Plugin(org.openksavi.sponge.plugin.Plugin)

Example 2 with Plugin

use of org.openksavi.sponge.plugin.Plugin in project sponge by softelnet.

the class DefaultPluginManager method createAndConfigurePlugin.

/**
 * Creates and configures a plugin.
 *
 * @param pluginConfig plugin configuration.
 * @return a plugin.
 */
public Plugin createAndConfigurePlugin(Configuration pluginConfig) {
    String pluginName = pluginConfig.getAttribute(PluginManagerConstants.CFG_PLUGIN_NAME, null);
    if (StringUtils.isBlank(pluginName)) {
        throw new SpongeException("Plugin should have a name");
    }
    String className = pluginConfig.getAttribute(PluginManagerConstants.CFG_PLUGIN_CLASS, null);
    if (StringUtils.isBlank(className)) {
        throw new SpongeException("Plugin configuration should specify a class: " + pluginName);
    }
    String knowledgeBaseName = pluginConfig.getAttribute(PluginManagerConstants.CFG_PLUGIN_KB_NAME, null);
    Plugin plugin = createPluginStub(pluginName, knowledgeBaseName, className);
    if (existsPlugin(plugin.getName())) {
        throw new SpongeException("Plugin '" + plugin.getName() + "' already exists.");
    }
    if (plugin.getName() != null && plugin.getName().equals(KnowledgeBaseConstants.VAR_ENGINE_OPERATIONS)) {
        throw new SpongeException("Invalid plugin name: " + plugin.getName());
    }
    plugin.setConfiguration(pluginConfig.getChildConfiguration(PluginManagerConstants.CFG_PLUGIN_CONFIGURATION), true);
    return plugin;
}
Also used : SpongeException(org.openksavi.sponge.SpongeException) Plugin(org.openksavi.sponge.plugin.Plugin)

Example 3 with Plugin

use of org.openksavi.sponge.plugin.Plugin in project sponge by softelnet.

the class DefaultPluginManager method loadPlugin.

/**
 * Loads a plugin.
 *
 * @param pluginStub a plugin stub.
 * @return loaded plugin.
 */
protected Plugin loadPlugin(KnowledgeBasePluginStub pluginStub) {
    try {
        KnowledgeBase knowledgeBase = pluginStub.getKnowledgeBaseName() != null ? getEngine().getKnowledgeBaseManager().getKnowledgeBase(pluginStub.getKnowledgeBaseName()) : getEngine().getKnowledgeBaseManager().getDefaultKnowledgeBase();
        Plugin plugin = knowledgeBase.getInterpreter().createPluginInstance(pluginStub.getPluginClassName());
        if (pluginStub.getName() != null) {
            plugin.setName(pluginStub.getName());
        }
        plugin.setEngine(getEngine());
        plugin.setKnowledgeBase(knowledgeBase);
        plugin.setConfiguration(pluginStub.getConfiguration(), true);
        return plugin;
    } catch (Throwable e) {
        throw SpongeUtils.wrapException(e);
    }
}
Also used : KnowledgeBase(org.openksavi.sponge.kb.KnowledgeBase) Plugin(org.openksavi.sponge.plugin.Plugin)

Aggregations

Plugin (org.openksavi.sponge.plugin.Plugin)3 SpongeException (org.openksavi.sponge.SpongeException)1 KnowledgeBasePluginStub (org.openksavi.sponge.core.plugin.KnowledgeBasePluginStub)1 KnowledgeBase (org.openksavi.sponge.kb.KnowledgeBase)1