use of org.motechproject.mds.domain.Relationship in project motech by motech.
the class EntityBuilderImpl method createField.
private CtField createField(CtClass declaring, EntityDto entity, FieldDto field, EntityType entityType) throws IllegalAccessException, InstantiationException, CannotCompileException, ClassNotFoundException {
TypeDto fieldType = field.getType();
String genericSignature = null;
CtClass type = null;
if (fieldType.isCombobox()) {
ComboboxHolder holder = new ComboboxHolder(entity, field);
if (holder.isEnum() || holder.isEnumCollection()) {
type = classPool.getOrNull(holder.getEnumName());
if (holder.isEnumCollection()) {
genericSignature = JavassistUtil.genericSignature(holder.getTypeClassName(), holder.getEnumName());
type = classPool.getOrNull(holder.getTypeClassName());
}
} else if (holder.isStringCollection()) {
genericSignature = JavassistUtil.genericSignature(holder.getTypeClassName(), holder.getUnderlyingType());
type = classPool.getOrNull(holder.getTypeClassName());
} else if (holder.isString()) {
type = classPool.getOrNull(holder.getUnderlyingType());
}
} else if (fieldType.isRelationship()) {
Class fieldClass = getClass().getClassLoader().loadClass(fieldType.getTypeClass());
Relationship relationshipType = (Relationship) fieldClass.newInstance();
genericSignature = relationshipType.getGenericSignature(field, entityType);
type = classPool.getOrNull(relationshipType.getFieldType(field, entityType));
} else {
type = classPool.getOrNull(fieldType.getTypeClass());
}
return JavassistBuilder.createField(declaring, type, field.getBasic().getName(), genericSignature);
}
Aggregations