When using the JavaScript adapter, E2E Bridge Base Types (excluding Any) will automatically be converted to JavaScript types. If a conversion is not possible, an exception will be thrown (see section Exception Handling).
Use the following syntax to create a JavaScript object:
var myString = aString; |
The table shows the E2E Bridge base types and the corresponding JavaScript types after conversion using the JavaScript adapter:
E2E Base Type | JavaScript Type | Additional Information |
---|---|---|
Array | Array | Nested/multidimensional arrays are not supported. Assigning arrays between JavaScript and the Bridge works both ways, but mentioned limitations are still applicable. |
Blob | The support of type Blob is limited: Blobs cannot be created, but assigned with another blob. Blobs have a toString() method, which can be called internally to convert blob to string. | |
Boolean | boolean | |
DateTime | Date | |
Float | number | |
Integer | number | |
String | string |
The basis for the conversion example are the following classes:
The input parameters contain E2E Bridge base types, the output provides the corresponding JavaScript types:
Input parameter name | Input parameter value | JavaScript Code | Output parameter name | Output parameter value | |
---|---|---|---|---|---|
aString | {aString: "Hello Bridge!"} |
| output | {aString: "HelloBridge!Hello world!", aDate: "2017-02-28", anInteger: "3", aFloat: "2.1" } | |
anInteger | {anInteger: "3" } | ||||
aFloat | {aFloat: "2.1" } | ||||
aDateTime | {aDateTime: "2017-02-28" } | ||||
anObject | {aString: "Hello world!" } |
With the JavaScript adapter, you can create objects of complex type by calling its constructor which is already included in JavaScript. The constructor is invoked with the operator new
. The constructor name is created by simply replacing the dots of the full object type (with all packages) with underscores. The full object types prefix is deleted.
Full Object Type | urn:Services.MyTypes.CustomerAddress | |
---|---|---|
Constructor Name | Services_MyTypes_CustomerAddress | |
Constructor Call | var myObject = new Services_MyTypes_CustomerAddress(); |
Please note: Using underscores in your full object types names may result in conflicts with the constructors name. For example, the constructors name of the two full object types urn:Services.MyTypes.CustomerAddress and urn:Services_MyTypes.CustomerAddress would be the same. In such cases the behavior is undefined. |
JavaScript is dynamic while the action script used in the Bridge is well-regulated. When mixing Bridge objects of complex type with JavaScript objects, the following rules apply:
Input parameter name | Input parameter value | JavaScript Code | Output parameter name | Output parameter value | |
---|---|---|---|---|---|
person | {name: "John Doe"} |
| person | {name: "James Smith" } | |
employee | {name: "James Smith", company: "E2E" } |
JSON.parse
is a JavaScript construct you can use within the JavaScript adapter.
Syntax |
| ||
---|---|---|---|
Semantics | Convert a JSON string into an object. The operation returns an object.
| ||
Substitutables | out | An object. | |
json | Any JSON string. | ||
Example |
|
Thrown exceptions will be propagate d outside the adapter as standard Bridge exceptions. All JavaScript exceptions will be reported to the Bridge as SCRIPTSM/1. They can be caught using the JavaScript statement try{} catch(){}. You can throw a user-defined exception using the
throw
statement.
The global variable session can be used to store JavaScript objects between adapter calls. The variable exists for the duration of the session (one request to the Bridge). Its purpose is to store some state between adapter calls.
Figure: Storing JavaScript objects in variable session
session.number is propagated to the second adapter call, but number is not. The value of answer will be 42.
As in Action Script (see section Map Operations), you can also use maps in JavaScript. You can build/create a map, add new elements to a map, retrieve and remove items from a map and get map entries. Maps can also be used as input/output parameters to the JavaScript Adapter.
Operation | Action Script | JavaScript | Additional Information | ||
---|---|---|---|---|---|
Creating a new map | create myMap; | var myMap = new Base_Components_Basic_Behavior_Map_Map(); | |||
Adding a new element to a map | set anObject = myMap.setMapValue("my key", "my value"); | myMap.setEntry('my key', 'my value'); | All simple types except blob can be used as key. All values except arrays and anonymous objects are allowed. (see section setMapValue() Operation) | ||
Retrieving an item from a map | set anObject = myMap.getMapValue("my key") ; | var value = myMap.getEntry('my key'); | (see section getMapValue() Operation) | ||
Removing an item from a map | set deletedObject = myMap.removeMapValue( ; | var removed = myMap.removeEntry('my key'); | (see section removeMapValue() Operation) | ||
Getting map entries | set anArray = myMap.getMapEntries(); | var mapEntries = myMap.getEntries(); | (see section getMapEntries() Operation) | ||
Building a map | set myMap = myArray.buildMap("name"); |
| (see section buildMap() Operation) |