/** * Load a {@link ServiceRegistrarFactory} using a class loader. * * @param source The source of the class loader. * @param classLoader The class loader to load from. * * @return A {@link ServiceRegistrarFactory}, null if none could be found. * * @throws ServiceRegistrarLoadingException if loading failed. */ public static ServiceRegistrarFactory load(final String source, final ClassLoader classLoader) throws ServiceRegistrarLoadingException { final ServiceLoader<ServiceRegistrarFactory> loader; try { loader = ServiceLoader.load(ServiceRegistrarFactory.class, classLoader); } catch (ServiceConfigurationError e) { throw new ServiceRegistrarLoadingException( "Failed to load service registrar from " + source, e); } final Iterator<ServiceRegistrarFactory> iterator = loader.iterator(); if (iterator.hasNext()) { return iterator.next(); } else { return null; } }
/** * Load a {@link ServiceRegistrarFactory} using a class loader. * * @param source The source of the class loader. * @param classLoader The class loader to load from. * @return A {@link ServiceRegistrarFactory}, null if none could be found. * @throws ServiceRegistrarLoadingException if loading failed. */ public static ServiceRegistrarFactory load(final String source, final ClassLoader classLoader) throws ServiceRegistrarLoadingException { final ServiceLoader<ServiceRegistrarFactory> loader; try { loader = ServiceLoader.load(ServiceRegistrarFactory.class, classLoader); } catch (ServiceConfigurationError e) { throw new ServiceRegistrarLoadingException( "Failed to load service registrar from " + source, e); } final Iterator<ServiceRegistrarFactory> iterator = loader.iterator(); if (iterator.hasNext()) { return iterator.next(); } else { return null; } }