class ConsistentReferenceNameValidator implements ConstraintValidator<ConsistentReferenceName, ReferenceElement>,
        ValidationErrorDescriptorBuilder {

    @Override
    public ErrorDescriptor build(ConstraintViolation violation) {
        final ReferenceElement invalidValue = (ReferenceElement) violation.getInvalidValue();
        String expectedName = getReferencedResourceName(invalidValue.getReferencePath());
        return new ErrorDescriptor().setErrorCode("domain.schema.resources.join.reference.name.inconsistent")
                .setMessage("Reference name should be the same as name of referenced resource. I.e. \"" + expectedName +
                        "\"").addProperties(
                        new ClientProperty("expectedName", expectedName),
                        new ClientProperty("currentName", invalidValue.getName())
                );
    }

}