use of org.motechproject.mds.domain.ComboboxHolder in project motech by motech.
the class MDSConstructorImpl method buildEnum.
private void buildEnum(JavassistLoader loader, MdsJDOEnhancer enhancer, EntityDto entity, SchemaHolder schemaHolder) {
for (FieldDto field : schemaHolder.getFields(entity.getClassName())) {
TypeDto type = field.getType();
if (!type.isCombobox()) {
continue;
}
ComboboxHolder holder = new ComboboxHolder(entity, field);
if (holder.isEnum() || holder.isEnumCollection()) {
if (field.isReadOnly()) {
String enumName = holder.getEnumName();
Class<?> definition = loadClass(entity, enumName);
if (null != definition) {
MotechClassPool.registerEnum(enumName);
CtClass ctClass = MotechClassPool.getDefault().getOrNull(enumName);
if (null != ctClass) {
try {
ctClass.defrost();
byte[] bytecode = ctClass.toBytecode();
ClassData data = new ClassData(enumName, bytecode);
// register with the classloader so that we avoid issues with the persistence manager
MDSClassLoader.getInstance().safeDefineClass(data.getClassName(), data.getBytecode());
addClassData(loader, enhancer, data);
} catch (IOException | CannotCompileException e) {
LOGGER.error("Could not load enum: {}", enumName);
}
}
}
} else {
buildEnum(loader, enhancer, holder);
}
}
}
}
Aggregations