private static LocalizedString getDisplayNames(ModelObject nodeModel) {
ModelList list = get(nodeModel, ModelList.class, "displayNames");
if (!list.isDefined()) {
throw invalidValue(null, "displayNames");
}
LocalizedString displayName = null;
int i=0;
for (ModelValue mv : list) {
ModelObject displayNameModel = mv.asValue(ModelObject.class);
// Parse value (required && non-null)
if (!displayNameModel.has("value")) {
throw requiredField("displayNames["+i+"].value");
}
String value = get(displayNameModel, ModelString.class, "value").getValue();
if (value == null) {
throw invalidValue(value, "displayNames[" + i + "].value");
}
// Parse lang (not-required but if defined must be non-null)
if (displayNameModel.has("lang")) {
ModelString langModel = get(displayNameModel, ModelString.class, "lang");
String lang = langModel.getValue();
if (lang == null) {
throw invalidValue(lang, "displayNames[" + i + "].lang");
}
Locale locale = getLocale(displayNameModel, "lang");
if (displayName == null) {
displayName = new LocalizedString(locale, value);
} else {
displayName.setLocalizedValue(locale, value);
}
} else if (displayName == null) {
displayName = new LocalizedString(value);
} else {
throw invalidData("Cannot have multiple non localized values for displayNames");
}
}