Search in sources :

Example 1 with Relationship

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);
}
Also used : CtClass(javassist.CtClass) ComboboxHolder(org.motechproject.mds.domain.ComboboxHolder) Relationship(org.motechproject.mds.domain.Relationship) TypeDto(org.motechproject.mds.dto.TypeDto) CtClass(javassist.CtClass)

Aggregations

CtClass (javassist.CtClass)1 ComboboxHolder (org.motechproject.mds.domain.ComboboxHolder)1 Relationship (org.motechproject.mds.domain.Relationship)1 TypeDto (org.motechproject.mds.dto.TypeDto)1