* @param source The transformation source.
* @param value The value to assign.
*/
protected void setDestination(TransformationMapping mapping, TransformationSource source, Object value)
{
TransferObject tobj = m_output;
int nList = -1;
value = convert(value, source, mapping);
for (int i = 0, n = mapping.getDestinationCount() - 1; i <= n; ++i)
{
EndpointPart destinationPart = mapping.getDestination(i);
String sDestinationName = destinationPart.getName();
if (destinationPart.isCollection())
{
List list = (List)tobj.findValue(sDestinationName);
if (list == null)
{
list = new ArrayList(4);
destinationPart.setValue(tobj, list);
}
if (destinationPart.isPrimitive())
{
if (value instanceof List)
{
list.addAll((List)value);
}
else
{
list.add(value);
}
}
else if (mapping.isFixedDestination(i))
{
if (list.isEmpty())
{
tobj = destinationPart.createObject();
list.add(tobj);
}
else
{
tobj = (TransferObject)list.get(0);
}
}
else if (i == n && value instanceof List)
{
list.addAll((List)value);
}
else
{
int nLastCollection = mapping.getLastCollectionDestinationOrdinal();
int nParentLevel = (mapping.getCollectionParent() == null) ? 0 : mapping.getCollectionParent().getLevel();
boolean bListKey = false;
tobj = null;
while (++nList <= source.getLevel())
{
TransformationSource path = source.getPath(nList);
if (!mapping.isFixedSource(path))
{
EndpointPart sourcePart = path.getPart();
if (sourcePart.isCollection())
{
if (m_listKey == null)
{
m_listKey = new ListKey();
}
if (i == nLastCollection)
{
nList = nParentLevel;
}
m_listKey.set(list, getSourceList(nList), getSourceIndex(nList), sourcePart);
tobj = (TransferObject)m_listMap.get(m_listKey);
bListKey = true;
break;
}
else if (i == nLastCollection && nList > nParentLevel)
{
Object sourceObject = getSourceObject(nList);
if (sourcePart.isPrimitive() ||
sourceObject == null ||
sourceObject == Undefined.VALUE)
{
sourceObject = getSourceObject(nList - 1);
}
if (m_listKey == null)
{
m_listKey = new ListKey();
}
m_listKey.set(list, sourceObject, 0, sourcePart);
tobj = (TransferObject)m_listMap.get(m_listKey);
bListKey = true;
break;
}
}
}
if (tobj == null)
{
if (i == n)
{
tobj = (TransferObject)value;
list.add(tobj);
}
else
{
tobj = destinationPart.createObject();
list.add(tobj);
}
if (bListKey)
{
m_listMap.put(m_listKey, tobj);
m_listKey = null;
}
}
}
}
else
{
if (i == n)
{
destinationPart.setValue(tobj, value);
}
else
{
TransferObject obj = (TransferObject)tobj.findValue(sDestinationName);
if (obj == null)
{
obj = destinationPart.createObject();
destinationPart.setValue(tobj, obj);