for (JavaModel javaModel : map.values()) {
Map<String, JavaExceptionClass> exceptionClasses = javaModel
.getExceptionClasses();
for (String expClassName : exceptionClasses.keySet()) {
JavaExceptionClass expClz =
exceptionClasses.get(expClassName);
clearAttributes();
if (penv.containsKey(ToolConstants.CFG_FAULT_SERIAL_VERSION_UID)) {
String faultSerialVersionUID
= penv.get(ToolConstants.CFG_FAULT_SERIAL_VERSION_UID).toString();
setAttributes("faultSerialVersionUID", faultSerialVersionUID);
if ("FQCN".equalsIgnoreCase(faultSerialVersionUID)) {
setAttributes("suid", generateHashSUID(expClz.getFullClassName()));
} else if ("TIMESTAMP".equalsIgnoreCase(faultSerialVersionUID)) {
setAttributes("suid", generateTimestampSUID());
} else if ("NONE".equalsIgnoreCase(faultSerialVersionUID)) {
//nothing
setAttributes("suid", "");
} else {
//do a quick Parse to make sure it looks like a Long
try {
Long.parseLong(faultSerialVersionUID);
} catch (NumberFormatException nfe) {
throw new ToolException(nfe);
}
setAttributes("suid", faultSerialVersionUID);
}
} else {
setAttributes("suid", "");
}
setAttributes("expClass", expClz);
String exceptionSuperclass;
if (penv.containsKey(ToolConstants.CFG_EXCEPTION_SUPER)) {
exceptionSuperclass = penv.get(ToolConstants.CFG_EXCEPTION_SUPER).toString();
} else {
exceptionSuperclass = "java.lang.Exception";
}
String simpleName = exceptionSuperclass.indexOf('.') == -1 ? exceptionSuperclass
: exceptionSuperclass.substring(exceptionSuperclass.lastIndexOf('.') + 1);
String exceptionSuperclassString = simpleName;
for (JavaField jf : expClz.getFields()) {
String jfClassName = jf.getClassName();
if (jfClassName.substring(jfClassName.lastIndexOf(".") + 1)
.equals(simpleName)) {
exceptionSuperclassString = exceptionSuperclass;
}
setAttributes("paraName", ProcessorUtil.mangleNameToVariableName(jf.getName()));
}
ClassCollector collector = penv.get(ClassCollector.class);
for (String pkg : collector.getTypesPackages()) {
if (collector.containTypesClass(pkg, simpleName)) {
exceptionSuperclassString = exceptionSuperclass;
}
}
if (expClz.getName().equals(exceptionSuperclassString)) {
exceptionSuperclassString = exceptionSuperclass;
}
setAttributes("exceptionSuperclass", exceptionSuperclassString);
setCommonAttributes();
doWrite(FAULT_TEMPLATE, parseOutputName(expClz.getPackageName(),
expClz.getName()));
}
}
}