/**
   * Wraps a method as a JavaScript function.
   *
   * @param methodName the name of the method to wrap
   * @param clazz the class declaring the method
   * @param parameterTypes the types of the method's parameter
   * @throws NoSuchMethodException if the method is no found
   */
  MethodWrapper(final String methodName, final Class<?> clazz, final Class<?>[] parameterTypes)
      throws NoSuchMethodException {

    clazz_ = clazz;
    method_ = clazz.getMethod(methodName, parameterTypes);
    jsTypeTags_ = new int[parameterTypes.length];
    int i = 0;
    for (final Class<?> klass : parameterTypes) {
      jsTypeTags_[i++] = FunctionObject.getTypeTag(klass);
    }
  }
 /**
  * Converts js arguments to java arguments
  *
  * @param context the current context
  * @param scope the current scope
  * @param jsArgs the JavaScript arguments
  * @return the java arguments
  */
 Object[] convertJSArgsToJavaArgs(
     final Context context, final Scriptable scope, final Object[] jsArgs) {
   if (jsArgs.length != jsTypeTags_.length) {
     throw Context.reportRuntimeError(
         "Bad number of parameters for function "
             + method_.getName()
             + ": expected "
             + jsTypeTags_.length
             + " got "
             + jsArgs.length);
   }
   final Object[] javaArgs = new Object[jsArgs.length];
   int i = 0;
   for (final Object object : jsArgs) {
     javaArgs[i] = FunctionObject.convertArg(context, scope, object, jsTypeTags_[i++]);
   }
   return javaArgs;
 }
Example #3
0
 /**
  * finishInit
  *
  * @param scope
  * @param constructor
  * @param prototype
  */
 public static void finishInit(
     Scriptable scope, FunctionObject constructor, Scriptable prototype) {
   constructor.defineProperty("separator", java.io.File.separator, READONLY | PERMANENT);
 }