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

org.hibernate.validation.util.LoadClass Maven / Gradle / Ivy

Go to download

Module repackaging of the Hibernate validator library and Validation API (JSR 303)

There is a newer version: 3.0-JBoss-4.0.2_03
Show newest version
package org.hibernate.validation.util;

import java.security.PrivilegedAction;
import javax.validation.ValidationException;

/**
 * @author Emmanuel Bernard
 */
public class LoadClass implements PrivilegedAction> {
	private final String className;
	private final Class caller;

	public static LoadClass action(String className, Class caller) {
		return new LoadClass( className, caller );
	}

	private LoadClass(String className, Class caller) {
		this.className = className;
		this.caller = caller;
	}

	public Class run() {
		try {
			ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
			if ( contextClassLoader != null ) {
				return contextClassLoader.loadClass( className );
			}
		}
		catch ( Throwable e ) {
			// ignore
		}
		try {
			return Class.forName( className, true, caller.getClassLoader() );
		}
		catch ( ClassNotFoundException e ) {
			throw new ValidationException("Unable to load class: " + className, e);
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy