class RegistrationValidator implements Validator {

    @Override
    public void validate(Object target, Errors errors) {
        if (target == null) {
            return;
        }

        Player player = (Player) target;

        String name = player.getReadableName();

        if (!validateNicknameStructure(name)) {
            errors.rejectValue("readableName", "registration.nickname.invalid", new Object[]{ name }, null);
        }

        if (!checkNameUniqueness(name)) {
            errors.rejectValue("readableName", "registration.nickname.alreadyUsed", new Object[]{ name }, null);
        }

        String email = player.getEmail();
        if (!validateEmailStructure(email)) {
            errors.rejectValue("email", "registration.email.invalid", new Object[]{ email }, null);
        }

        if (!checkEmailUniqueness(email)) {
            errors.rejectValue("email", "registration.email.alreadyUsed");
        }

        String password = player.getPassword();

        if (!checkPasswordNotEmpty(password)) {
            errors.rejectValue("password", "registration.password.empty");
        }

        if (!checkPasswordLength(password)) {
            errors.rejectValue("password", "registration.password.length", new Object[] { minPasswordLen }, null);
        }

        if (!checkPasswordConfirmation(password, player.getPasswordConfirmation())) {
            errors.rejectValue("passwordConfirmation", "registration.password.invalidConfirmation");
        }

        String gameName = rooms.getGameName(player.getGameName());
        if (!validator.isGameName(gameName, CANT_BE_NULL)) {
            errors.rejectValue("gameName", "registration.game.invalid", new Object[]{ gameName }, null);
        }
    }

}