Class JavaAdapter

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      (package private) static class  JavaAdapter.JavaAdapterSignature
      Provides a key with which to distinguish previously generated adapter classes stored in a hash table.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static java.lang.Object FTAG  
      private static int Id_JavaAdapter  
    • Constructor Summary

      Constructors 
      Constructor Description
      JavaAdapter()  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      (package private) static int appendMethodSignature​(java.lang.Class<?>[] argTypes, java.lang.Class<?> returnType, java.lang.StringBuilder sb)  
      private static void appendOverridableMethods​(java.lang.Class<?> c, java.util.ArrayList<java.lang.reflect.Method> list, java.util.HashSet<java.lang.String> skip)  
      private static java.lang.StringBuilder appendTypeString​(java.lang.StringBuilder sb, java.lang.Class<?> type)  
      static java.lang.Object callMethod​(ContextFactory factory, Scriptable thisObj, Function f, java.lang.Object[] args, long argsToWrap)
      Utility method which dynamically binds a Context to the current thread, if none already exists.
      static java.lang.Object convertResult​(java.lang.Object result, java.lang.Class<?> c)  
      static byte[] createAdapterCode​(ObjToIntMap functionNames, java.lang.String adapterName, java.lang.Class<?> superClass, java.lang.Class<?>[] interfaces, java.lang.String scriptClassName)  
      static Scriptable createAdapterWrapper​(Scriptable obj, java.lang.Object adapter)  
      private static java.lang.Object doCall​(Context cx, Scriptable scope, Scriptable thisObj, Function f, java.lang.Object[] args, long argsToWrap)  
      java.lang.Object execIdCall​(IdFunctionObject f, Context cx, Scriptable scope, Scriptable thisObj, java.lang.Object[] args)
      'thisObj' will be null if invoked as constructor, in which case instance of Scriptable should be returned
      private static void generateCtor​(ClassFileWriter cfw, java.lang.String adapterName, java.lang.String superName, java.lang.reflect.Constructor<?> superCtor)  
      private static void generateEmptyCtor​(ClassFileWriter cfw, java.lang.String adapterName, java.lang.String superName, java.lang.String scriptClassName)  
      private static void generateMethod​(ClassFileWriter cfw, java.lang.String genName, java.lang.String methodName, java.lang.Class<?>[] parms, java.lang.Class<?> returnType, boolean convertResult)  
      private static void generatePopResult​(ClassFileWriter cfw, java.lang.Class<?> retType)
      Generates code to return a Java type, after calling a Java method that returns the same type.
      private static int generatePushParam​(ClassFileWriter cfw, int paramOffset, java.lang.Class<?> paramType)
      Generates code to push typed parameters onto the operand stack prior to a direct Java method call.
      (package private) static void generatePushWrappedArgs​(ClassFileWriter cfw, java.lang.Class<?>[] argTypes, int arrayLength)
      Generates code to wrap Java arguments into Object[].
      (package private) static void generateReturnResult​(ClassFileWriter cfw, java.lang.Class<?> retType, boolean callConvertResult)
      Generates code to convert a wrapped value type to a primitive type.
      private static void generateSerialCtor​(ClassFileWriter cfw, java.lang.String adapterName, java.lang.String superName)  
      private static void generateSuper​(ClassFileWriter cfw, java.lang.String genName, java.lang.String superName, java.lang.String methodName, java.lang.String methodSignature, java.lang.Class<?>[] parms, java.lang.Class<?> returnType)
      Generates a method called "super$methodName()" which can be called from JavaScript that is equivalent to calling "super.methodName()" from Java.
      private static int generateWrapArg​(ClassFileWriter cfw, int paramOffset, java.lang.Class<?> argType)
      Generates code to wrap Java argument into Object.
      private static java.lang.Class<?> getAdapterClass​(Scriptable scope, java.lang.Class<?> superClass, java.lang.Class<?>[] interfaces, Scriptable obj)  
      static java.lang.Object getAdapterSelf​(java.lang.Class<?> adapterClass, java.lang.Object adapter)  
      (package private) static int[] getArgsToConvert​(java.lang.Class<?>[] argTypes)  
      static Function getFunction​(Scriptable obj, java.lang.String functionName)  
      private static java.lang.String getMethodSignature​(java.lang.reflect.Method method, java.lang.Class<?>[] argTypes)
      Returns a fully qualified method name concatenated with its signature.
      private static ObjToIntMap getObjectFunctionNames​(Scriptable obj)  
      (package private) static java.lang.reflect.Method[] getOverridableMethods​(java.lang.Class<?> clazz)  
      static void init​(Context cx, Scriptable scope, boolean sealed)  
      (package private) static java.lang.Object js_createAdapter​(Context cx, Scriptable scope, java.lang.Object[] args)  
      (package private) static java.lang.Class<?> loadAdapterClass​(java.lang.String className, byte[] classBytes)  
      static java.lang.Object readAdapterObject​(Scriptable self, java.io.ObjectInputStream in)  
      static Scriptable runScript​(Script script)  
      static void writeAdapterObject​(java.lang.Object javaObject, java.io.ObjectOutputStream out)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • FTAG

        private static final java.lang.Object FTAG
    • Constructor Detail

      • JavaAdapter

        public JavaAdapter()
    • Method Detail

      • convertResult

        public static java.lang.Object convertResult​(java.lang.Object result,
                                                     java.lang.Class<?> c)
      • createAdapterWrapper

        public static Scriptable createAdapterWrapper​(Scriptable obj,
                                                      java.lang.Object adapter)
      • getAdapterSelf

        public static java.lang.Object getAdapterSelf​(java.lang.Class<?> adapterClass,
                                                      java.lang.Object adapter)
                                               throws java.lang.NoSuchFieldException,
                                                      java.lang.IllegalAccessException
        Throws:
        java.lang.NoSuchFieldException
        java.lang.IllegalAccessException
      • js_createAdapter

        static java.lang.Object js_createAdapter​(Context cx,
                                                 Scriptable scope,
                                                 java.lang.Object[] args)
      • writeAdapterObject

        public static void writeAdapterObject​(java.lang.Object javaObject,
                                              java.io.ObjectOutputStream out)
                                       throws java.io.IOException
        Throws:
        java.io.IOException
      • readAdapterObject

        public static java.lang.Object readAdapterObject​(Scriptable self,
                                                         java.io.ObjectInputStream in)
                                                  throws java.io.IOException,
                                                         java.lang.ClassNotFoundException
        Throws:
        java.io.IOException
        java.lang.ClassNotFoundException
      • getAdapterClass

        private static java.lang.Class<?> getAdapterClass​(Scriptable scope,
                                                          java.lang.Class<?> superClass,
                                                          java.lang.Class<?>[] interfaces,
                                                          Scriptable obj)
      • createAdapterCode

        public static byte[] createAdapterCode​(ObjToIntMap functionNames,
                                               java.lang.String adapterName,
                                               java.lang.Class<?> superClass,
                                               java.lang.Class<?>[] interfaces,
                                               java.lang.String scriptClassName)
      • getOverridableMethods

        static java.lang.reflect.Method[] getOverridableMethods​(java.lang.Class<?> clazz)
      • appendOverridableMethods

        private static void appendOverridableMethods​(java.lang.Class<?> c,
                                                     java.util.ArrayList<java.lang.reflect.Method> list,
                                                     java.util.HashSet<java.lang.String> skip)
      • loadAdapterClass

        static java.lang.Class<?> loadAdapterClass​(java.lang.String className,
                                                   byte[] classBytes)
      • getFunction

        public static Function getFunction​(Scriptable obj,
                                           java.lang.String functionName)
      • callMethod

        public static java.lang.Object callMethod​(ContextFactory factory,
                                                  Scriptable thisObj,
                                                  Function f,
                                                  java.lang.Object[] args,
                                                  long argsToWrap)
        Utility method which dynamically binds a Context to the current thread, if none already exists.
      • generateCtor

        private static void generateCtor​(ClassFileWriter cfw,
                                         java.lang.String adapterName,
                                         java.lang.String superName,
                                         java.lang.reflect.Constructor<?> superCtor)
      • generateSerialCtor

        private static void generateSerialCtor​(ClassFileWriter cfw,
                                               java.lang.String adapterName,
                                               java.lang.String superName)
      • generateEmptyCtor

        private static void generateEmptyCtor​(ClassFileWriter cfw,
                                              java.lang.String adapterName,
                                              java.lang.String superName,
                                              java.lang.String scriptClassName)
      • generatePushWrappedArgs

        static void generatePushWrappedArgs​(ClassFileWriter cfw,
                                            java.lang.Class<?>[] argTypes,
                                            int arrayLength)
        Generates code to wrap Java arguments into Object[]. Non-primitive Java types are left as-is pending conversion in the helper method. Leaves the array object on the top of the stack.
      • generateWrapArg

        private static int generateWrapArg​(ClassFileWriter cfw,
                                           int paramOffset,
                                           java.lang.Class<?> argType)
        Generates code to wrap Java argument into Object. Non-primitive Java types are left unconverted pending conversion in the helper method. Leaves the wrapper object on the top of the stack.
      • generateReturnResult

        static void generateReturnResult​(ClassFileWriter cfw,
                                         java.lang.Class<?> retType,
                                         boolean callConvertResult)
        Generates code to convert a wrapped value type to a primitive type. Handles unwrapping java.lang.Boolean, and java.lang.Number types. Generates the appropriate RETURN bytecode.
      • generateMethod

        private static void generateMethod​(ClassFileWriter cfw,
                                           java.lang.String genName,
                                           java.lang.String methodName,
                                           java.lang.Class<?>[] parms,
                                           java.lang.Class<?> returnType,
                                           boolean convertResult)
      • generatePushParam

        private static int generatePushParam​(ClassFileWriter cfw,
                                             int paramOffset,
                                             java.lang.Class<?> paramType)
        Generates code to push typed parameters onto the operand stack prior to a direct Java method call.
      • generatePopResult

        private static void generatePopResult​(ClassFileWriter cfw,
                                              java.lang.Class<?> retType)
        Generates code to return a Java type, after calling a Java method that returns the same type. Generates the appropriate RETURN bytecode.
      • generateSuper

        private static void generateSuper​(ClassFileWriter cfw,
                                          java.lang.String genName,
                                          java.lang.String superName,
                                          java.lang.String methodName,
                                          java.lang.String methodSignature,
                                          java.lang.Class<?>[] parms,
                                          java.lang.Class<?> returnType)
        Generates a method called "super$methodName()" which can be called from JavaScript that is equivalent to calling "super.methodName()" from Java. Eventually, this may be supported directly in JavaScript.
      • getMethodSignature

        private static java.lang.String getMethodSignature​(java.lang.reflect.Method method,
                                                           java.lang.Class<?>[] argTypes)
        Returns a fully qualified method name concatenated with its signature.
      • appendMethodSignature

        static int appendMethodSignature​(java.lang.Class<?>[] argTypes,
                                         java.lang.Class<?> returnType,
                                         java.lang.StringBuilder sb)
      • appendTypeString

        private static java.lang.StringBuilder appendTypeString​(java.lang.StringBuilder sb,
                                                                java.lang.Class<?> type)
      • getArgsToConvert

        static int[] getArgsToConvert​(java.lang.Class<?>[] argTypes)