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

org.jpmml.model.ServiceLoaderUtil Maven / Gradle / Ivy

There is a newer version: 1.6.6
Show newest version
/*
 * Copyright (c) 2019 Villu Ruusmann
 */
package org.jpmml.model;

import java.util.Iterator;
import java.util.ServiceConfigurationError;
import java.util.ServiceLoader;

import org.dmg.pmml.PMMLObject;

public class ServiceLoaderUtil {

	private ServiceLoaderUtil(){
	}

	static
	public  E load(Class clazz, ClassLoader clazzLoader){
		ServiceLoader serviceLoader;

		try {
			serviceLoader = ServiceLoader.load(clazz, clazzLoader);
		} catch(ServiceConfigurationError sce){
			throw new IllegalArgumentException(sce);
		}

		Iterator it = serviceLoader.iterator();

		if(it.hasNext()){
			E object = it.next();

			if(it.hasNext()){
				throw new IllegalArgumentException();
			}

			return object;
		}

		throw new IllegalArgumentException();
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy