Penetration System, Method, Medium and Device between Multiple Programming Languages Based on Dynamic Parsing
By dynamically parsing Java class functions and registering them to a JavaScript virtual machine, the one-to-one correspondence between Java and JavaScript objects is achieved, which solves the problem of function call binding and namespace confusion, and improves development efficiency.
Patent Information
- Application Number
- CN202111631481.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-28
- Publication Date
- 2025-06-24
- Estimated Expiration
- 2041-12-28
AI Technical Summary
In the prior art, JavaScript objects and Java objects cannot correspond one by one, and function calls cannot be bound to multiple Java objects, resulting in namespace confusion and function coverage problems.
By dynamically parsing Java class functions, registering them to the JavaScript virtual machine, implementing mutual conversion of Java data types and JavaScript data types, and data unpacking, Java object creation or location and function distribution are performed in the function call distribution unit.
It solves the problem that function calls cannot be bound to multiple Java objects, avoids namespace confusion and function coverage, reduces the complexity of inter-language penetration, and improves development efficiency.
Smart Images

Figure CN114489580B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of data parsing, and in particular, to a penetration system, method, medium and device between multiple development languages based on dynamic parsing. Background Art
[0002] In the prior art, when performing function development, especially when using multiple languages for function development, JavaScript objects and Java objects cannot correspond one by one, function calls cannot be bound to multiple Java objects, and a large number of functions are registered in the JavaScript virtual machine, resulting in a chaotic naming space. When multiple modules are integrated, there may be an overwriting problem due to the same function name.
[0003] Patent document CN104125240A (application number: CN201410403098.5) discloses an information external network, an information internal network, and an internal and external network data interaction system and method. In the method, the information external network concurrently receives and processes multiple request information of high concurrency of users, and performs data penetration with the information internal network based on a concurrent processing interaction method, and concurrently sends multiple request instructions processed into a preset language form and a preset format to the information internal network through a physical isolation device. The information internal network concurrently processes the multiple request instructions to obtain corresponding response result data, and finally the information external network obtains the response result data and concurrently displays it at relevant positions of the application system. However, this patent cannot solve the above problems, nor can it achieve the technical effects of the present invention. Summary of the Invention
[0004] Aiming at the defects in the prior art, the purpose of the present invention is to provide a penetration system, method, medium and device between multiple development languages based on dynamic parsing.
[0005] According to the penetration system between multiple development languages based on dynamic parsing provided by the present invention, it includes:
[0006] A class registration unit: dynamically parses Java class functions and registers them in the JavaScript virtual machine;
[0007] A data conversion unit: mutually converts Java data types and JavaScript data types;
[0008] A function call distribution unit: performs data unpacking, Java object creation or positioning, and function distribution.
[0009] Preferably, the dynamic parsing of the Java class functions is used to analyze the Java class to include the class name, the function name and function parameters for modification, and the name of the ancestor class;
[0010] It is registered to the JavaScript virtual machine, performs data conversion on the parsed class information, and is sequentially registered to the JavaScript virtual machine in the way of native callback.
[0011] Preferably, the data unpacking means parsing out the function name, parameter type and parameter value from the parameters called by JavaScript, and then performing data type conversion through the data conversion unit;
[0012] The creation or positioning of the Java object means judging the operation mode according to the parameter information after data unpacking, creating a new Java object or positioning to the corresponding Java object;
[0013] The function distribution means distributing the function to the member function of the located Java object and returning the call result to JavaScript.
[0014] Preferably, when only using the Java language for function development at the bottom layer, the Java class is registered to the JavaScript virtual machine. When a JavaScript instance is created, the corresponding Java class object and its member functions are created at the same time.
[0015] According to the penetration method between multiple development languages based on dynamic parsing provided by the present invention, execute:
[0016] For the initialization data stream, first dynamically parse the class information in the Java virtual machine and register it, then convert the data type from Java to JavaScript, and finally load the converted data into the JavaScript virtual machine;
[0017] For the class function call data stream, first obtain the class name and call method from the JavaScript virtual machine, then perform data unpacking in the function call distribution unit, convert the data type from JavaScript to Java, then perform Java object creation or positioning and function distribution, and then load it into the Java virtual machine according to the class name and call method; after software function development in the Java virtual machine, convert the data type from Java to JavaScript and then load it into the JavaScript virtual machine.
[0018] Preferably, the dynamic parsing of the Java class function is used to analyze the Java class to include the class name, the function name and function parameters for modification, and the name of the ancestor class;
[0019] It is registered to the JavaScript virtual machine, performs data conversion on the parsed class information, and is sequentially registered to the JavaScript virtual machine in the way of native callback.
[0020] Preferably, the data unpacking means parsing out the function name, parameter type, and parameter value from the parameters called by JavaScript, and then performing data type conversion through the data conversion unit;
[0021] The Java object creation or location means judging the operation mode according to the parameter information after data unpacking, and creating a new Java object or locating to the corresponding Java object;
[0022] The function distribution means distributing the function to the member function of the located Java object and returning the call result to JavaScript.
[0023] Preferably, when only using the Java language for function development at the bottom layer, register the Java class into the JavaScript virtual machine. When JavaScript creates an instance, simultaneously create the corresponding Java class object and its member functions.
[0024] According to the computer-readable storage medium storing a computer program provided by the present invention, when the computer program is executed by a processor, the steps of the method are implemented.
[0025] According to the penetration device between multiple development languages based on dynamic parsing provided by the present invention, including: a controller;
[0026] The controller includes the computer-readable storage medium storing the computer program, and when the computer program is executed by a processor, the steps of the penetration method between multiple development languages based on dynamic parsing are implemented; or, the controller includes the penetration system between multiple development languages based on dynamic parsing.
[0027] Compared with the prior art, the present invention has the following beneficial effects:
[0028] (1) By the structure in which the JavaScript object and the Java object correspond one by one, the present invention solves the problem that function calls cannot be bound to multiple Java objects; solves the problem that a large number of functions are registered in the JavaScript virtual machine, resulting in a chaotic naming space; solves the problem of possible overwriting due to the same function name when multiple modules are integrated;
[0029] (2) Through the automatic registration mechanism, the present invention reduces the complexity of penetration between languages, greatly reduces the workload of JavaScript developers, and improves the development efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0030] By reading the detailed description of the non-restrictive embodiments with reference to the following drawings, other features, objects, and advantages of the present invention will become more apparent:
[0031] Figure 1 To initialize the data stream;
[0032] Figure 2 To initialize the timing diagram;
[0033] Figure 3 For class function call data stream;
[0034] Figure 4 For class function call timing diagram. Detailed implementation manner
[0035] The present invention will be described in detail below in conjunction with specific embodiments. The following embodiments will help those skilled in the art to further understand the present invention, but do not limit the present invention in any form. It should be noted that for those of ordinary skill in the art, without departing from the concept of the present invention, several changes and improvements can still be made. These all belong to the protection scope of the present invention.
[0036] Embodiment:
[0037] Through the reflection mechanism of the Java language, the present invention uses dynamic analysis to automatically register the classes (including member functions) declared and implemented in the Java language into the JavaScript language dynamically, so that the objects created in JavaScript can be completely mapped to Java.
[0038] Please refer to Figures 1 to 4 , according to the penetration system between multiple development languages based on dynamic parsing provided by the present invention, including:
[0039] A class registration unit, including dynamic parsing and registration of Java class functions into the JavaScript virtual machine;
[0040] The dynamic parsing of the Java class functions is used to analyze a specific Java class to obtain the class name, the function name and function parameters modified by @JavascriptInterface, as well as the names of ancestor classes and function-related information; the function of registering into the JavaScript virtual machine sequentially registers the previously analyzed class information into the JavaScript virtual machine in the form of native callbacks after being converted by the data conversion unit. At this time, there are classes and class member functions in JavaScript that correspond one-to-one with those in Java.
[0041] The data conversion unit includes converting Java data to JavaScript type and converting JavaScript data to Java type; the conversion from Java data to JavaScript type and the conversion from JavaScript data to Java type are opposite conversion processes for data exchange between Java and JavaScript, and the corresponding relationship of numerical types is as follows:
[0042] Java type boolean int long String Array Custom Function type JavaScript type Boolean Int32 BigInt String ArrayBuffer function
[0043] The function call distribution unit includes data unpacking, Java object creation or location, and function distribution; the data unpacking means parsing out information such as function name, parameter type, and parameter value from the parameters of a JavaScript call, and then through conversion by the data conversion unit, the Java object creation or location determines the operation method according to the result of data unpacking, creates a new one or locates the corresponding Java object, and the function distribution is used to distribute the function to the member function of the located Java object and return the call result to JavaScript.
[0044] When JavaScript developers need to use functions that can only be implemented in Java at the bottom layer (taking the commonly used WebView as an example), usually a function is registered in JavaScript in advance using the Java language; in the present invention, instead of registering a single function, a Java class is registered in the JavaScript virtual machine. When a JavaScript instance is created, a corresponding Java class object and its member functions are automatically created in a one-to-one correspondence, realizing the consistency of classes and operations between JavaScript and Java. Through the automatic registration mechanism, the complexity of cross-language penetration is reduced, the workload of JavaScript developers is greatly reduced, and the development efficiency is improved.
[0045] The present invention plays a bridging role between JavaScript and Java developers, and each part of the function can be realized respectively through the commonality of the languages (classes, functions, parameters, etc.) without the foundation of the other language.
[0046] The present invention provides a penetration method between multiple development languages based on dynamic parsing, such as Figure 1 For the initialization data stream, first dynamically parse the class information in the Java virtual machine and register it, then convert the data type from Java to JavaScript, and finally load the converted data into the JavaScript virtual machine.
[0047] Such as Figure 3, for the data flow of class function calls, first obtain the class name and call method from the JavaScript virtual machine, then unpack the data in the function call distribution unit, convert the data type from JavaScript to Java, and then create or locate Java objects, distribute functions, and load them into the Java virtual machine according to the class name and call method; after software function development in the Java virtual machine, convert the data type from Java to JavaScript and then load it into the JavaScript virtual machine.
[0048] The dynamic parsing of the Java class function is used to analyze the Java class to obtain the class name, the function name and function parameters for modification, and the name of the ancestor class; registering it to the JavaScript virtual machine, converting the parsed class information, and registering it to the JavaScript virtual machine sequentially through the native callback method. The data unpacking refers to parsing the function name, parameter type and parameter value from the parameters of the JavaScript call, and then converting the data type through the data conversion unit; the Java object creation or location refers to judging the operation method according to the parameter information after data unpacking, creating a new Java object or locating the corresponding Java object; the function distribution refers to distributing the function to the member function of the located Java object and returning the call result to JavaScript. When only using the Java language for function development at the bottom layer, register the Java class to the JavaScript virtual machine. When a JavaScript instance is created, create the corresponding Java class object and its member functions at the same time.
[0049] According to the computer-readable storage medium storing a computer program provided by the present invention, when the computer program is executed by a processor, the steps of the described method are implemented.
[0050] According to the penetration device between multiple development languages based on dynamic parsing provided by the present invention, it includes: a controller; the controller includes the computer-readable storage medium storing the computer program, and when the computer program is executed by a processor, the steps of the penetration method between multiple development languages based on dynamic parsing are implemented; or, the controller includes the penetration system between multiple development languages based on dynamic parsing.
[0051] Those skilled in the art know that, in addition to implementing the systems, devices and their respective modules provided by the present invention in the form of pure computer-readable program code, it is entirely possible to logically program the method steps so that the systems, devices and their respective modules provided by the present invention are implemented in the form of logic gates, switches, application-specific integrated circuits, programmable logic controllers, embedded microcontrollers, etc. to achieve the same program. Therefore, the systems, devices and their respective modules provided by the present invention can be considered as a kind of hardware components, and the modules included therein for implementing various programs can also be regarded as the structures within the hardware components; the modules for implementing various functions can also be regarded as either software programs for implementing methods or structures within hardware components.
[0052] The specific embodiments of the present invention have been described above. It should be understood that the present invention is not limited to the above specific embodiments, and those skilled in the art can make various changes or modifications within the scope of the claims, which do not affect the essence of the present invention. Without conflict, the embodiments of the present application and the features in the embodiments can be combined with each other arbitrarily.
Claims
1. A penetration system between multiple development languages based on dynamic parsing, characterized in that, Including: Class registration unit: Dynamically parse Java class functions and register them to the JavaScript virtual machine; Data conversion unit: Mutually convert Java data types and JavaScript data types; Function call distribution unit: Perform data unpacking, Java object creation or location, and function distribution; The dynamic parsing of the Java class functions is used to analyze the Java class to obtain the class name, the function name and function parameters for modification, and the name of the ancestor class; The registration to the JavaScript virtual machine converts the parsed class information, and sequentially registers it to the JavaScript virtual machine through the native callback method; The data unpacking means parsing the function name, parameter type and parameter value from the parameters of the JavaScript call, and then performing data type conversion through the data conversion unit; The Java object creation or location means judging the operation method according to the parameter information after data unpacking, creating a new Java object or locating the corresponding Java object; The function distribution means distributing the function to the member functions of the located Java object and returning the call result to JavaScript; When only using the Java language for function development at the bottom layer, register the Java class to the JavaScript virtual machine. When a JavaScript instance is created, the corresponding Java class object and its member functions are created at the same time.
2. A penetration method between multiple programming languages based on dynamic parsing, characterized in that, Adopt the penetration system between multiple development languages based on dynamic parsing described in claim 1, and execute: For the initialization data stream, first dynamically parse the class information in the Java virtual machine and register it, then convert the data type from Java to JavaScript, and finally load the converted data into the JavaScript virtual machine; For the class function call data stream, first obtain the class name and call method from the JavaScript virtual machine, then perform data unpacking in the function call distribution unit, convert the data type from JavaScript to Java, then perform Java object creation or location, function distribution, and then load it into the Java virtual machine according to the class name and call method; After software function development in the Java virtual machine, convert the data type from Java to JavaScript and then load it into the JavaScript virtual machine; The dynamic parsing of the Java class functions is used to analyze the Java class to obtain the class name, the function name and function parameters for modification, and the name of the ancestor class; The registration to the JavaScript virtual machine converts the parsed class information, and sequentially registers it to the JavaScript virtual machine through the native callback method; The data unpacking means parsing the function name, parameter type and parameter value from the parameters of the JavaScript call, and then performing data type conversion through the data conversion unit; The creation or location of the Java object refers to determining the operation method based on the parameter information after data unpacking, creating a new Java object or locating to the corresponding Java object; The function distribution refers to distributing the function to the member function of the located Java object and returning the call result to JavaScript; When only using the Java language for function development at the underlying layer, register the Java class into the JavaScript virtual machine. When a JavaScript instance is created, create the corresponding Java class object and its member functions simultaneously.
3. A computer-readable storage medium storing a computer program, characterized in that, When the computer program is executed by a processor, the steps of the method described in claim 2 are implemented.
4. A penetration device between multiple development languages based on dynamic parsing, characterized in that, Including: A controller; The controller includes the computer-readable storage medium storing the computer program described in claim 3, and when the computer program is executed by a processor, the steps of the method for penetration between multiple development languages based on dynamic parsing described in claim 2 are implemented; or, the controller includes the penetration system between multiple development languages based on dynamic parsing described in claim 1.
Citation Information
Patent Citations
Information external network, information internal network, and system and method for data interaction between internal network and external network
CN104125240A
A system and method for data interaction between information extranet, information intranet, and extranet
CN104125240B
Binding method and device for Java function and C function
CN107239265A