Code example for ServiceLoader

Methods: iterator

0
 */ 
public class ServiceFactoryBean extends AbstractServiceLoaderBasedFactoryBean implements BeanClassLoaderAware {
 
	@Override 
	protected Object getObjectToExpose(ServiceLoader<?> serviceLoader) {
		Iterator<?> it = serviceLoader.iterator();
		if (!it.hasNext()) {
			throw new IllegalStateException(
					"ServiceLoader could not find service for type [" + getServiceType() + "]"); 
		} 
		return it.next();
	} 
 
	@Override 
	public Class<?> getObjectType() {
		return getServiceType(); 
	} 
 
}