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

org.hibernate.validator.internal.util.privilegedactions.GetClassLoader Maven / Gradle / Ivy

Go to download

JSR 380's RI, Hibernate Validator version ${hibernate-validator.version} and its dependencies repackaged as OSGi bundle

There is a newer version: 5.1.0
Show newest version
/*
 * Hibernate Validator, declare and validate application constraints
 *
 * License: Apache License, Version 2.0
 * See the license.txt file in the root directory or .
 */
package org.hibernate.validator.internal.util.privilegedactions;

import java.security.PrivilegedAction;

import org.hibernate.validator.internal.util.Contracts;

import static org.hibernate.validator.internal.util.logging.Messages.MESSAGES;

/**
 * @author Emmanuel Bernard
 */
public final class GetClassLoader implements PrivilegedAction {
	private final Class clazz;

	public static GetClassLoader fromContext() {
		return new GetClassLoader( null );
	}

	public static GetClassLoader fromClass(Class clazz) {
		Contracts.assertNotNull( clazz, MESSAGES.classIsNull() );
		return new GetClassLoader( clazz );
	}

	private GetClassLoader(Class clazz) {
		this.clazz = clazz;
	}

	@Override
	public ClassLoader run() {
		if ( clazz != null ) {
			return clazz.getClassLoader();
		}
		else {
			return Thread.currentThread().getContextClassLoader();
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy