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

com.orientechnologies.common.util.OClassLoaderHelper Maven / Gradle / Ivy

The newest version!
package com.orientechnologies.common.util;

import java.util.Iterator;

import com.wuman.spi.ServiceRegistry;

public class OClassLoaderHelper {

	/**
	 * Switch to the OrientDb classloader before lookups on ServiceRegistry for
	 * implementation of the given Class. Useful under OSGI and generally under
	 * applications where jars are loaded by another class loader
	 * 
	 * @param clazz
	 *            the class to lookup foor
	 * @return an Iterator on the class implementation
	 */
	public static synchronized  Iterator lookupProviderWithOrientClassLoader(Class clazz) {

		return lookupProviderWithOrientClassLoader(clazz,OClassLoaderHelper.class.getClassLoader());
	}

	public static synchronized  Iterator lookupProviderWithOrientClassLoader(Class clazz,ClassLoader orientClassLoader) {
		
		ClassLoader origClassLoader = Thread.currentThread().getContextClassLoader();

		Thread.currentThread().setContextClassLoader(orientClassLoader);
		Iterator lookupProviders = ServiceRegistry.lookupProviders(clazz);
		Thread.currentThread().setContextClassLoader(origClassLoader);

		return lookupProviders;
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy