made the res.data get its HashMap from the ResponseTrans

object

added methods to check if a function is defined for an object
and to retrieve a property. This is used by Skins and should
work for any object, be it HopObjects or scripted Java objects.
This commit is contained in:
hns 2001-11-26 17:24:04 +00:00
parent 5ae3d18565
commit 782bf86ba2

View file

@ -13,6 +13,7 @@ import helma.xmlrpc.fesi.*;
import helma.util.*; import helma.util.*;
import java.util.*; import java.util.*;
import java.io.*; import java.io.*;
import java.lang.reflect.*;
import Acme.LruHashtable; import Acme.LruHashtable;
import FESI.Data.*; import FESI.Data.*;
import FESI.Interpreter.*; import FESI.Interpreter.*;
@ -206,7 +207,7 @@ public class RequestEvaluator implements Runnable {
// set and mount the request and response data object // set and mount the request and response data object
reqData.setData (req.getRequestData()); reqData.setData (req.getRequestData());
req.data = reqData; req.data = reqData;
resData.setData (new HashMap ()); resData.setData (res.getResponseData());
res.data = resData; res.data = resData;
try { try {
@ -443,7 +444,7 @@ public class RequestEvaluator implements Runnable {
global.deleteProperty ("path", "path".hashCode()); global.deleteProperty ("path", "path".hashCode());
global.putHiddenProperty ("app", appnode); global.putHiddenProperty ("app", appnode);
resData.setData (new HashMap ()); resData.setData (res.getResponseData());
res.data = resData; res.data = resData;
// convert arguments // convert arguments
@ -517,7 +518,7 @@ public class RequestEvaluator implements Runnable {
global.deleteProperty ("path", "path".hashCode()); global.deleteProperty ("path", "path".hashCode());
global.putHiddenProperty ("app", appnode); global.putHiddenProperty ("app", appnode);
resData.setData (new HashMap ()); resData.setData (res.getResponseData());
res.data = resData; res.data = resData;
if (current == null) { if (current == null) {
@ -1004,6 +1005,54 @@ public class RequestEvaluator implements Runnable {
prototypes.put (protoName, op); prototypes.put (protoName, op);
} }
/**
* Check if an object has a function property (public method if it
* is a java object) with that name.
*/
public boolean hasFunction (Object obj, String fname) {
ESObject eso = null;
if (obj == null)
eso = global;
else
eso = getElementWrapper (obj);
try {
ESValue func = eso.getProperty (fname, fname.hashCode());
if (func != null && func instanceof FunctionPrototype)
return true;
} catch (EcmaScriptException esx) {
System.err.println ("Error in getProperty: "+esx);
return false;
}
return false;
}
/**
* Check if an object has a defined property (public field if it
* is a java object) with that name.
*/
public Object getProperty (Object obj, String propname) {
if (obj == null)
return null;
String prototypeName = app.getPrototypeName (obj);
if ("user".equalsIgnoreCase (prototypeName) &&
"password".equalsIgnoreCase (propname))
return null;
ESObject eso = getElementWrapper (obj);
try {
ESValue prop = eso.getProperty (propname, propname.hashCode());
if (prop != null && !(prop instanceof ESNull) &&
!(prop instanceof ESUndefined))
return prop.toJavaObject ();
} catch (EcmaScriptException esx) {
System.err.println ("Error in getProperty: "+esx);
return null;
}
return null;
}
/** /**
* Utility class to use for caching skins in a Hashtable. * Utility class to use for caching skins in a Hashtable.
* The key consists out of two strings: prototype name and skin name. * The key consists out of two strings: prototype name and skin name.