
Problem
Table of Content

1 What is Appway Script?
How to Use it:
1.1 Scopes
1.2 Data Entities
2 Implementing and Deploying Java based Functions
2.1 Function Implementation
2.2 Deploying the Function
3 Implementing and Deploying Script Function Business Objects
4 Data Class Methods
4.1 Defininition of Non-Static Class Method
4.2 Definition of a Static Class Method
5 Class Diagramm
1 What is Appway Script?
Appway Script is an object oriented, strongly typed, interpreted script language.
The language supports creation of new data classes, primitive types, functions, and class methods.
Values can be defined as single value, indexed collection (array) or named collection (map).
Read the Expression Language document for more details about the expression language itself. The main business objects related to the script language are Data Classes and Primitive Types and Script Functions.
Script Functions may be implemented as Appway Scripts via the Script Function Business Object in the Appway Studio or as Appway SDK Java function implementations deployed via extensions.
Functions implemented in Java may register a ScopeFinalizer which provide a mechanism that allows a function implementator to register cleanup functions in a scope.
SDK Developers may execute scripts using Appway API. The document How To Execute Appway Scripts explains how to create and use a script interpreter.

Solution

Variables and their values are defined and stored in scopes. The scopes used during evaluation of a script build a chain where each scope of the chain is connected to a parent scope. During execution the execution context keeps track of the current top level scope.

Figure 1: Scope and ExecutionContext
Let's assume we start a process. Currently there is a workitem waiting at screen A. The scope chain for the screen context looks like this

Figure 2: Scope Chain
An execution context built for a script in the process screen A will see the above scope chain. Variables and their values will be searched starting at the Screen scope going upwards until the variable is found or there is no more parent scope to search.

Figure 3: Scope Variables
There are 3 cases to be distinguished:
- Local variable, found at the local scope.
For example searching for variable $c in above example will find the variable and its value in the Screen scope. - Inherited variable, found in a parent scope.
For example searching for variable $a in above example will find the variable and its value in the WorkflowInstance scope. - Shadowed variable, found in more than one scope in the scope chain.
For example searching for variable $b in above example will find the variable in the top level Screen scope. The same variable name is also defined in the WorkflowInstance scope.
The definition in the Screen scope will shadow the definition in the WorkflowInstance scope. Appway always returns the definition/value that is first found when traversing the scope chain from bottom to top.
1.2 Data Entities
Data Entities are single instances or collections of data classes and primitive types.

Figure 4: Data Entity Relations
2 Implementing and Deploying Java based Functions
Appway Script may be extended with new functions that are implemented in Java. The advantages of using this approach are:
- There is only one version of the function in the system. All processes which use the function use the same version independent of the version filter used to start the process.
- The function serves as a wrapper for Appway SDK functions used in scripts. Changes to the Appway SDK might require recompilation of the function source code and deployment of a new extension version. The solution itself will still be working with new versions without modifications.
- Depending of the complexity of the function, execution speed might be higher than function implementations using the Appway Script language.
2.1 Function Implementation
Java implemented Functions deployed via extensions have to extends the AbstractFunction class.
The implementation needs to define the function parameters and the abstract calculate method.
2.2 Deploying the Function
At extension startup the function must be registered with the ExpessionLanguageService.
At extension shutdown the function must be deregistered.
3 Implementing and Deploying Script Function Business Objects
The following is an example how to insert or upate a script function Business Object using Appway SDK functions.
4 Data Class Methods
Data Classes may have methods just like in other Object Oriented languages.
Methods can be static or non-static
4.1 Defininition of Non-Static Class Method
The default method visibility is non-static. The non-static method definition looks like a standard script function definition inside a Data Class.
Class properties can be accessed using the implicit variable $this. The superclass can be accessed using the implicit variable $super.
Eventhough the Studio Data Class editor allows to define multiple super classes for a data class $super only allows access to the FIRST class found in the super class list

Figure 5: standard method
4.2 Definition of a Static Class Method
The static method definition uses StaticFunction keyword in the definiiton script.
Figure 6: static method
5 Class Diagramm


Comments (0)