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

org.hibernate.validation.util.NewInstance 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 NewInstance implements PrivilegedAction {
	private final Class clazz;
	private final String message;

	public static  NewInstance action(Class clazz, String message) {
		return new NewInstance( clazz, message );
	}

	private NewInstance(Class clazz, String message) {
		this.clazz = clazz;
		this.message = message;
	}

	public T run() {
		try {
			return clazz.newInstance();
		}
		catch ( InstantiationException e ) {
			throw new ValidationException( "Unable to instanciate " + message + ": " + clazz, e );
		}
		catch ( IllegalAccessException e ) {
			throw new ValidationException( "Unable to instanciate " + clazz, e );
		}
		catch ( RuntimeException e ) {
			throw new ValidationException( "Unable to instanciate " + clazz, e );
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy