Skip to content

Commit

Permalink
HV-461 Making ValidatorUtil class final and use a static bloc to init…
Browse files Browse the repository at this point in the history
…ialize validator.
  • Loading branch information
kevinpollet committed May 30, 2011
1 parent a170523 commit 518d7f0
Showing 1 changed file with 13 additions and 8 deletions.
Expand Up @@ -41,8 +41,15 @@
* @author Gunnar Morling
* @author Kevin Pollet - SERLI - (kevin.pollet@serli.com)
*/
public class ValidatorUtil {
private static Validator hibernateValidator;
public final class ValidatorUtil {
private final static Validator hibernateValidator;

// configure instance of validator for validation provider Hibernate Validator.
static {
final Configuration<HibernateValidatorConfiguration> configuration = getConfiguration();
configuration.traversableResolver( new DummyTraversableResolver() );
hibernateValidator = configuration.buildValidatorFactory().getValidator();
}

/**
* Private constructor in order to avoid instantiation.
Expand All @@ -57,11 +64,6 @@ private ValidatorUtil() {
* @return an instance of {@code Validator}.
*/
public static Validator getValidator() {
if ( hibernateValidator == null ) {
final Configuration<HibernateValidatorConfiguration> configuration = getConfiguration();
configuration.traversableResolver( new DummyTraversableResolver() );
hibernateValidator = configuration.buildValidatorFactory().getValidator();
}
return hibernateValidator;
}

Expand Down Expand Up @@ -194,7 +196,10 @@ public static MethodDescriptor getMethodDescriptor(Class<?> clazz, String method
*/
public static ParameterDescriptor getParameterDescriptor(Class<?> clazz, String methodName, Class<?>[] parameterTypes, int parameterIndex) {
final MethodDescriptor methodDescriptor = getMethodDescriptor( clazz, methodName, parameterTypes );
assertNotNull( methodDescriptor );
assertNotNull(
methodDescriptor,
"No method with the given signature is declared in " + clazz + " or its super class"
);
return methodDescriptor.getParameterConstraints().get( parameterIndex );
}

Expand Down

0 comments on commit 518d7f0

Please sign in to comment.