1
|
package eu.dnetlib.data.collector;
|
2
|
|
3
|
import java.util.Collection;
|
4
|
|
5
|
import org.springframework.beans.BeansException;
|
6
|
import org.springframework.beans.factory.BeanFactory;
|
7
|
import org.springframework.beans.factory.BeanFactoryAware;
|
8
|
import org.springframework.beans.factory.ListableBeanFactory;
|
9
|
|
10
|
import eu.dnetlib.data.collector.plugin.CollectorPlugin;
|
11
|
import eu.dnetlib.data.collector.rmi.CollectorServiceException;
|
12
|
|
13
|
public class CollectorPluginEnumerator implements BeanFactoryAware {
|
14
|
|
15
|
// private static final Log log = LogFactory.getLog(CollectorPluginEnumerator.class); // NOPMD by marko on 11/24/08 5:02 PM
|
16
|
|
17
|
/**
|
18
|
* bean factory.
|
19
|
*/
|
20
|
private ListableBeanFactory beanFactory;
|
21
|
|
22
|
/**
|
23
|
* Get all beans implementing the CollectorPlugin interface.
|
24
|
*
|
25
|
* @return
|
26
|
*/
|
27
|
public Collection<CollectorPlugin> getAll() {
|
28
|
return beanFactory.getBeansOfType(CollectorPlugin.class).values();
|
29
|
}
|
30
|
|
31
|
@Override
|
32
|
public void setBeanFactory(final BeanFactory beanFactory) throws BeansException {
|
33
|
this.beanFactory = (ListableBeanFactory) beanFactory;
|
34
|
}
|
35
|
|
36
|
public ListableBeanFactory getBeanFactory() {
|
37
|
return beanFactory;
|
38
|
}
|
39
|
|
40
|
/**
|
41
|
* Get given CollectorPlugin or throws exception.
|
42
|
*
|
43
|
* @param protocol
|
44
|
* @return
|
45
|
* @throws CollectorServiceException
|
46
|
*/
|
47
|
public CollectorPlugin get(final String protocol) throws CollectorServiceException {
|
48
|
for (CollectorPlugin cp : getAll()) {
|
49
|
if (protocol.equalsIgnoreCase(cp.getProtocol())) {
|
50
|
return cp;
|
51
|
}
|
52
|
}
|
53
|
throw new CollectorServiceException("plugin not found for protocol: " + protocol);
|
54
|
}
|
55
|
}
|