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

org.crsh.spring.SpringPluginDiscovery Maven / Gradle / Ivy

There is a newer version: 1.3.2
Show newest version
package org.crsh.spring;

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

import org.crsh.plugin.CRaSHPlugin;
import org.crsh.plugin.ServiceLoaderDiscovery;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.ListableBeanFactory;

public class SpringPluginDiscovery extends ServiceLoaderDiscovery {

	private BeanFactory factory;

	public SpringPluginDiscovery(ClassLoader classLoader, BeanFactory factory)
	        throws NullPointerException {
		super(classLoader);
		this.factory = factory;
	}

	@SuppressWarnings("rawtypes")
    @Override
    public Iterable> getPlugins() {
		List> serviceAndSpringPlugins = new ArrayList>();
		
		for (CRaSHPlugin cRaSHPlugin : super.getPlugins()) {
	        serviceAndSpringPlugins.add(cRaSHPlugin);
        }
		
		if (factory instanceof ListableBeanFactory) {
            Collection springPlugins = ((ListableBeanFactory)factory)
            .getBeansOfType(CRaSHPlugin.class).values();
			
			for (CRaSHPlugin cRaSHPlugin : springPlugins) {
	            serviceAndSpringPlugins.add(cRaSHPlugin);
            }
		}
		
		return serviceAndSpringPlugins;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy