⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 singlepluginloader.java

📁 模块化您的应用系统
💻 JAVA
字号:
package com.opensymphony.tonic.loaders;

import com.opensymphony.tonic.ModuleDescriptorFactory;
import com.opensymphony.tonic.impl.StaticPlugin;
import com.opensymphony.tonic.PluginParseException;
import com.opensymphony.tonic.Plugin;
import com.opensymphony.tonic.PluginException;
import org.dom4j.Document;
import org.dom4j.DocumentException;

import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

public class SinglePluginLoader extends AbstractXmlPluginLoader
{
    List plugins;
    protected String resource;
    protected InputStream is;

    public SinglePluginLoader(String resource)
    {
        this.resource = resource;
    }

    public SinglePluginLoader(InputStream is)
    {
        this.is = is;
    }

    public Collection loadAllPlugins(ModuleDescriptorFactory moduleDescriptorFactory) throws PluginParseException
    {
        if (plugins == null)
        {
            plugins = new ArrayList();
            loadPlugins(moduleDescriptorFactory);
        }

        return plugins;
    }

    public boolean supportsRemoval()
    {
        return false;
    }

    public boolean supportsAddition()
    {
        return false;
    }

    public Collection removeMissingPlugins()
    {
        throw new UnsupportedOperationException("This PluginLoader does not support removal.");
    }

    public Collection addFoundPlugins(ModuleDescriptorFactory moduleDescriptorFactory)
    {
        throw new UnsupportedOperationException("This PluginLoader does not support addition.");
    }

    public void removePlugin(Plugin plugin) throws PluginException
    {
        throw new PluginException("This PluginLoader does not support removal.");
    }

    private void loadPlugins(ModuleDescriptorFactory moduleDescriptorFactory) throws PluginParseException
    {
        if (resource == null && is == null)
            throw new PluginParseException("No resource or inputstream specified to load plugins from.");

        try
        {
            Plugin plugin = configurePlugin(moduleDescriptorFactory, getDocument(), new StaticPlugin());
            plugins.add(plugin);
        }
        catch (DocumentException e)
        {
            throw new PluginParseException("Exception parsing plugin document", e);
        }
    }

    protected Document getDocument() throws DocumentException, PluginParseException
    {
        Document doc = null;

        if (resource != null)
            doc = getDocument(resource);
        else
            doc = getDocument(is);

        return doc;
    }

    public void setRecogniseSystemPlugins(boolean recogniseSystemPlugins)
    {
        this.recogniseSystemPlugins = recogniseSystemPlugins;
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -