final boolean isListEntity = !isMapEntity && List.class.isAssignableFrom(entityClass);
final PropertyDescriptor dtoFieldDesc = PropertyInspector.getDtoPropertyDescriptorForField(
dtoClass, meta.getDtoFieldName(), dtoPropertyDescriptors);
final MethodSynthesizer synthesizer = context.getMethodSynthesizer();
final MethodSynthesizer entitySynthesizer;
final PropertyDescriptor entityFieldDesc;
if (isMapEntity || isListEntity) {
if (isMapEntity) {
entitySynthesizer = mapSynthesizer;
} else {
entitySynthesizer = listSynthesizer;
}
entityFieldDesc = dtoFieldDesc;
} else {
entitySynthesizer = synthesizer;
entityFieldDesc = PropertyInspector.getEntityPropertyDescriptorForField(
dtoClass, entityClass, meta.getDtoFieldName(), meta.getEntityFieldName(), entityPropertyDescriptors);
}
final DataReader dtoParentReadMethod;
if (meta.isChild()) {
final Method parentGet = dtoFieldDesc.getReadMethod();
Class returnTypeClass;
try {
returnTypeClass = PropertyInspector.getClassForType(parentGet.getGenericReturnType());
} catch (GeDARuntimeException gre) {
throw new GeDARuntimeException(
"Generics tree is too complex only rawTypes are supported class: " + dtoClass.getSimpleName()
+ ", method: " + parentGet.getName(), gre);
}
final PropertyDescriptor[] dtoSubPropertyDescriptors = PropertyInspector.getPropertyDescriptorsForClass(returnTypeClass);
final PropertyDescriptor dtoParentDesc = PropertyInspector.getDtoPropertyDescriptorForField(
dtoClass, meta.getParentEntityPrimaryKeyField(), dtoSubPropertyDescriptors);
dtoParentReadMethod = context.getMethodSynthesizer().synthesizeReader(dtoParentDesc);
} else {
dtoParentReadMethod = null;
}
return new DataPipe(context,
meta.isReadOnly() ? null : synthesizer.synthesizeReader(dtoFieldDesc),
synthesizer.synthesizeWriter(dtoFieldDesc),
dtoParentReadMethod,
entitySynthesizer.synthesizeReader(entityFieldDesc),
meta.isReadOnly() ? null : entitySynthesizer.synthesizeWriter(entityFieldDesc),
meta
);
}