}
if (addListeners)
{
lockForListeners = LockManager.getInstance().getLockHeld(
new Identity(obj, _pb), _tx);
}
fields[0] = obj.getClass(); // we must notice if the object class changes
count++;
for (int i = 0; i < fieldDescs.length; i++)
{
FieldDescriptor fd = fieldDescs[i];
PersistentField f = fd.getPersistentField();
fields[count] = f.get(obj);
count++;
}
int countRefs = 0;
for (Iterator it = refDescs.iterator(); it.hasNext(); count++, countRefs++)
{
ObjectReferenceDescriptor rds = (ObjectReferenceDescriptor) it.next();
PersistentField f = rds.getPersistentField();
Object relObj = f.get(obj);
if (relObj != null)
{
fields[count] = new Identity(relObj, _pb);
if (withObjects)
{
references[countRefs] = relObj;
}
}
}
count = 0;
for (Iterator it = colDescs.iterator(); it.hasNext(); count++)
{
CollectionDescriptor cds = (CollectionDescriptor) it.next();
PersistentField f = cds.getPersistentField();
Class type = f.getType();
Object col = f.get(obj);
if ((col != null) && (col instanceof CollectionProxyDefaultImpl)
&& !((CollectionProxyDefaultImpl) col).isLoaded())
{
if (addListeners)
{
OTMCollectionProxyListener listener =
new OTMCollectionProxyListener(cds, collections,
count, lockForListeners);
((CollectionProxyDefaultImpl) col).addListener(listener);
if (_colProxyListeners == null)
{
_colProxyListeners = new HashMap();
}
_colProxyListeners.put(listener, col);
}
continue;
}
if (col != null)
{
ArrayList list = new ArrayList();
ArrayList listOfObjects = null;
Iterator colIterator;
collections[count] = list;
if (withObjects)
{
listOfObjects = new ArrayList();
collectionsOfObjects[count] = listOfObjects;
}
if (Collection.class.isAssignableFrom(type))
{
colIterator = ((Collection) col).iterator();
}
else if (type.isArray())
{
colIterator = new ArrayIterator(col);
}
else
{
continue;
}
while (colIterator.hasNext())
{
Object relObj = colIterator.next();
list.add(new Identity(relObj, _pb));
if (withObjects)
{
listOfObjects.add(relObj);
}
}