[Red5commits] [1874] fixed AMF3 deserializer for references from attributes to parent classes (Jira A

jbauch luke at codegent.com
Mon Apr 16 17:10:18 EDT 2007


fixed AMF3 deserializer for references from attributes to parent classes (Jira APPSERVER-101)


Timestamp: 04/16/07 16:08:16 EST (less than one hour ago) 
Change: 1874 
Author: jbauch

Files (see diff or trac for details): 
doc/trunk/changelog.txt
java/server/trunk/src/org/red5/io/amf3/Input.java


Trac: http://mirror1.cvsdude.com/trac/osflash/red5/changeset/1874

Index: /java/server/trunk/src/org/red5/io/amf3/Input.java
===================================================================
--- /java/server/trunk/src/org/red5/io/amf3/Input.java (revision 1794)
+++ /java/server/trunk/src/org/red5/io/amf3/Input.java (revision 1874)
@@ -67,4 +67,44 @@
 	 */
 	protected class PendingObject {
+		
+		class PendingProperty {
+			Object obj;
+			Class klass;
+			String name;
+			
+			PendingProperty(Object obj, Class klass, String name) {
+				this.obj = obj;
+				this.klass = klass;
+				this.name = name;
+			}
+		}
+		
+		private List<PendingProperty> properties;
+		
+		public void addPendingProperty(Object obj, Class klass, String name) {
+			if (properties == null) {
+				properties = new ArrayList<PendingProperty>();
+			}
+			properties.add(new PendingProperty(obj, klass, name));
+		}
+		
+		public void resolveProperties(Object result) {
+			if (properties == null)
+				// No pending properties
+				return;
+			
+			for (PendingProperty prop: properties) {
+				try {
+					try {
+						prop.klass.getField(prop.name).set(prop.obj, result);
+					} catch (Exception e) {
+						BeanUtils.setProperty(prop.obj, prop.name, result);
+					}
+				} catch (Exception e) {
+					log.error("Error mapping property: " + prop.name + " (" + result + ")");
+				}
+			}
+			properties.clear();
+		}
 	}
 	
@@ -409,18 +449,27 @@
 					storeReference(tempRefId, result);
 					Class resultClass = result.getClass();
+					pending.resolveProperties(result);
 					for (Map.Entry<String, Object> entry: properties.entrySet()) {
 						// Resolve circular references
-						if (entry.getValue() == pending) {
-							entry.setValue(result);
+						final String key = entry.getKey();
+						Object value = entry.getValue();
+						if (value == pending) {
+							value = result;
+						}
+						
+						if (value instanceof PendingObject) {
+							// Deferr setting of value until real object is created
+							((PendingObject) value).addPendingProperty(result, resultClass, key);
+							continue;
 						}
 						
 						try {
 							try {
-								resultClass.getField(entry.getKey()).set(result, entry.getValue());
+								resultClass.getField(key).set(result, value);
 							} catch (Exception e) {
-								BeanUtils.setProperty(result, entry.getKey(), entry.getValue());
+								BeanUtils.setProperty(result, key, value);
 							}
 						} catch (Exception e) {
-							log.error("Error mapping property: " + entry.getKey() + " (" + entry.getValue() + ")");
+							log.error("Error mapping property: " + key + " (" + value + ")");
 						}
 					}
Index: /doc/trunk/changelog.txt
===================================================================
--- /doc/trunk/changelog.txt (revision 1873)
+++ /doc/trunk/changelog.txt (revision 1874)
@@ -12,4 +12,6 @@
 - deserialization of objects defined in webapp classpath fixed
   (Jira APPSERVER-80, APPSERVER-100)
+- fixed AMF3 deserializer for references from attributes to parent classes
+  (Jira APPSERVER-101)
 
 


Note:
Diffs are chopped if more than 25k.
This is to get past the limit on the mailing list.



More information about the Red5commits mailing list