{
Object targetEcObj = null;
if (sourceEcObj != null
&& PersistenceType.BASIC.equals(embeddedColumn.getPersistenceType()))
{
PropertyAccessor accessor = PropertyAccessorFactory
.getPropertyAccessor(sourceEcObj.getClass());
if (accessor != null)
{
targetEcObj = accessor.getCopy(sourceEcObj);
}
}
else if (sourceEcObj != null
&& PersistenceType.EMBEDDABLE.equals(embeddedColumn
.getPersistenceType()))
{
targetEcObj = genericClass.newInstance();
for (Field f : genericClass.getDeclaredFields())
{
if (f != null && !Modifier.isStatic(f.getModifiers()))
{
PropertyAccessorHelper.set(targetEcObj, f,
PropertyAccessorHelper.getObjectCopy(sourceEcObj, f));
}
}
}
if (List.class.isAssignableFrom(ecDeclaredClass))
{
Method m = actualEcObjectClass.getMethod("add", Object.class);
m.invoke(targetCollectionObject, targetEcObj);
}
else if (Set.class.isAssignableFrom(ecDeclaredClass))
{
Method m = actualEcObjectClass.getMethod("add", Object.class);
m.invoke(targetCollectionObject, targetEcObj);
}
}
}
// Copy element collection for Map
else if (sourceEmbeddedObj instanceof Map)
{
for (Object sourceKey : ((Map) sourceEmbeddedObj).keySet())
{
Object targetKey = null;
Object targetValue = null;
if (PersistenceType.BASIC.equals(embeddedColumn.getPersistenceType()))
{
// Create copy of map key
if (sourceKey != null)
{
PropertyAccessor keyAccessor = PropertyAccessorFactory
.getPropertyAccessor(sourceKey.getClass());
if (keyAccessor != null)
{
targetKey = keyAccessor.getCopy(sourceKey);
}
}
else
{
targetKey = null;
}
// Create copy of map value
Object sourceValue = ((Map) sourceEmbeddedObj).get(sourceKey);
if (sourceValue != null)
{
PropertyAccessor valueAccessor = PropertyAccessorFactory
.getPropertyAccessor(sourceValue.getClass());
if (valueAccessor != null)
{
targetValue = valueAccessor.getCopy(sourceValue);
}
}
else
{
targetValue = null;