if (objectDescriptorStrategy.writeObjectSpecialCase(outputParent, cache, obj)) {
return;
}
ClassMetaData metaData = getMetaData(obj, cache);
if (objectDescriptorStrategy.writeDuplicateObject(outputParent, cache, obj, metaData)) {
return;
}
Object originalObject = obj;
Object newObject = obj;
do {
obj = newObject;
metaData = getMetaData(obj, cache);
newObject = objectDescriptorStrategy.replaceObjectByClass(cache, obj, metaData);
if (objectDescriptorStrategy.writeObjectSpecialCase(outputParent, cache, newObject)) {
return;
}
}
while (!objectDescriptorStrategy.doneReplacing(cache, newObject, obj, metaData));
obj = newObject;
metaData = getMetaData(obj, cache);
if (cache.getSubstitution() != null) {
Object orig = obj;
obj = cache.getSubstitution().replaceObject(obj);
if (obj != orig) {
if (objectDescriptorStrategy.writeObjectSpecialCase(outputParent, cache, obj)) {
return;
}
metaData = getMetaData(obj, cache);
}
}
int description = 0;
if (cache.getSafeToReuse() != null) {
description = cache.getSafeToReuse().storeSafe(obj);
if (description != 0) {
outputParent.writeByte(DataContainerConstants.SMARTCLONE_DEF);
cache.getOutput().addObjectReference(description);
return;
}
}
description = cache.findIdInCacheWrite(obj, metaData.isImmutable());
if (description != 0) // Shouldn't happen.
{
outputParent.writeByte(DataContainerConstants.OBJECTREF);
cache.getOutput().addObjectReference(description);
return;
} else {
ClassMetaData originalMetaData = metaData;
if (obj != originalObject) {
originalMetaData = getMetaData(originalObject, cache);
}
description = cache.putObjectInCacheWrite(originalObject, originalMetaData.isImmutable());
outputParent.writeByte(DataContainerConstants.NEWDEF);
cache.getOutput().addObjectReference(description);
cache.getClassDescriptorStrategy().writeClassDescription(obj, metaData, cache, description);
cache.getObjectDescriptorStrategy().writeObject(outputParent, cache, metaData, obj);