Don't do deep serialization of HopObjects. Instead, for
HopObject properties a proxy object is created for serialization. It is a Hashtable with two entries: id and prototype, containing the the id and prototype name of the referenced HopObject as string values.
This commit is contained in:
parent
7ee29bfdc3
commit
d306e6fa18
1 changed files with 29 additions and 7 deletions
|
@ -5,6 +5,8 @@ package helma.xmlrpc.fesi;
|
|||
|
||||
|
||||
import helma.xmlrpc.*;
|
||||
import helma.scripting.fesi.ESNode;
|
||||
import helma.objectmodel.INode;
|
||||
|
||||
import FESI.Exceptions.*;
|
||||
import FESI.Data.*;
|
||||
|
@ -14,7 +16,9 @@ import java.util.*;
|
|||
|
||||
public class FesiRpcUtil {
|
||||
|
||||
// convert a generic Java object to a JavaScript Object.
|
||||
/**
|
||||
* convert a generic Java object to a JavaScript Object.
|
||||
*/
|
||||
public static ESValue convertJ2E (Object what, Evaluator evaluator) throws Exception {
|
||||
if (what == null)
|
||||
return ESNull.theNull;
|
||||
|
@ -22,7 +26,7 @@ public class FesiRpcUtil {
|
|||
Vector v = (Vector) what;
|
||||
ArrayPrototype retval = new ArrayPrototype (evaluator.getArrayPrototype (), evaluator);
|
||||
int l = v.size ();
|
||||
for (int i=0; i<l; i++)
|
||||
for (int i=0; i<l; i++)
|
||||
retval.putProperty (i, convertJ2E (v.elementAt (i), evaluator));
|
||||
return retval;
|
||||
}
|
||||
|
@ -39,7 +43,7 @@ public class FesiRpcUtil {
|
|||
return new ESString (what.toString ());
|
||||
if (what instanceof Number)
|
||||
return new ESNumber (new Double (what.toString ()).doubleValue ());
|
||||
if (what instanceof Boolean)
|
||||
if (what instanceof Boolean)
|
||||
return ESBoolean.makeBoolean (((Boolean) what).booleanValue ());
|
||||
if (what instanceof Date)
|
||||
return new DatePrototype (evaluator, (Date) what);
|
||||
|
@ -47,9 +51,11 @@ public class FesiRpcUtil {
|
|||
}
|
||||
|
||||
|
||||
// convert a JavaScript Object object to a generic Java.
|
||||
/**
|
||||
* convert a JavaScript Object object to a generic Java.
|
||||
*/
|
||||
public static Object convertE2J (ESValue what) throws EcmaScriptException {
|
||||
if (XmlRpc.debug)
|
||||
if (XmlRpc.debug)
|
||||
System.out.println ("converting e-2-j: "+what.getClass ());
|
||||
if (what instanceof ESNull)
|
||||
return null;
|
||||
|
@ -69,13 +75,29 @@ public class FesiRpcUtil {
|
|||
for (Enumeration e=o.getProperties (); e.hasMoreElements (); ) {
|
||||
String next = (String) e.nextElement ();
|
||||
if (XmlRpc.debug) System.out.println ("converting object member "+next);
|
||||
Object nj = convertE2J (o.getProperty (next, next.hashCode ()));
|
||||
// We don't do deep serialization of HopObjects to avoid
|
||||
// that the whole web site structure is sucked out with one
|
||||
// object. Instead we return some kind of "proxy" objects
|
||||
// that only contain the prototype and id of the HopObject property.
|
||||
Object nj = null;
|
||||
ESValue esv = o.getProperty (next, next.hashCode ());
|
||||
if (esv instanceof ESNode) {
|
||||
INode node = ((ESNode) esv).getNode ();
|
||||
if (node != null) {
|
||||
Hashtable nt = new Hashtable ();
|
||||
nt.put ("id", node.getID());
|
||||
if (node.getPrototype() != null)
|
||||
nt.put ("prototype", node.getPrototype ());
|
||||
nj = nt;
|
||||
}
|
||||
} else
|
||||
nj = convertE2J (esv);
|
||||
if (nj != null) // can't put null as value in hashtable
|
||||
t.put (next, nj);
|
||||
}
|
||||
return t;
|
||||
}
|
||||
if (what instanceof ESUndefined || what instanceof ESNull)
|
||||
if (what instanceof ESUndefined || what instanceof ESNull)
|
||||
return null;
|
||||
Object jval = what.toJavaObject ();
|
||||
if (jval instanceof Byte || jval instanceof Short)
|
||||
|
|
Loading…
Add table
Reference in a new issue