/** * Create new instance of class implementing SPI. * * @param <T> The SPI type * @param loaders The class loaders holder * @param spi Service Provider Interface Class. * @param properties Used to determine name of SPI implementation, * and passed to implementation.init() method if * implementation implements Service interface. * @param defaultImpl Default implementation. * @return Instance of a class implementing the SPI. * @exception DiscoveryException Thrown if the name of a class implementing * the SPI cannot be found, if the class cannot be loaded and * instantiated, or if the resulting class does not implement * (or extend) the SPI. * @throws InstantiationException see {@link Class#newInstance()} * @throws IllegalAccessException see {@link Class#newInstance()} * @throws NoSuchMethodException see {@link Class#newInstance()} * @throws InvocationTargetException see {@link Class#newInstance()} */ public static <T> T newInstance(ClassLoaders loaders, SPInterface<T> spi, PropertiesHolder properties, DefaultClassHolder<T> defaultImpl) throws DiscoveryException, InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException { return spi.newInstance(find(loaders, spi, properties, defaultImpl)); }
private S getNextClassInstance() { while (services.hasNext()) { ResourceClass<S> info = services.nextResourceClass(); try { return spi.newInstance(info.loadClass()); } catch (Exception e) { // ignore } catch (LinkageError le) { // ignore } } return null; } };