{
TraitsInfo ti = readTraits(ref);
String className = ti.getClassName();
boolean externalizable = ti.isExternalizable();
Object object;
PropertyProxy proxy = null;
// Check for any registered class aliases
String aliasedClass = ClassAliasRegistry.getRegistry().getClassName(className);
if (aliasedClass != null)
className = aliasedClass;
if (className == null || className.length() == 0)
{
object = new ASObject();
}
else if (className.startsWith(">")) // Handle [RemoteClass] (no server alias)
{
object = new ASObject();
((ASObject)object).setType(className);
}
else if (context.instantiateTypes || className.startsWith("flex."))
{
Class desiredClass = AbstractProxy.getClassFromClassName(className, context.createASObjectForMissingType);
proxy = PropertyProxyRegistry.getRegistry().getProxyAndRegister(desiredClass);
if (proxy == null)
object = ClassUtil.createDefaultInstance(desiredClass, null);
else
object = proxy.createInstance(className);
}
else
{
// Just return type info with an ASObject...
object = new ASObject();
((ASObject)object).setType(className);
}
if (proxy == null)
proxy = PropertyProxyRegistry.getProxyAndRegister(object);
// Remember our instance in the object table
int objectId = objectTable.size();
objectTable.add(object);
if (externalizable)
{
readExternalizable(className, object);
}
else
{
if (isDebug)
{
trace.startAMFObject(className, objectTable.size() - 1);
}
int len = ti.getProperties().size();
for (int i = 0; i < len; i++)
{
String propName = (String)ti.getProperty(i);
if (isDebug)
trace.namedElement(propName);
Object value = readObject();
proxy.setValue(object, propName, value);
}
if (ti.isDynamic())
{
for (; ;)
{
String name = readString();
if (name == null || name.length() == 0) break;
if (isDebug)
trace.namedElement(name);
Object value = readObject();
proxy.setValue(object, name, value);
}
}
}
if (isDebug)
trace.endAMFObject();
// This lets the BeanProxy substitute a new instance into the BeanProxy
// at the end of the serialization. You might for example create a Map, store up
// the properties, then construct the instance based on that. Note that this does
// not support recursive references to the parent object however.
Object newObj = proxy.instanceComplete(object);
// TODO: It is possible we gave out references to the
// temporary object. it would be possible to warn users about
// that problem by tracking if we read any references to this object
// in the readObject call above.