org.hibernate.validator.internal.engine.constraintvalidation.ConstraintValidatorFactoryImpl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of bean-validator Show documentation
Show all versions of bean-validator Show documentation
JSR 380's RI, Hibernate Validator version ${hibernate-validator.version} and its dependencies repackaged as OSGi bundle
/*
* 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.engine.constraintvalidation;
import java.security.AccessController;
import java.security.PrivilegedAction;
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorFactory;
import org.hibernate.validator.internal.util.privilegedactions.NewInstance;
/**
* Default {@code ConstraintValidatorFactory} using a no-arg constructor.
*
* @author Emmanuel Bernard
* @author Hardy Ferentschik
*/
//TODO Can we make the constructor non-public?
public class ConstraintValidatorFactoryImpl implements ConstraintValidatorFactory {
@Override
public final > T getInstance(Class key) {
return run( NewInstance.action( key, "ConstraintValidator" ) );
}
@Override
public void releaseInstance(ConstraintValidator instance) {
// noop
}
/**
* Runs the given privileged action, using a privileged block if required.
*
* NOTE: This must never be changed into a publicly available method to avoid execution of arbitrary
* privileged actions within HV's protection domain.
*/
private T run(PrivilegedAction action) {
return System.getSecurityManager() != null ? AccessController.doPrivileged( action ) : action.run();
}
}