org.helma.util
Class ScriptUtils

java.lang.Object
  extended by org.helma.util.ScriptUtils

public class ScriptUtils
extends java.lang.Object

A collection of Rhino utility methods.


Constructor Summary
ScriptUtils()
           
 
Method Summary
static void checkArguments(java.lang.Object[] args, int min, int max)
          Make sure that number of arguments is valid.
static org.mozilla.javascript.Scriptable getClassOrObjectProto(org.mozilla.javascript.Scriptable scope, java.lang.String className)
          Return a class prototype, or the object prototype if the class is not defined.
static java.lang.Object getObjectArgument(java.lang.Object[] args, int pos)
          Get an argument as object
static java.lang.String getStringArgument(java.lang.Object[] args, int pos)
          Get an argument as string
static java.lang.Object javaToJS(java.lang.Object obj, org.mozilla.javascript.Scriptable scope)
          Coerce/wrap a java object to a JS object, and mask Lists and Maps as native JS objects.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ScriptUtils

public ScriptUtils()
Method Detail

javaToJS

public static java.lang.Object javaToJS(java.lang.Object obj,
                                        org.mozilla.javascript.Scriptable scope)
Coerce/wrap a java object to a JS object, and mask Lists and Maps as native JS objects.

Parameters:
obj - the object to coerce/wrap
scope - the scope
Returns:
the wrapped/masked java object

getClassOrObjectProto

public static org.mozilla.javascript.Scriptable getClassOrObjectProto(org.mozilla.javascript.Scriptable scope,
                                                                      java.lang.String className)
Return a class prototype, or the object prototype if the class is not defined.

Parameters:
scope - the scope
className - the class name
Returns:
the class or object prototype

checkArguments

public static void checkArguments(java.lang.Object[] args,
                                  int min,
                                  int max)
Make sure that number of arguments is valid.

Parameters:
args - the argument array
min - the minimum number of arguments
max - the maximum number of arguments
Throws:
java.lang.IllegalArgumentException - if the number of arguments is not valid

getStringArgument

public static java.lang.String getStringArgument(java.lang.Object[] args,
                                                 int pos)
Get an argument as string

Parameters:
args - the argument array
pos - the position of the requested argument
Returns:
the argument as string

getObjectArgument

public static java.lang.Object getObjectArgument(java.lang.Object[] args,
                                                 int pos)
Get an argument as object

Parameters:
args - the argument array
pos - the position of the requested argument
Returns:
the argument as object