All Downloads are FREE. Search and download functionalities are using the official Maven repository.

kikaha.core.cdi.helpers.ServiceLoader Maven / Gradle / Ivy

package kikaha.core.cdi.helpers;

import java.util.*;

public abstract class ServiceLoader {

	public static  List> loadImplementationsFor( Class clazz ) {
		final ClassLoader cl = Thread.currentThread().getContextClassLoader();
		final Iterator> reader = new LazyClassReader( clazz, cl );
		return readAndConvertToList( reader );
	}

	public static  List> loadImplementationsFor( String clazz ) {
		final ClassLoader cl = Thread.currentThread().getContextClassLoader();
		final Iterator> reader = new LazyClassReader( clazz, cl );
		return readAndConvertToList( reader );
	}

	private static  List> readAndConvertToList( final Iterator> reader ) {
		final List> list = new TinyList<>();
		while ( reader.hasNext() )
			try {
				list.add( reader.next() );
			} catch ( IllegalStateException cause ) {
				continue;
			}
		return list;
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy