[Red5commits] [1674] implemented AMF3 class references
jbauch
luke at codegent.com
Fri Jan 26 22:10:07 EST 2007
implemented AMF3 class references
Timestamp: 01/26/07 21:04:32 EST (1 hour ago)
Change: 1674
Author: jbauch
Files (see diff or trac for details):
java/server/trunk/src/org/red5/io/amf/Input.java
java/server/trunk/src/org/red5/io/amf3/Input.java
java/server/trunk/swf/DEV_Source/classes/org/red5/samples/echo/RemoteClass.as
java/server/trunk/swf/DEV_Source/echotest.mxml
java/server/trunk/webapps/echo/WEB-INF/src/org/red5/server/webapp/echo/RemoteClass.java
Trac: http://mirror1.cvsdude.com/trac/osflash/red5/changeset/1674
Index: /java/server/trunk/src/org/red5/io/amf3/Input.java
===================================================================
--- /java/server/trunk/src/org/red5/io/amf3/Input.java (revision 1668)
+++ /java/server/trunk/src/org/red5/io/amf3/Input.java (revision 1674)
@@ -20,8 +20,8 @@
*/
-import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
+import java.util.LinkedList;
import java.util.List;
import java.util.Map;
@@ -44,4 +44,22 @@
*/
public class Input extends org.red5.io.amf.Input implements org.red5.io.object.Input {
+
+ /**
+ * Holds informations about already deserialized classes.
+ */
+ protected class ClassReference {
+
+ /** Name of the deserialized class. */
+ protected String className;
+ /** Names of the attributes of the class. */
+ protected List<String> attributeNames;
+
+ /** Create new informations about a class. */
+ public ClassReference(String className, List<String> attributeNames) {
+ this.className = className;
+ this.attributeNames = attributeNames;
+ }
+ }
+
/**
* Logger
@@ -56,4 +74,8 @@
*/
private List<String> stringReferences;
+ /**
+ * Informations about already deserialized classes.
+ */
+ private List<ClassReference> classReferences;
/**
@@ -66,4 +88,5 @@
amf3_mode = 0;
stringReferences = new ArrayList<String>();
+ classReferences = new ArrayList<ClassReference>();
}
@@ -288,12 +311,17 @@
type >>= 1;
+ List<String> attributes = null;
+ String className;
+ Object result = null;
boolean inlineClass = (type & 1) == 1;
if (!inlineClass) {
- throw new RuntimeException("Class references not supported yet.");
- }
-
- type >>= 1;
- String className = readString();
- Object result = null;
+ ClassReference info = classReferences.get(type >> 1);
+ className = info.className;
+ attributes = info.attributeNames;
+ type = attributes.size() << 2 | AMF3.TYPE_OBJECT_PROPERTY;
+ } else {
+ type >>= 1;
+ className = readString();
+ }
amf3_mode += 1;
Map<String, Object> properties = null;
@@ -303,10 +331,13 @@
int count = type >> 2;
properties = new ObjectMap<String, Object>();
- List<String> propertyNames = new ArrayList<String>(count);
+ if (attributes == null) {
+ attributes = new ArrayList<String>(count);
+ for (int i=0; i<count; i++) {
+ attributes.add(readString());
+ }
+ classReferences.add(new ClassReference(className, attributes));
+ }
for (int i=0; i<count; i++) {
- propertyNames.add(readString());
- }
- for (int i=0; i<count; i++) {
- properties.put(propertyNames.get(i), deserializer.deserialize(this));
+ properties.put(attributes.get(i), deserializer.deserialize(this));
}
break;
@@ -328,10 +359,13 @@
// Load object properties into map
properties = new ObjectMap<String, Object>();
+ attributes = new LinkedList<String>();
String key = readString();
while (!"".equals(key)) {
+ attributes.add(key);
Object value = deserializer.deserialize(this);
properties.put(key, value);
key = readString();
}
+ classReferences.add(new ClassReference(className, attributes));
break;
default:
@@ -358,7 +392,12 @@
if (result != null) {
storeReference(properties);
+ Class resultClass = result.getClass();
for (Map.Entry<String, Object> entry: properties.entrySet()) {
try {
- BeanUtils.setProperty(result, entry.getKey(), entry.getValue());
+ try {
+ resultClass.getField(entry.getKey()).set(result, entry.getValue());
+ } catch (Exception e) {
+ BeanUtils.setProperty(result, entry.getKey(), entry.getValue());
+ }
} catch (Exception e) {
log.error("Error mapping property: " + entry.getKey() + " (" + entry.getValue() + ")");
Index: /java/server/trunk/src/org/red5/io/amf/Input.java
===================================================================
--- /java/server/trunk/src/org/red5/io/amf/Input.java (revision 1664)
+++ /java/server/trunk/src/org/red5/io/amf/Input.java (revision 1674)
@@ -397,4 +397,5 @@
}
storeReference(bean);
+ Class theClass = bean.getClass();
while (hasMoreProperties()) {
String name = readPropertyName();
@@ -409,5 +410,9 @@
try {
if (property != null) {
- BeanUtils.setProperty(bean, name, property);
+ try {
+ theClass.getField(name).set(bean, property);
+ } catch (Exception ex2) {
+ BeanUtils.setProperty(bean, name, property);
+ }
} else {
if (log.isDebugEnabled()) {
@@ -416,5 +421,5 @@
}
} catch (Exception ex) {
- log.error("Error mapping property: " + name);
+ log.error("Error mapping property: " + name + " (" + property + ")");
}
if (hasMoreProperties()) {
Index: /java/server/trunk/swf/DEV_Source/echotest.mxml
===================================================================
--- /java/server/trunk/swf/DEV_Source/echotest.mxml (revision 1668)
+++ /java/server/trunk/swf/DEV_Source/echotest.mxml (revision 1674)
@@ -12,4 +12,5 @@
import mx.controls.Alert;
import org.red5.samples.echo.EchoClass;
+ import org.red5.samples.echo.RemoteClass;
import org.red5.samples.echo.ExternalizableClass;
@@ -78,4 +79,23 @@
tmp7.attr2 = 1;
testParams.push(tmp7);
+ var tmp8: Array = new Array();
+ tmp8.push(tmp7);
+ tmp8.push(tmp7);
+ testParams.push(tmp8);
+ var remote: RemoteClass = new RemoteClass();
+ remote.attribute1 = "one";
+ remote.attribute2 = 2;
+ testParams.push(remote);
+ var tmp9: Array = new Array();
+ var remote1: RemoteClass = new RemoteClass();
+ remote1.attribute1 = "one";
+ remote1.attribute2 = 1;
+ tmp8.push(remote1);
+ var remote2: RemoteClass = new RemoteClass();
+ remote2.attribute1 = "two";
+ remote2.attribute2 = 2;
+ tmp9.push(remote2);
+ testParams.push(tmp9);
+
AMF0Count = testParams.length;
@@ -83,4 +103,8 @@
var ext: ExternalizableClass = new ExternalizableClass();
testParams.push(ext);
+ var tmp_1: Array = new Array();
+ tmp_1.push(ext);
+ tmp_1.push(ext);
+ testParams.push(tmp_1);
nc = new NetConnection();
Index: /java/server/trunk/swf/DEV_Source/classes/org/red5/samples/echo/RemoteClass.as
===================================================================
--- /java/server/trunk/swf/DEV_Source/classes/org/red5/samples/echo/RemoteClass.as (revision 1674)
+++ /java/server/trunk/swf/DEV_Source/classes/org/red5/samples/echo/RemoteClass.as (revision 1674)
@@ -0,0 +1,9 @@
+package org.red5.samples.echo {
+
+[RemoteClass(alias="org.red5.server.webapp.echo.RemoteClass")]
+public class RemoteClass {
+ public var attribute1: String;
+ public var attribute2: Number;
+}
+
+}
Index: /java/server/trunk/webapps/echo/WEB-INF/src/org/red5/server/webapp/echo/RemoteClass.java
===================================================================
--- /java/server/trunk/webapps/echo/WEB-INF/src/org/red5/server/webapp/echo/RemoteClass.java (revision 1674)
+++ /java/server/trunk/webapps/echo/WEB-INF/src/org/red5/server/webapp/echo/RemoteClass.java (revision 1674)
@@ -0,0 +1,9 @@
+package org.red5.server.webapp.echo;
+
+public class RemoteClass {
+
+ public String attribute1;
+
+ public int attribute2;
+
+}
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