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

📄 abstractmoduledescriptor.java

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

import com.opensymphony.tonic.ModuleDescriptor;
import com.opensymphony.tonic.loaders.LoaderUtils;
import com.opensymphony.tonic.PluginParseException;
import com.opensymphony.tonic.Plugin;
import org.dom4j.Element;

import java.util.Map;

public abstract class AbstractModuleDescriptor implements ModuleDescriptor
{
    private Plugin plugin;
    String key;
    String name;
    Class moduleClass;
    String description;
    boolean enabledByDefault = true;
    protected boolean singleton = true;
    Map params;

    public void init(Plugin plugin, Element element) throws PluginParseException
    {
        this.plugin = plugin;
        this.key = element.attributeValue("key");
        this.name = element.attributeValue("name");

        String clazz = element.attributeValue("class");
        try
        {
            if (clazz != null)  //not all plugins have to have a class
                moduleClass = plugin.loadClass(clazz, getClass());
        }
        catch (ClassNotFoundException e)
        {
            throw new PluginParseException("Could not load class: " + clazz);
        }

        this.description = element.elementTextTrim("description");
        params = LoaderUtils.getParams(element);

        if ("disabled".equalsIgnoreCase(element.attributeValue("state")))
            enabledByDefault = false;

        if ("false".equalsIgnoreCase(element.attributeValue("singleton")))
            singleton = false;
        else if ("true".equalsIgnoreCase(element.attributeValue("singleton")))
            singleton = true;
        else
            singleton = isSingletonByDefault();
    }

    /**
     * Override this if your tonic needs to clean up when it's been removed.
     * @param plugin
     */
    public void destroy(Plugin plugin)
    {}

    public boolean isEnabledByDefault()
    {
        return enabledByDefault;
    }

    public boolean isSingleton()
    {
        return singleton;
    }

    /**
     * Override this method if you want your module descriptor to be or not be a singleton by default.
     * <p>
     * Default is "true" - ie all tonic modules are singletons by default.
     */
    protected boolean isSingletonByDefault()
    {
        return true;
    }

    /**
     * Check that the module class of this descriptor implements a given interface, or extends a given class.
     * @param requiredModuleClazz The class this module's class must implement or extend.
     * @throws PluginParseException If the module class does not implement or extend the given class.
     */
    final protected void assertModuleClassImplements(Class requiredModuleClazz) throws PluginParseException
    {
        if (!requiredModuleClazz.isAssignableFrom(getModuleClass()))
            throw new PluginParseException("Given module class: " + getModuleClass().getName() + " does not implement " + requiredModuleClazz.getName());
    }

    public String getCompleteKey() {
        return plugin.getKey() + ":" + getKey();
    }

    public String getKey()
    {
        return key;
    }

    public String getName()
    {
        return name;
    }

    public Class getModuleClass()
    {
        return moduleClass;
    }

    public abstract Object getModule();

    public String getDescription()
    {
        return description;
    }

    public Map getParams()
    {
        return params;
    }
}

⌨️ 快捷键说明

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