@Override
public void validate(Node node) throws ValidationException {
String name = getAttribute(getName(), node, "name");
if (name == null || name.length() < 1) {
throw new ValidationException("exceptions must have a name", node);
} else if (Character.isLowerCase(name.charAt(0))) {
throw new ValidationException("exceptions must start with a capital letter", node);
} else if (exceptionNames.contains(name)) {
throw new ValidationException("The exception " + name + " is already defined", node);
}
exceptionNames.add(name);
// Ensure there is at least one parameter, and it's an enum.
Node firstParam = getFirstChildWithName (node, "parameter");
// Ensure that the parameter has valid values
getFirstChildWithName(firstParam, "validValues");
//Check that all params in the exception type are firstly
List<Node> parameters = getChildrenWithName(getName(), node, "parameter");
for (Node param : parameters) {
String paramName = getAttribute(getName(), param, "name");
String paramType = getAttribute(getName(), param, "type");
checkTypeIsSimple( paramName, param, paramType, false);
//We simply don't permit this dude in exceptions
if (paramType.toLowerCase().equals("datetime")) {
throw new ValidationException("Datetime arguments [" + paramName + "] are not permitted as exception parameters", param);
}
if (paramName.equals("message") || paramName.equals("Message")) {
throw new ValidationException("Exceptions can't have a parameter named [message]", param);
}
if (paramName.equals("localizedMessage") || paramName.equals("LocalizedMessage")) {
throw new ValidationException("Exceptions can't have a parameter named [localizedMessage]", param);
}
if (paramName.equals("cause") || paramName.equals("Cause")) {
throw new ValidationException("Exceptions can't have a parameter named [cause]", param);
}
if (paramName.equals("stackTrace") || paramName.equals("StackTrace")) {
throw new ValidationException("Exceptions can't have a parameter named [stackTrace]", param);
}
if (paramName.equals("stackTraceDepth") || paramName.equals("StackTraceDepth")) {
throw new ValidationException("Exceptions can't have a parameter named [stackTraceDepth]", param);
}
if (paramName.equals("suppressed") || paramName.equals("Suppressed")) {
throw new ValidationException("Exceptions can't have a parameter named [suppressed]", param);
}
}
}