1 |
32307
|
claudio.at
|
package eu.dnetlib.data.download;
|
2 |
26600
|
sandro.lab
|
|
3 |
|
|
import java.util.Map;
|
4 |
|
|
|
5 |
|
|
import org.springframework.beans.BeansException;
|
6 |
|
|
import org.springframework.beans.factory.BeanFactory;
|
7 |
|
|
import org.springframework.beans.factory.ListableBeanFactory;
|
8 |
|
|
|
9 |
|
|
import com.google.common.collect.Maps;
|
10 |
|
|
|
11 |
32499
|
sandro.lab
|
import eu.dnetlib.data.download.rmi.DownloadPlugin;
|
12 |
|
|
import eu.dnetlib.data.download.rmi.DownloadPluginEnumerator;
|
13 |
|
|
import eu.dnetlib.data.download.rmi.DownloadServiceException;
|
14 |
26600
|
sandro.lab
|
|
15 |
30077
|
sandro.lab
|
/**
|
16 |
|
|
* The Class DownloadPluginEnumeratorImpl.
|
17 |
|
|
*/
|
18 |
|
|
public class DownloadPluginEnumeratorImpl implements DownloadPluginEnumerator {
|
19 |
32499
|
sandro.lab
|
|
20 |
26600
|
sandro.lab
|
/**
|
21 |
|
|
* bean factory.
|
22 |
|
|
*/
|
23 |
|
|
private ListableBeanFactory beanFactory;
|
24 |
|
|
|
25 |
32499
|
sandro.lab
|
/*
|
26 |
|
|
* (non-Javadoc)
|
27 |
|
|
*
|
28 |
30077
|
sandro.lab
|
* @see eu.dnetlib.data.download.rmi.DownloadPluginEnumerator#getAll()
|
29 |
26600
|
sandro.lab
|
*/
|
30 |
30077
|
sandro.lab
|
@Override
|
31 |
26600
|
sandro.lab
|
public Map<String, DownloadPlugin> getAll() {
|
32 |
|
|
return beanFactory.getBeansOfType(DownloadPlugin.class);
|
33 |
|
|
}
|
34 |
|
|
|
35 |
32499
|
sandro.lab
|
/*
|
36 |
|
|
* (non-Javadoc)
|
37 |
|
|
*
|
38 |
30077
|
sandro.lab
|
* @see eu.dnetlib.data.download.rmi.DownloadPluginEnumerator#getByProtocols()
|
39 |
26600
|
sandro.lab
|
*/
|
40 |
30077
|
sandro.lab
|
@Override
|
41 |
26600
|
sandro.lab
|
public Map<String, DownloadPlugin> getByProtocols() {
|
42 |
|
|
final Map<String, DownloadPlugin> res = Maps.newHashMap();
|
43 |
|
|
for (DownloadPlugin cp : getAll().values()) {
|
44 |
|
|
res.put(cp.getPluginName().toLowerCase(), cp);
|
45 |
|
|
}
|
46 |
|
|
return res;
|
47 |
|
|
}
|
48 |
|
|
|
49 |
32499
|
sandro.lab
|
/*
|
50 |
|
|
* (non-Javadoc)
|
51 |
|
|
*
|
52 |
30077
|
sandro.lab
|
* @see org.springframework.beans.factory.BeanFactoryAware#setBeanFactory(org.springframework.beans.factory.BeanFactory)
|
53 |
|
|
*/
|
54 |
26600
|
sandro.lab
|
@Override
|
55 |
|
|
public void setBeanFactory(final BeanFactory beanFactory) throws BeansException {
|
56 |
|
|
this.beanFactory = (ListableBeanFactory) beanFactory;
|
57 |
|
|
}
|
58 |
|
|
|
59 |
30077
|
sandro.lab
|
/**
|
60 |
|
|
* Gets the bean factory.
|
61 |
|
|
*
|
62 |
|
|
* @return the bean factory
|
63 |
|
|
*/
|
64 |
26600
|
sandro.lab
|
public ListableBeanFactory getBeanFactory() {
|
65 |
|
|
return beanFactory;
|
66 |
|
|
}
|
67 |
|
|
|
68 |
|
|
/**
|
69 |
|
|
* Get given DownloadPlugin or throws exception.
|
70 |
30077
|
sandro.lab
|
*
|
71 |
32499
|
sandro.lab
|
* @param protocol
|
72 |
|
|
* the protocol
|
73 |
30077
|
sandro.lab
|
* @return the download plugin
|
74 |
32499
|
sandro.lab
|
* @throws eu.dnetlib.data.download.rmi.DownloadServiceException
|
75 |
|
|
* the download service exception
|
76 |
26600
|
sandro.lab
|
*/
|
77 |
|
|
public DownloadPlugin get(final String protocol) throws DownloadServiceException {
|
78 |
|
|
final DownloadPlugin plugin = getByProtocols().get(protocol.toLowerCase());
|
79 |
|
|
if (plugin == null) throw new DownloadServiceException("plugin not found for name: " + protocol);
|
80 |
|
|
return plugin;
|
81 |
|
|
}
|
82 |
|
|
|
83 |
|
|
}
|