## 3 Method
### Multi-Layer Reusable Library and Mapping Rules  
To solve RQ2, we propose a multi-layer reusable library and define the composition between the different layers, as shown in Figure 6. We model real-world scenarios with SC interactions as models based on BPMN in a manual manner, following our modeling rules. An SC may consist of one or more interaction models based on BPMN. Script tasks in the models based on BPMN bind _composite functions_ to support code generation. The composite function layer and the function layer are two reusable layers; the function layer is continuously combined to form new composite functions to support continuous changes in business logic.  
To support the process, developers must firstly complete the BPMN modeling of the multi-party interaction business scenario described in Section 3.1. Secondly, they should ensure that each task of the process of code generation has corresponding _composite functions_ in the reusable library. Otherwise, we must add new _composite functions_ to the reusable code library to support code generation. _Composite functions_ can be composed of multiple functions, and new functions must be added to the library when the functions in the reusable library do not meet the requirements.  
The methods of adding _functions_ include the following: they can be manually added by developers, or they can be added through our low-code visualization method, described in Section 3.3.  
The most important step in generating the code is parsing the models based on BPMN. The essence of analyzing the models is to analyze different tasks in the models, and the interaction relationships in the models are reflected in the application that calls the SC. There are four types of tasks in the models based on BPMN, and, in automatic code generation, different tasks are performed with different generation methods. Therefore, when modeling a business process, the developers must determine the type of each task. The four types of tasks and their corresponding code generation methods are as follows.  
1. **script-common:** This task is the current SC task and does not invoke any other task--for example, the _Cancel the insurance_ task in Figure 4. When parsing such tasks, the developers only need to form a mapping to the _composite functions_ in the reusable code library.  
Figure 6: Multi-layer reusable library structure.  
2. **script-extra-replaced:** This task is a task of the current SC and it invokes a task of an external SC--for example, the _Check validity and cancellation conditions of the insurance_ task in Figure 4. In addition to forming a mapping of the task to the _composite functions_ in the reusable code library, its parsing process also requires the introduction of the function name and address of the external SC being invoked.
3. **script-intern-replaced:** This task belongs to the current SC, and it invokes another task of the current SC. When parsing such tasks, in addition to forming a mapping to the _composite functions_ in the reusable code library, the developers also need to introduce the name of the called function. This type of task is not commonly used because functions with call relationships are usually written in a task.
4. **service:** This task is an external contract task invoked by the current SC task--for example, the _Determine whether the cancellation time limit is exceeded_ task in Figure 4. Since this type of task is an external task, we do not need to form a mapping to the _composite functions_ in the reusable code library; we only need to obtain the function name and contract name.  
The flowchart for the parsing of tasks in the model based on BPMN to generate code is shown in Figure 7.  
Figure 7: The flowchart for parsing of tasks in the model based on BPMN.