// definitions is empty.
// * Choice name must be equal to the name of one of the choice
// definitions.
// * Choice value must pass verification of its choice definition
// type.
final ChoiceValue choiceValue = (ChoiceValue) value;
final String choiceName = choiceValue.getChoiceName();
if (choiceName == null) {
if (!choiceDefinitions.isEmpty()) {
errors.add(new VerificationError(
VerificationError.CHOICE_NAME_NULL,
path,
value,
null,
"Null choice name."));
}
} else {
final ChoiceDefinition choiceDefinition =
getChoiceDefinition(choiceName);
if (choiceDefinition == null) {
// No choice definition for selected choice name is an error.
errors.add(new VerificationError(
VerificationError.TYPE_UNEXPECTED_VALUE,
path,
value,
null,
"Choice '" + choiceName + "' is not expected here."));
} else {
// Verify choice value against its type.
Collection valueErrors =
choiceDefinition.getType().verify(choiceValue.getValue());
errors.addAll(valueErrors);
}
}
}