Searches the class path for the specific plugin of a given type Note: If you want to load JARs dynamically, you need to call #loadJAR or #loadJARs methods with the proper file or directory first, otherwise this will only search whatever was loaded on startup. WARNIN
(final String name,
final Class<T> type)
| 92 | * @throws IllegalArgumentException if the plugin name is null or empty |
| 93 | */ |
| 94 | public static <T> T loadSpecificPlugin(final String name, |
| 95 | final Class<T> type) { |
| 96 | if (name.isEmpty()) { |
| 97 | throw new IllegalArgumentException("Missing plugin name"); |
| 98 | } |
| 99 | ServiceLoader<T> serviceLoader = ServiceLoader.load(type); |
| 100 | Iterator<T> it = serviceLoader.iterator(); |
| 101 | if (!it.hasNext()) { |
| 102 | LOG.warn("Unable to locate any plugins of the type: " + type.getName()); |
| 103 | return null; |
| 104 | } |
| 105 | |
| 106 | while(it.hasNext()) { |
| 107 | T plugin = it.next(); |
| 108 | if (plugin.getClass().getName().equals(name) || plugin.getClass().getSuperclass().getName().equals(name)) { |
| 109 | return plugin; |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | LOG.warn("Unable to locate plugin: " + name); |
| 114 | return null; |
| 115 | } |
| 116 | |
| 117 | /** |
| 118 | * Searches the class path for implementations of the given type, returning a |