println(file.getClass().getName());
var clas = file.getClass();
var clasJSON = { methods: [] };
for(var methodI in clas.getDeclaredMethods()) {
var method = clas.getDeclaredMethods()[methodI];
println("m:"+method.getName());
var methodName = method.getName();
var allPrimatives = true;
var methodJSON = {name: methodName};
for(var argI in method.getParameterTypes()) {
var arg = method.getParameterTypes()[argI];
println(" a:"+arg.getName());
if(arg.getClass().isPrimitive()===false) {
allPrimatives = false;
break;
}
var argName = arg.getName;
methodJSON.push( {name: 'arg'+argI, type: argName} );
}
if(allPrimatives) {
clasJSON.push(methodJSON);
}
}
/*
Server side javascript wrapper
*/
/*
Service code template
if(action==="methodName") {
var arg0 = transaction.getParameter("arg0");
return file.methodName(arg0);
}
*/
/*
Service documentation template
*/
/*
Client code template
file: {
methodName: function(arg0,successFn) {
if(successFn) {
JSON.get(uri,"arg0="+arg0).onSuccess(successFn).go();
} else {
return OpenForum.loadFile(uri+"?arg0="+arg0);
}
}
}
*/
/*
Client code documentation template
*/
Old Code
/OpenForum/Javascript/JavaWrapper/java-wrapper.sjs/*function wrap(instance) {
//if primative, convert to javascript type
if(instance instanceof String) {
return ""+instance;
} //etc
var jsWrapper = {};
// original instance held in wrapper
jsWrapper._original = instance;
// loop through each method in instance and add matching js method
{
jsWapper.method = function(signature) {
// if call parameter is non primative, if has wrapped java, use wrapped
var result = _original.method();
// if method returns non primative, include call to wrap so java wrapped on demand
return wrap(result);
}
}
return jsWapper;
}*/
function wrap(instance) {
for(var fn in instance) {
println(instance[fn]);
}
}
wrap(js);