class UserValidator implements EntityValidator<User> {

    @Override
    public Set<ConstraintViolation<User>> validate(final User entity) {
        if (entity == null) {
            return null;
        }
        final String id = entity.getIdentifier();
        Set<ConstraintViolation<User>> result = new HashSet<ConstraintViolation<User>>(1);
        // Validate user name not empty.
        if (id == null || id.trim().length() == 0) {
            final String msg = getMessage(KEY_NAME_NOT_EMPTY);
            result.add(createViolation(entity,
                                       "identifier",
                                       msg));
        }
        return result;
    }

}