Myna is designed to dynamically compile jsvascript files from the
filesystem in a web environment. That said, it can actually compile
and run raw javascript text, or theoretically use resource URL's since
all file handling id via URL/URI.
MynaThread is as "plain" as it gets. It is the core runtime class that
does all the Rhino interaction. All of the application server related
code is actually in JS files, so that can be heavily modified without
editing MynaThread. For example, all the user management and
permissions can be removed.
What Myna adds over plain Rhino, is it's standard library. Here is a
quick example of a plain Rhino task made easier in Myna:
Converting a Java bean to a JSON object
---- Plain Rhino----
var bean = new org.custom.SomeClass();
var result={}
for (x in bean){
if (/^get./.test(x)){
try{
property=x.replace(/^get_?/,"");
property=property.substr(0,1).toLowerCase() + property.substr(1);
result[property] = bean[x]();
if (result[property] instanceof java.lang.String){
result[property] = result[property];
}
}catch(e){}
}
if (/^is./.test(x)){
try{
property=x.replace(/^is/,"");
property=property.substr(0,1).toLowerCase() + property.substr(1);
result[property] = bean[x]();
if (result[property] instanceof java.lang.String){
result[property] = Boolean(result[property]);
}
}catch(e){}
}
}
try{
//make sure to reverse the slashes for Windows, or make a URI first
var fstream = new java.io.FileWriter("/path/to/app/dir/jsonfiles/
filename.json");
var out = new java.io.BufferedWriter(fstream);
out.write(JSON.stringify(result));
}catch (Exception e){//Catch exception if any
System.err.println("Error: " + e.getMessage());
} finally{
out.close()
}
---- Myna ----
Myna.applyTo(this);
var bean = new org.custom.SomeClass();
var result = JavaUtils.beanToObject(bean).toJson();
// here, "/" is the rootDir for Myna, and will work in UNIX and
Windows
new File("/jsonfiles/filename.json").writeString(result);
Myna also manages things like caching compiled JS code, and re-using
scopes to speed up repeated tasks
If you have no interest general purpose scripting, you can simplify
things by making your own Rhino runtime, or modifying Myna's JS
runtime. This will require either modifying Tony's code to not use
Myna's libraries, or load just enough of the Myna libs to get the code
to work. If I could see Tony's code I could probably give some
pointers on how big a task it would be convert.
> [2]
http://code.google.com/p/myna/source/browse/trunk/1.0/src/info/emptyb...