PropertyInfo[] fromPropertiesInfo = JClassUtils.extractBeanPropertiesInfo(fromType);
PropertyInfo[] toPropertiesInfo = JClassUtils.extractBeanPropertiesInfo(toType);
for (PropertyInfo fromPropertyInfo : fromPropertiesInfo)
{
PropertyInfo toPropertyInfo = getEquivalentPropertyInfo(fromPropertyInfo, toPropertiesInfo);
if (toPropertyInfo != null)
{
if (JClassUtils.isSimpleType(fromPropertyInfo.getType()))
{
if (fromPropertyInfo.getType().equals(toPropertyInfo.getType()))
{
srcWriter.println(toVariable+"."+toPropertyInfo.getWriteMethod().getName()+"("+fromVariable+"."+fromPropertyInfo.getReadMethod().getName()+"());");
}
else
{
throw new CruxGeneratorException("Can not create a BeanCopier. Incopatibles type for property ["+fromPropertyInfo.getName()+"].");
}
}
else
{
JClassType fromPropClass = fromPropertyInfo.getType().isClassOrInterface();
JClassType toPropClass = toPropertyInfo.getType().isClassOrInterface();
if (fromPropClass.isAssignableTo(toPropClass))
{
srcWriter.println(toVariable+"."+toPropertyInfo.getWriteMethod().getName()+"("+fromVariable+"."+fromPropertyInfo.getReadMethod().getName()+"());");
}
else
{
srcWriter.println("if ("+fromVariable+"."+fromPropertyInfo.getReadMethod().getName()+"() != null){");
srcWriter.println(toVariable+"."+toPropertyInfo.getWriteMethod().getName()+"(GWT.create("+toPropClass.getQualifiedSourceName()+".class));");
generateCopyBeanCode(srcWriter, fromVariable+"."+fromPropertyInfo.getReadMethod().getName()+"()",
toVariable+"."+toPropertyInfo.getReadMethod().getName()+"()",
fromPropertyInfo.getType().isClassOrInterface(),
toPropertyInfo.getType().isClassOrInterface());
srcWriter.println("}else{");
srcWriter.println(toVariable+"."+toPropertyInfo.getWriteMethod().getName()+"(null);");
srcWriter.println("}");
}
}
}
}