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

com.aeontronix.commons.validation.IsClassValidator Maven / Gradle / Ivy

The newest version!
/*
 * Copyright (c) 2014 Kloudtek Ltd
 */

package com.aeontronix.commons.validation;

import com.aeontronix.commons.validation.annotation.IsClass;
import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;

public class IsClassValidator implements ConstraintValidator {
    private Class isClass;

    public void initialize(IsClass isClass) {
        this.isClass = isClass.value();
    }

    public boolean isValid(Object object, ConstraintValidatorContext constraintContext) {
        if (object == null) {
            return true;
        }
        if (!object.getClass().getName().equals(isClass.getName())) {
            constraintContext.disableDefaultConstraintViolation();
            constraintContext.buildConstraintViolationWithTemplate("{com.aeontronix.common.validation.isclass}")
                    .addConstraintViolation();
            return false;
        }
        return true;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy