boolean needsIDs = false;
if (grandParent.getLocalName().equals("exceptionType")) {
// Only the first child of an exception type needs an ID
Node firstParam = getFirstChildWithName(grandParent, "parameter");
if (firstParam == null) {
throw new ValidationException(getName() + " - Node does not have any parameter children defined", node);
}
if (firstParam.equals(parent)) {
needsIDs = true;
}
}
// Ensure that all enumerations are of type string.
String type = getAttribute(getName(), parent, "type");
if (!type.equals("string")) {
throw new ValidationException(getName() + " - Valid values is not of base type string.", node);
}
// If it's a simpleType enumeration, it must start with an upper case letter
if (parent.getLocalName().equals("simpleType")) {
String name = getAttribute(getName(), parent, "name");
if (name == null || name.length() < 1) {
throw new ValidationException("Data types must have a name", node);
} else if (Character.isLowerCase(name.charAt(0))) {
throw new ValidationException("Simple type names must start with a capital letter", node);
}
}
Set<Integer> idsUsed = new HashSet<Integer>();
Set<String> namesUsed = new HashSet<String>();
List<Node> values = getChildrenWithName(getName(), node, "value");
if (values.size() == 0) {
throw new ValidationException(getName() + " - Valid values list does not have any children defined", node);
}
for (Node val : values) {
Integer id = getAttributeAsInt(getName(), val, "id");
if (needsIDs == (id == null)) {
if (needsIDs) {
throw new ValidationException(getName() + " - no ID defined for valid value", val);
} else {
throw new ValidationException(getName() + " - ID defined for valid value which does not require one", val);
}
}
if (id != null) {
if (idsUsed.contains(id)) {
throw new ValidationException(getName() + " - duplicate id: " + id, val);
}
idsUsed.add(id);
}
String vvName = getAttribute(getName(), val, "name");
if (vvName != null) {
if (vvName.length() < 1) {
throw new ValidationException("Valid values must have a name", node);
} else if (Character.isLowerCase(vvName.charAt(0))) {
throw new ValidationException("Valid value names must start with a capital letter", node);
}
if (namesUsed.contains(vvName)) {
throw new ValidationException(getName() + " - duplicate name: " + vvName, val);
}
namesUsed.add(vvName);
} else {
throw new ValidationException(getName() + " - no name defined for valid value", val);
}
}