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)
{
if (isDebug)
{
log.debug("describeObject::checking substitution on interface");
}
Object orig = obj;
obj = cache.getSubstitution().replaceObject(obj);
if (obj!=orig)
{
if (isDebug)
{
log.debug("describeObject::on check interface, original object[" + orig.getClass().getName() +"] was replaced by [" + obj.getClass().getName() + "]");
}
if (objectDescriptorStrategy.writeObjectSpecialCase(outputParent, cache, obj))
{
return;
}
metaData = getMetaData(obj, cache);
}
}
if (isDebug)
{
if (obj==null)
{
log.debug("obj==null",new Exception());
}
}
if (isDebug)
{
log.debug("describeObject for class=" + obj.getClass().getName());
}
int description = 0;
if (cache.getSafeToReuse()!=null)
{
description = cache.getSafeToReuse().storeSafe(obj);
if (description!=0)
{
if (isDebug)
{
log.debug("describeObject::a safeClone reference " + description);
}
outputParent.writeByte(DataContainerConstants.SMARTCLONE_DEF);
cache.getOutput().addObjectReference(description);
return;
}
}
description = cache.findIdInCacheWrite(obj, metaData.isImmutable());
if (description != 0) // Shouldn't happen.
{
if (isDebug)
{
log.debug("describeObject::a circular reference " + description);
}
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());
if (isDebug)
{
log.debug("describeObject::a new reference " + description);
}
outputParent.writeByte(DataContainerConstants.NEWDEF);