Project

General

Profile

1
package eu.dnetlib.data.collector;
2

    
3
import java.util.Collection;
4

    
5
import eu.dnetlib.rmi.data.CollectorServiceException;
6
import eu.dnetlib.rmi.data.plugin.CollectorPlugin;
7
import org.springframework.beans.BeansException;
8
import org.springframework.beans.factory.BeanFactory;
9
import org.springframework.beans.factory.BeanFactoryAware;
10
import org.springframework.beans.factory.ListableBeanFactory;
11

    
12
public class CollectorPluginEnumerator implements BeanFactoryAware {
13

    
14
	// private static final Log log = LogFactory.getLog(CollectorPluginEnumerator.class); // NOPMD by marko on 11/24/08 5:02 PM
15

    
16
	/**
17
	 * bean factory.
18
	 */
19
	private ListableBeanFactory beanFactory;
20

    
21
	/**
22
	 * Get all beans implementing the CollectorPlugin interface.
23
	 *
24
	 * @return
25
	 */
26
	public Collection<CollectorPlugin> getAll() {
27
		return beanFactory.getBeansOfType(CollectorPlugin.class).values();
28
	}
29

    
30
	public ListableBeanFactory getBeanFactory() {
31
		return beanFactory;
32
	}
33

    
34
	@Override
35
	public void setBeanFactory(final BeanFactory beanFactory) throws BeansException {
36
		this.beanFactory = (ListableBeanFactory) beanFactory;
37
	}
38

    
39
	/**
40
	 * Get given CollectorPlugin or throws exception.
41
	 *
42
	 * @param protocol
43
	 * @return
44
	 * @throws CollectorServiceException
45
	 */
46
	public CollectorPlugin get(final String protocol) throws CollectorServiceException {
47
		for (CollectorPlugin cp : getAll()) {
48
            if (protocol.trim().equalsIgnoreCase(cp.getProtocol())) {
49
                return cp;
50
			}
51
		}
52
		throw new CollectorServiceException("plugin not found for protocol: " + protocol);
53
	}
54
}
(1-1/2)