예제 #1
0
 public static Object convertArg(Context cx, Scriptable scope, Object arg, int typeTag) {
   switch (typeTag) {
     case JAVA_STRING_TYPE:
       if (arg instanceof String) {
         return arg;
       }
       return ScriptRuntime.toString(arg);
     case JAVA_INT_TYPE:
       if (arg instanceof Integer) {
         return arg;
       }
       return new Integer(ScriptRuntime.toInt32(arg));
     case JAVA_BOOLEAN_TYPE:
       if (arg instanceof Boolean) {
         return arg;
       }
       return ScriptRuntime.toBoolean(arg) ? Boolean.TRUE : Boolean.FALSE;
     case JAVA_DOUBLE_TYPE:
       if (arg instanceof Double) {
         return arg;
       }
       return new Double(ScriptRuntime.toNumber(arg));
     case JAVA_SCRIPTABLE_TYPE:
       if (arg instanceof Scriptable) {
         return arg;
       }
       return ScriptRuntime.toObject(cx, scope, arg);
     case JAVA_OBJECT_TYPE:
       return arg;
     default:
       throw new IllegalArgumentException();
   }
 }