All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.mycila.plugin.spi.PluginManager Maven / Gradle / Ivy

There is a newer version: 1.10
Show newest version
/**
 * Copyright (C) 2008 Mathieu Carbou 
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.mycila.plugin.spi;

import com.mycila.log.Logger;
import com.mycila.log.Loggers;
import com.mycila.plugin.api.Plugin;
import com.mycila.plugin.api.PluginCache;
import com.mycila.plugin.api.PluginLoader;
import com.mycila.plugin.api.PluginResolver;
import static com.mycila.plugin.spi.Ensure.*;

/**
 * Defines a new plugin manager based on a plugin descriptor or
 * memory based if you do not pass a descriptor (i.e. META-INF/plugins.properties)
 *
 * @author Mathieu Carbou ([email protected])
 */
public final class PluginManager {

    private static final Logger LOGGER = Loggers.get(PluginManager.class);

    private final PluginLoader loader;
    private final PluginResolver resolver;
    private final PluginCache cache;

    public PluginManager(Class pluginType) {
        notNull("Plugin type", pluginType);
        LOGGER.debug("Creating new empty PluginManager for plugin type {0}", pluginType);
        loader = new DefaultPluginLoader(pluginType);
        cache = new DefaultPluginCache(loader);
        resolver = new DefaultPluginResolver(cache);
    }

    public PluginManager(Class pluginType, String pluginDescriptor) {
        notNull("Plugin type", pluginType);
        notEmpty("Plugin descriptor", pluginDescriptor);
        LOGGER.debug("Creating new PluginManager for plugin type {0} from descriptors {1}", pluginType, pluginDescriptor);
        loader = new DefaultPluginLoader(pluginType, pluginDescriptor);
        cache = new DefaultPluginCache(loader);
        resolver = new DefaultPluginResolver(cache);
    }

    public PluginCache getCache() {
        return cache;
    }

    public PluginLoader getLoader() {
        return loader;
    }

    public PluginResolver getResolver() {
        return resolver;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy