static Object js_createAdpter(Context cx, Scriptable scope, Object[] args)
    {
        int N = args.length;
        if (N == 0) {
            throw ScriptRuntime.typeError0("msg.adapter.zero.args");
        }

        Class superClass = null;
        Class[] intfs = new Class[N - 1];
        int interfaceCount = 0;
        for (int i = 0; i != N - 1; ++i) {
            Object arg = args[i];
            if (!(arg instanceof NativeJavaClass)) {
                throw ScriptRuntime.typeError2("msg.not.java.class.arg",
                                               String.valueOf(i),
                                               ScriptRuntime.toString(arg));
            }
            Class c = ((NativeJavaClass) arg).getClassObject();
            if (!c.isInterface()) {
                if (superClass != null) {
                    throw ScriptRuntime.typeError2("msg.only.one.super",
                              superClass.getName(), c.getName());
                }
                superClass = c;
            } else {
                intfs[interfaceCount++] = c;
            }
        }

        if (superClass == null)
            superClass = ScriptRuntime.ObjectClass;

        Class[] interfaces = new Class[interfaceCount];
        System.arraycopy(intfs, 0, interfaces, 0, interfaceCount);
        Scriptable obj = ScriptRuntime.toObject(cx, scope, args[N - 1]);

        Class adapterClass = getAdapterClass(scope, superClass, interfaces,
                                             obj);

        Class[] ctorParms = {
            ScriptRuntime.ContextFactoryClass,
            ScriptRuntime.ScriptableClass
        };
        Object[] ctorArgs = { cx.getFactory(), obj };
        try {
            Object adapter = adapterClass.getConstructor(ctorParms).
                                 newInstance(ctorArgs);
            return getAdapterSelf(adapterClass, adapter);
        } catch (Exception ex) {
            throw Context.throwAsScriptRuntimeEx(ex);
        }
    }