How Do I: Use ECMAScript (JavaScript) to Process XML Messages?

Sometimes the transformations needed to process incoming or outgoing XML messages are more complex than you can accomplish with static XML maps. In these cases, you can use WebLogic Workshop's extended version of ECMAScript to perform XML mappings. To do so, you must first create a script file (with a JSX extension) in your project to hold the script.

To Create a Script File

1. Click the File menu, point to New, then click New JavaScript File. The Create New File dialog appears.

2. Confirm that JavaScript is selected.

3. In the File name field, type a name for the new script file.

4. Click OK.

The newly created JSX file contains two functions, named myScriptFromXML and myScriptToXML. These are used to map from XML to Java types and to XML from Java types. The newly created JSX file also contains some rudimentary instructions about how to use the script from a map.

From within a map, script may be called by using the following syntax:

    {ScriptFileName.myScript(parameters)}

Notice that the function name in the call does not include "ToXML" or "FromXML". The appropriate method in the JavaScript file is determined automatically based on the direction of the mapping being performed.

parameters will depend on whether you are mapping the parameters or the return value of your Java declaration. If you are placing the call to script in a parameter-xml map, parameters should be the arguments of the method or callback that you would like this script method to populate. If you are placing the call to script in a return-xml map, you should simply enter "type return” where type is the method or callback's declared return type.

Related Topics

Handling XML with ECMAScript Extensions
Handling and Shaping XML Messages with XML Maps
How Do I: Create and Invoke a Script for Use with XML Messages?