in core/src/main/java/flex/messaging/io/amfx/AmfxInput.java [910:1048]
private Object setValue(Object value) {
if (objectStack.empty()) {
if (currentHeader != null)
currentHeader.setData(value);
else if (currentBody != null)
currentBody.setData(value);
else
throw new MessageException("Unexpected value: " + value);
return value;
}
// ActionScript Data
Object obj = objectStackPeek();
// <object type="..."> <traits externalizable="true">
if (obj instanceof Externalizable) {
if (value != null && value.getClass().isArray() && Byte.TYPE.equals(value.getClass().getComponentType())) {
Externalizable extern = (Externalizable) obj;
Amf3Input objIn = new Amf3Input(context);
byte[] ba = (byte[]) value;
ByteArrayInputStream baIn = new ByteArrayInputStream(ba);
try {
//objIn.setDebugTrace(trace);
objIn.setInputStream(baIn);
extern.readExternal(objIn);
} catch (ClassNotFoundException ex) {
throw new MessageException("Error while reading Externalizable class " + extern.getClass().getName(), ex);
} catch (IOException ex) {
throw new MessageException("Error while reading Externalizable class " + extern.getClass().getName(), ex);
} finally {
try {
objIn.close();
} catch (IOException ex) {
}
}
} else {
throw new MessageException("Error while reading Externalizable class. Value must be a byte array.");
}
}
// <object>
else if (obj instanceof ASObject) {
String prop;
TraitsContext traitsContext = (TraitsContext) traitsStack.peek();
try {
prop = traitsContext.next();
} catch (IndexOutOfBoundsException ex) {
throw new MessageException("Object has no trait info for value: " + value);
}
ASObject aso = (ASObject) obj;
ClassUtil.validateAssignment(aso, prop, value);
aso.put(prop, value);
if (isDebug)
trace.namedElement(prop);
}
// <array ecma="false"> in ArrayList form
else if (obj instanceof ArrayList && !(obj instanceof ArrayCollection)) {
ArrayList list = (ArrayList) obj;
ClassUtil.validateAssignment(list, list.size(), value);
list.add(value);
if (isDebug)
trace.arrayElement(list.size() - 1);
}
// <array ecma="false"> in Object[] form
else if (obj.getClass().isArray()) {
if (!strictArrayIndexStack.empty()) {
int[] indexObj = (int[]) strictArrayIndexStack.peek();
int index = indexObj[0];
if (Array.getLength(obj) > index) {
ClassUtil.validateAssignment(obj, index, value);
Array.set(obj, index, value);
} else {
throw new MessageException("Index out of bounds at: " + index + " cannot set array value: " + value + "");
}
indexObj[0]++;
}
} else if (obj instanceof Map) {
if (obj instanceof Dictionary) // <dictionary>
{
Dictionary dict = (Dictionary) obj;
if (!dictionaryStack.empty()) {
Object key = dictionaryStack.pop();
if (isDebug) trace.addDictionaryEquals();
ClassUtil.validateAssignment(dict, key.toString(), value);
dict.put(key, value);
} else {
if (isDebug) trace.startDictionaryElement();
dictionaryStack.push(value);
}
return value;
}
Map map = (Map) obj; // <array ecma="true">
// <item name="prop">
if (!arrayPropertyStack.empty()) {
String prop = (String) arrayPropertyStack.peek();
ClassUtil.validateAssignment(map, prop, value);
map.put(prop, value);
if (isDebug)
trace.namedElement(prop);
return value;
}
// Mixed content, auto-generate string for ECMA Array index
if (!ecmaArrayIndexStack.empty()) {
int[] index = (int[]) ecmaArrayIndexStack.peek();
String prop = String.valueOf(index[0]);
index[0]++;
ClassUtil.validateAssignment(map, prop, value);
map.put(prop, value);
if (isDebug)
trace.namedElement(prop);
}
}
// <object type="...">
else {
value = setObjectValue(obj, value);
}
return value;
}