*/
public class ReferenceAwareTypedObjectDecoder extends TypedObjectDecoder
{
protected Object decodeTypedObject(Object bean, Object encodedObject)
{
TypeMarshallingContext context = TypeMarshallingContext.getTypeMarshallingContext();
context.getKnownObjects().put(encodedObject, bean);
PropertyProxy beanProxy = PropertyProxyRegistry.getProxy(bean);
PropertyProxy encodedProxy = PropertyProxyRegistry.getProxy(encodedObject);
List propertyNames = beanProxy.getPropertyNames(bean);
if (propertyNames != null)
{
Iterator it = propertyNames.iterator();
while (it.hasNext())
{
String propName = (String)it.next();
Class wClass = beanProxy.getType(bean, propName);
// get property value from encodedObject
Object value = encodedProxy.getValue(encodedObject, propName);
Object decodedObject = null;
try
{
if (value != null)
{
//Check whether we need to restore a client
//side reference to a known object
Object ref = null;
if (canUseByReference(value))
ref = context.getKnownObjects().get(value);
if (ref == null)
{
ActionScriptDecoder decoder = DecoderFactory.getReferenceAwareDecoder(value, wClass);
decodedObject = decoder.decodeObject(value, wClass);
if (canUseByReference(decodedObject))
{
context.getKnownObjects().put(value, decodedObject);
}
}
else
{
decodedObject = ref;