Composer User's Guide

CHAPTER 7

Basic Actions

Up to this point, you've learned how to create XML templates and an XML Map component that uses templates for inputs and outputs. Now it's time to learn about the actual work that takes place. This is where the action is.

NOTE:   This chapter defines the basic actions available within the XML Map component. The next chapter covers more powerful actions and Applying Actions to Common Tasks covers detailed examples of using some of these actions.

 
Top of page

What is an Action?

An action is similar to a programming statement in that it takes input in the form of parameters and performs specific tasks. For instance, the Send Mail action sends an e-mail when you supply the recipient's e-mail address as one of the parameters.

Before looking at individual actions, you should first understand exteNd's Action Model. You may remember an earlier discussion that a component is a set of instructions for processing XML documents or communicating with non-XML data sources. This set of instructions is called an Action Model. In Composer, an Action Model performs all data mapping, data transformation, and data transfer within components and services.

An Action Model is made up of a list of actions. All actions within an Action Model work together. As an example, the Action Model for a component might read invoice data from a disk, retrieve the e-mail addresses from the invoices, and send e-mail messages to notify the recipients that their invoices were received.

The Action Model mentioned above would be composed of several actions. These actions:

 
Top of page

Using Composer Actions

Composer provides actions with the basic XML Map component. These actions are also available for all other component types, such as JDBC Components, JMS Components, etc. Actions are grouped on the Action menu as Basic Actions and Advanced Actions. The following table lists the suite of basic actions available in Composer. The Advanced Actions are described in the next chapter.

Basic Action

Description

Comment

Documents the Action Model. You can use comments to clarify the processing, especially if Decisions and/or Repeats are used in the Action Model.

Keyboard shortcut: Ctrl-E

Component

Executes another component or service and defines runtime DOMs to be passed to, and received from the called component.

Keyboard shortcut: Ctrl-T

Decision

Allows you to execute one of two sets of actions based on a condition you specify. Processing branches along a True or False path, depending on how your condition is resolved as the component executes.

Keyboard shortcut: Ctrl-D

Declare Alias

Allows you to assign an arbitrary label to any XPath, for convenience purposes. The label expands to the full XPath at runtime or animation time.

Function

Executes either an ECMAScript script function or a custom script you have previously created. You can create custom scripts using Composer's Custom Script Resource Editor.

Keyboard shortcut: Ctrl-U

Log

Writes information to various log files specified in the component. There are three Log types: System Output, System Log, and User Log.

Keyboard shortcut: Ctrl-L

Map

Transfers and optionally transforms element data from one XML DOM to another.

Keyboard shortcut: Ctrl-M

Send Mail

Automatically sends an e-mail to a specified e-mail address during execution of the component.

Switch

Allows program control to branch to a particular block of actions based on a match between an input value and a Case value. This is essentially a convenience action that can be used to eliminate long, hard-to-read if/else (Decision action) chains.

Todo

Gives you a place to maintain a Todo list that organizes and tracks your tasks.

 
Top of section

Creating an Action

There are four methods for creating a new action:

In all cases, you must have the component open before you can create an action.

Procedure To create an action using the Action menu:

  1. Open a component.

  2. Click the mouse on (that is, highlight or select) a line in the Action Model just above the place where you want a new action. The new action will be inserted below the line you selected.

  3. From Composer's Action menu (main menubar), select New Action and then the type of action you wish to create.

    ActionMenus

  4. If a dialog appears, type or select parameters pertinent to the action, as required. (These are described individually in subsequent topics. See below.) Then dismiss the dialog, as applicable.

Procedure To create an action using the Context menu:

  1. Select a line in the Action Model where you want to place the action. The new action will be inserted below the line you select.

  2. Click the right mouse button to display the Context menu:

7actionContextMenu

  1. Select an action from the Context menu.

  2. Interact as necessary with any dialogs that appear.

  3. Dismiss the dialog(s).

Procedure To create an action using a shortcut key:

  1. Select a line in the Action Model where you want to place the action. The new action will be inserted below the line you select.

  2. Create your new action by pressing the key combination indicated in the table above. For example, pressing Ctrl-L will add a Log action to your model.

Procedure To Cut, Copy, or Paste an action:

  1. Select (click on) the action in the Action Model pane.

  2. Choose Cut, Copy, Paste, or Delete, as appropriate, from the Edit menu in the main menubar, or from the context menu available via right-mouse-click.

  3. Type Control-Z (or choose Undo from the Edit menu) if you want to undo the operation.

In addition to adding actions, you can edit existing actions and disable actions within an Action Model. When you disable an action, it does not execute, but it remains in the Action Model, and you can enable it at a later time.

Procedure To edit an action:

  1. Doubleclick any action in the Action Model and edit it.

  2. Alternately, you can select the action in the Action Model pane.

  3. From the Action menu, select Edit. A dialog box for the action type appears.

  4. Make any necessary changes to the action.

  5. Click OK.

Procedure To disable an action:

  1. Select the action in the Action Model pane.

  2. From the Action menu, select Disable. The action is grayed out.

  3. Repeat steps 1 and 2, selecting Enable, to enable the action again.

The rest of this chapter describes each basic action and gives examples on how to use them.

 
Top of page

The Comment Action

You can use the Comment action to document your Action Model and clarify the processing that takes place. You can add comments anywhere within an Action Model. They perform no processing of their own.

Procedure To add a Comment action:

  1. Open a component.

  2. Select a line in the Action Model where you want to place a comment. The new comment is inserted below the line you selected.

  3. From the Action menu, select New Action, then Comment, or press Ctrl-E. The Comment dialog appears.

    7comment01

  4. Type your comment.

  5. Click OK.

 
Top of page

The Component Action

The Component action calls and executes another component or service with runtime inputs and outputs that you specify. You can call any component in your project. To call another component, you must specify four parameters to the action:

The Component Type is simply the category of component you wish to call. The component types do not correspond to those listed in the Composer Category pane under the Component heading. The following strings are valid values and are case sensitive:

depending on whether or not you have the Connect installed that implements that Component Type.

The Component Name is the name of the component you wish to call or target component. The Component Name must be one that exists within the Component Type you select.

The Passed ID are document names within the current component or service. You can specify none, one, or more documents to pass into the target component. The document names you specify here will be passed into the target component as its Input documents.

The Returned ID is the name of a document within the current component or service that will receive the results of the target component. You can use the name of an existing document or force the creation of a new document by specifying a name that does not already exist.

You can specify these parameters in one or two ways: Predefined or Dynamic. A Predefined Component action populates the four parameters with values derived from the current state of the project. Once specified, these values remain fixed for all executions of the action unless you manually change them. A Dynamic Component action populates the four parameters at runtime with values calculated from expressions you create. This allows the Component action's behavior to be flexible and vary based on runtime conditions each time it is executed. One Component action can execute a different component depending on various runtime conditions, or pass in different Input documents, or receive results into different result documents.

Procedure To add a Predefined Component action:

  1. Open a component.

  2. Select a line in the Action Model where you want to place a call to a component. The new action is inserted below the line you selected.

  3. From the Action menu, select New Action, then Component, or press Ctrl-T. The Component dialog appears.

  4. Select Predefined, by clicking on the radio button, if it is not already selected.

    7Componentpredefined

  5. Select the relevant Component Type from the drop down list.

  6. Select a Component Name to execute (the list of Components is context sensitive to the Component Type selected).

  7. In the Passed ID field, select a source component DOM.

  8. In the Returned ID field, select the source DOM into which the called component will return its Output. If you wish to create a new DOM, you may type the name in the Returned ID field.

  9. Click OK.

Procedure To add a Dynamic Component action:

  1. Open a component.

  2. Select a line in the Action Model where you want to place a call to a component. The new action is inserted below the line you selected.

  3. From the Action menu, select New Action, then Component, or press Ctrl-T. The Component dialog appears.

  4. Select Dynamic, by clicking on the radio button, if it is not already selected.

  5. Create an ECMAScript expression that evaluates to one of the following valid Component Types: map, service, JDBC, 3270, 5250, CICSRPC, JMS, HTML

    NOTE:   A Component Type will only be valid if the Connect implementing that Type is installed in your version of Composer.

    7componentdynamic

  6. Create an ECMAScript expression that evaluates to a valid component or service name in your project.

  7. Create an ECMAScript expression that evaluates to a valid document ID at runtime in the current component or service. This document will be passed to the target component or service as its Input document. If passing more than one document, the expression must evaluate to a single string containing a comma-separated list of document IDs (e.g. Input, Input 1, Temp, MyDoc).

  8. Enter an ECMAScript expression that evaluates to a document ID that will receive the results of the target component.

 
Top of page

The Decision Action

The Decision action creates an if. . . then branching between actions or group of actions. You use a Decision action to select one branch or another, based upon a condition you supply. The condition must use an ECMAScript comparison operator, such as = =, <, >,!, >=, <=, (&), OR (||), or <>. The expression must resolve to the Boolean true or false statement. For instance, you can check to see if an invoice is older than a certain date and send an e-mail if it is.

Procedure To add a Decision action:

  1. Open a component.

  2. Select a line in the Action Model where you want to place the Decision action. The new action is inserted below the line you selected.

  3. From the Action menu, select New Action, then Decision, or press Ctrl-D. The Decision dialog appears.

  4. Type the expression using any of the ECMAScript comparison operators or click the Expression Builder button and create a Decision script (ECMAScript expression) that will evaluate to true or false at runtime.

  5. Click OK. The Action Model displays the following Decision action, which tests for the existence of an INVOICE node.

    7DecisionResultinActionModel

  6. In the Action Model pane, select the TRUE icon.

  7. Add one or more actions that will execute if the expression is true. you can, of course, cut/copy actions via drag and drop from outside the true branch to within the true branch.

  8. Select the FALSE icon.

  9. Add one or more actions that will execute if the expression is false.

You can nest other Decision actions inside the TRUE and/or FALSE branches of the Decision action. The following illustration shows a complete decision in the Action Model pane.

7decision02

 
Top of page

The Declare Alias Action

The Declare Alias action allows you to apply your own arbitrary custom label to a given XPath expression (valid within the scope of a given action model). You would use this action to make your action model more readable and save typing.

Procedure To add a Declare Alias action:

  1. Open a component.

  2. Select a line in the Action Model where you want to place the Declare Alias action. The new action is inserted below the line you selected.

  3. From the Action menu, select New Action, then Declare Alias. The Declare Alias dialog appears.

    7DeclareAlias

  4. Type the name you intend to use in the Alias text field.

  5. Choose either the XPath or the Expression radio button.

  6. If you have chosen the XPath radio button, select a target DOM (representing the document containing the target XPath) from the dropdown menu. Then enter the XPath to the target node in the text field below.

  7. If you have chosen the Expression radio button, type the appropriate ECMAScript representation of the target XPath in the text field, or click the Expression Builder icon (to the right of the text field) and use the Expression Builder pick-lists to build an expression.

  8. Click OK. The new action is added to your action model

In the above example, the Input Part has a node called SHOW_PRODUCT/LIST_PRICE. Rather than type $Input/SHOW_PRODUCT/LIST_PRICE repeatedly throughout the action model, one could, for convenience, assign an alias (an arbitrary name) to the XPath expression. In this case, the alias "aPrice" has been assigned to $Input/SHOW_PRODUCT/LIST_PRICE. From this point on, throughout the action model, one can use "aPrice" instead of $Input/SHOW_PRODUCT/LIST_PRICE. At runtime, the alias will be expanded to the complete XPath.

 
Top of page

The Function Action

The Function action executes either an ECMAScript function or a custom script function you have already created in the Custom Script Resource Editor. To manipulate a DOM element, the script you call in the Function action must reference a fully qualified DOM element name in the current component.

Custom Script functions you create and add to an Action Model can act upon any XML tree element. For instance, you can create a function that changes the format of a date element. You can create a function that performs a math function on the contents of an element. You can also perform file system, database, or URL functions that have no interaction with a Message Part. The Function Action can also be used to call Java methods that you have registered in the Custom Script Resources. This gives an ability to visually integrate complex (and simple) Java processing directly onto the Action Model.

Procedure To add a Function action:

  1. Open a component.

  2. Select a line in the Action Model where you want to place the Function action. The new action is inserted below the line you selected.

  3. From the Action menu, select New Action, then Function, or press Ctrl-U. The Function dialog appears.

    7Function130

  4. Type the function in the Function Call field or click the Expression Builder button to build an ECMAScript expression (discussed below). Function calls are case sensitive. Also, if the function requires parameters, make sure to include them in the function call.

  5. Click OK. Alternately, you can click on the Apply button to see the affect of the Function action without closing the dialog. This allows you to make repetitive edits to a Function action quickly see the results.

Procedure To use the Expression Builder:

  1. Add a new function action as described in the previous section.

  2. Click the Expression Builder button to open the Function Expression Builder dialog.

  3. Doubleclick variables, functions/methods, or operators to insert them into the function. You can also type directly into the function.

    NOTE:   Make sure the function follows ECMAScript standards or it will not compile or run correctly. It is usually more efficient to create functions within a Custom Script resource and test them before using them. When creating a Function action, you can simply refer to the Custom Script function name and supply it any parameters.

  4. Click Validate to verify the script before saving it.

  5. Click OK to save the script.

  6. Click OK again to add the function action.

NOTE:   Since ECMAScript is an interpreted language, Validate doesn't check any runtime dependent expressions other than to see if they conform to valid ECMAScript syntax.

 
Top of page

The Log Action

Log actions are designed to provide customizable reporting capabilities (design-time as well as runtime) for Composer applications. You can exercise fine control over the degree of reporting desired, by the use of Log Level settings (see further below); Log Actions needn't simply be turned "on" or "off."

Some examples of where the Log Action might be used are:

 
Top of section

Log File Locations

The Log action writes information to any of various locations external to Composer and exteNd Composer Enterprise Server. The actual locations are specified by the action. There are three locations for log output: System Output, System Log, and User Log (see below).

System Output

The System Output option writes out messages you specify in the Log Expression field to the Java Virtual Machine process window at design time or the Application Server console at runtime.

To create a Log message you can write any valid ECMAScript expression or use the Expression Builder to generate a Log Expression. Each message logged is preceded by a Date/Time stamp and the Component doing the logging. These messages also appear in the Message frame of the main Composer window.

System Log

The System Log option writes out messages you specify in the Log Expression field to the filename specified in the <LOGFILE> element of the Composer configuration file: xconfig.xml. You can change the name and location of the log file from the Composer Tools menu by selecting Tools > Preferences from the Composer menubar and going to the General tab.

User Log

The User Log option writes out messages you specify in the Log Expression field to a file you specify in the User Log File field of the Log Action dialog (see below).

To create a Log message, you can enter a static string or write any valid ECMAScript expression (or use the Expression Builder to generate a Log Expression). The results of the Log Expression will be written out to the Log as text. Each message logged is preceded by a Date/Time stamp and the Component doing the logging.

To create a User Log File you can also write any valid ECMAScript expression to generate the file name, click the Expression Builder button to use the Expression Builder.

 
Top of section

Log Priority Levels

Individual Log Actions can be assigned priority levels (from 1 to 10). At runtime, a Log Action's priority level is compared against a reporting threshold value which you set in the General tab of the Preferences dialog under the Tools menu. Any Log Action whose priority is equal to or greater than the reporting threshold will be executed (that is, its message will be logged to system output or to disk, as appropriate), while Log Actions of lower priority will not have their messages reported.

Priority levels for individual Log Actions can be set in the Log Action dialog. The reporting threshold is set in the General tab of the Preferences dialog (as explained below). Once a threshold value is set, only Log Actions of equal or greater priority will execute. For example, if Log Action A has a priority setting of 4 and Log Action B has a priority of 9, and the threshold setting in the Preferences dialog is 8, then at runtime only Log Action B will execute. Log Action A will be ignored.

NOTE:   The reporting level can also be adjusted after deployment of your project, via the exteNd Composer Enterprise Server console screen. Consult your Composer Enterprise Server documentation for details.

Procedure To set the reporting threshold for logging:

  1. Go to the Tools menu, then choose Preferences. The Preferences dialog appears.

    3ToolsConfig

  2. In the General tab, set the Log Threshold to a value from 1 to 10. The value you set here is a threshold value, which means that only Log Actions with a priority equal to or greater than this value will execute.

  3. Click OK to dismiss the dialog.

Procedure To create a Log action:

  1. Open a component.

  2. Select a line in the Action Model.

  3. From the Action menu, select New Action, then Log, or press Ctrl-L. The Log dialog appears.

    8log01

  4. In the Log to radio group, choose the location to which you want messages written. (See explanation of locations further above.)

  5. Use the Log Level spin control to select a priority level (1 to 10) for this Log action. The default is 5. In general, you should assign high numbers to messages with high importance. The priority you assign here will be ompared to the threshold number you chose in the last section (see further above). If the priority is equal to or greater than the threshold, the message is logged; otherwise it is not.

  6. Enter a String or ECMAScript expression in the Log Expression text field. (You can use the Expression Builder—accessed by clicking the small icon to the right of the text field—to build an expression via pick-list selections).

  7. Check Clear the Log File if you want the data in the log file to be cleared each time the component is executed.

More information about log files can be found in Viewing System Messages.

 
Top of page

The Map Action

The Map action is a DOM-node input/output mapping. It transfers (and optionally, transforms) data from one document context to another document context. A context has two parts. The first part usually identifies a DOM and the second part identifies a location within the DOM. The basic document context in Composer is expressed as a DOM name combined with an element location (referred to as a location) identified through an XPath expression. The DOM name is usually Input, Input1, Input(n), Temp, Output, or any named DOM you have loaded in the component. The XPath expression identifying a location in a DOM has the path elements delimited by "/".

NOTE:   A context in Composer can also be a Group name that itself is simply an alias or short-hand for an XPath expression.

 
Top of section

About XPath and ECMAScript Expressions

When you create a Map action, you can choose between two methods for addressing locations in XML Documents: XPath and ECMAScript. The default choice is XPath, and it is the basic method of addressing.

The Basic Method: XPath by Itself

The primary purpose of XPath is to address or locate parts of an XML document (i.e., elements and attributes). XPath also provides basic facilities for manipulation of strings, numbers and booleans through a simple expression syntax. XPath addresses message Part nodes, including element nodes, attribute nodes and text nodes.

XPath is based on pattern matching. You specify a pattern of element names that resolve to the nodes in the target document. Most of the time, XPath returns a node list containing the particular nodes that match your pattern. (Many XPath expressions return only one node, but it is very common to return multiple nodes.) Other times, XPath can return a primitive value (string, number, or boolean).

In all Composer dialogs that take an XPath expression, you can build the expression with the aid of pick-lists in an Expression Builder. (See "To build an expression using ECMAScript:" further below.)

The complete XPath specification can be seen at http://www.w3.org/TR/xpath.

NOTE:   The XPath spec is also available under the \Doc directory of your Composer installation.

The Alternative Method: XPath within ECMAScript

The second method to address locations in DOMs is to use ECMAScript with XPath. Choose this method if you wish to go beyond strict XPath addressing. ECMAScript is an object oriented scripting language for manipulating objects in a host environment (i.e., Composer). ECMAScript (ECMA-262 and ISO/IEC 16262) is the standards-based scripting language underpinning both JavaScript (Netscape) and JScript (Microsoft). It is designed to complement and extend existing functionality in a host environment such as Composer's graphical user interface. As a host environment, Composer provides ECMAScript access to various objects (including DOM objects) for processing. ECMAScript in turn provides a Java-like language that can operate on those objects.

Composer's built-in ECMAScript interpreter recognizes a custom Composer method called XPath(). It allows expressions such as:

  Input.XPath("Inventory/Books/Engineering")

Construction of this type of expression is greatly facilitated by the user of Composer's Expression Builder facility. (See "To build an expression using ECMAScript:" further below.)

 
Top of section

Adding a Map Action

Procedure To add a Map action:

  1. Open a component.

  2. Select a line in the Action Model where you want to place the Map action. The new action is inserted below the line you selected.

  3. From the Action menu, select New Action, then Map, or press Ctrl-M. The Map dialog appears.

    7MapAction124

  4. The Source type is XPath. Select a Part (Input, Output, or Temp) from the pulldown menu, then type the appropriate XPath expression, locating the element you want.

    NOTE:   Alternatively, you can click the Expression Builder to have Composer assist you in building the XPath expression. See Using the XPath Expression Builder.

    Together, the Part name and XPath specify the Source context for the Map action.

  5. Repeat steps 4 and 5 for the Target.

  6. Under Options, in the middle of the dialog, check Content Editor and/or Code Table Map and/or Advanced to exercise finer control over the mapping.

    NOTE:   More information on the Content Editor and Code Table Map option is available in Transforming Elements. A discussion of Advanced options appears below. Note that you will

  7. Click OK. The Map action appears in the Action Model pane as shown.

    NOTE:   You can press the Apply button to see the affect of the Map action without closing the dialog. This allows you to make repetitive edits to a Map action and quickly see the results.

    7newmap03

Default Mapping Behavior

When you use the Map action to map elements and attributes within XML Documents, certain default behaviors occur. The following table lists those default behaviors.

Map Type

Default Behavior

Leaf Element to Leaf Element

Transfers the element data only.

Leaf Element to Branch Element

Transfers the element data only.

Branch Element to Leaf Element

Transfers the entire branch including all child elements and attribute data under the branch.

Branch Element to Branch Element

Transfers the entire branch as above after removing the target's current branch.

A particular Leaf Element in a list of Leaf Elements, to Element

Transfers the element data from the selected leaf (or element instance) to the target element.

Attribute to Attribute

Transfers the attribute data only.

Element to Attribute

Transfers element data to attribute data.

Attribute to Element

Transfers the attribute data only.

Many of these behaviors can be altered, on an action-by-action basis, through the use of options exposed in the Advanced mapping dialog (see next section).

Leaf Elements that Contain Markup

A special situation can arise when an element is populated at runtime by a Java or ECMAScript operation. It's possible that the element might receive data that contains markup—in other words, strings with illegal characters, such as < and >. This presents a mapping challenge, in that if Composer were to merely map the raw contents of such an element, unchanged, to a node in the Output DOM, the output document would be malformed.

Composer resolves this issue by mapping any data that contains markup to a CDATA section created on-the-fly in the target document.

NOTE:   A somewhat different behavior applies at design time, when markup is entered by hand. At design time, if you type markup data into a node (via right-mouse-click/Edit Data), the markup characters are entitized on the fly. If you examine the raw XML in Text View, you'll see that any '<' characters entered by hand are converted to &lt; (and so on). The entitized data are then mapped directly to output.

 
Top of page

Advanced Mapping Options

When the Advanced checkbox is checked in the Map Action Dialog, the following dialog appears. Note that the options you set in this dialog affect only the current Map Action; not subsequent ones.

7AdvancedMapPrefs

The options in this dialog give you finer control over how input Part nodes are mapped to the output Part.

Copy Attributes

This grouping of controls allows you to specify how attributes are mapped. Three radio buttons appear under this grouping.

Deep Copy

By default, Composer maps whole branches at a time (that is, the target node plus all of its children). In some cases, you may want to turn off this "deep copy" behavior so that you can copy just the parent element without its children. Uncheck the checkbox labelled "Map the Dependents" if you want to disable Composer's standard deep-copy behavior.

Create Target

The Create Target option allows you to optionally create the destination node (or branch) that you specified under Target in the Map Action dialog, based on whether or not the source node (or branch) is present in the source DOM. The default behavior is that Composer always creates the target, whether or not the runtime source DOM contains the node(s) that you specified in the Source XPath for mapping.

For example: In the Map Action dialog, you may have specified a Source XPath that looks like

  $Input/Root/MySourceElement

while under Target, you may have specified something like

  $Output/Root/MyParentNode/SomeOtherElement

If the arriving Input document doesn't have a node corresponding to Root/MySourceElement, Composer will (by default) nevertheless create an empty Root/MyParentNode/SomeOtherElement node in the output DOM. In some cases, this might not be what you want. Using the radio buttons in the Advanced Mapping dialog, you can change the default behavior.

NOTE:   The Create Target options are disabled if Code Table Map was selected in the Map Action dialog.

The options under this radio button grouping are:

Create Target as CDATA Section

This radio-button group allows you to control the way element data gets mapped into CDATA sections. The options are:

Using the XPath Expression Builder

When you are in the Map Action dialog, you can build your own XPath expressions by choosing the Expression Builder button at the far right of the appropriate text field. The XPath Expression Builder dialog that appears will display pick-lists to help you construct valid XPath syntax in point-and-click fashion. This can be especially handy when you wish to go beyond basic XPath addressing and use some of the more powerful features of XPath.

exteNd Composer uses the XPath addressing syntax adopted by W3C. The XPath syntax is similar to URI address syntax in basic appearance but includes many subtle and powerful features for addressing and manipulating XML. Some of the more common syntax rules are listed in the following table.

XPath Syntax

Description

/

The single forward slash represents an absolute path to an element. /ABC selects the root element ABC.

//

Double slashes represents all elements in a path. //ABC selects all occurrences of ABC. //ABC//DEF selects all DEF elements which are children of ABC.

*

The asterisk selects all elements located by the preceding path. *ABC/DEF selects all elements enclosed by elements ABC/DEF. //* selects all elements.

[ ]

Square brackets specifies a particular element. /ABC[3] selects the third element in ABC. This can also be used as a filter (similar to a Where clause in SQL). //ABC["Table"] selects all elements that have the content "Table."

@

The At sign selects elements with a specified attribute. /ABC@name selects all elements in ABC that have an attribute called name.

|

The vertical bar allows you to specify multiple paths. //ACB|//DEF selects all elements in ACB and in DEF.

$

The dollar sign allows you to reference other documents besides the current one. INVOICEBATCH/INVOICE[SELLER/NAME=$PROJECT/USERCONFIG/COMPANYNAME]

function()

XPath has numerous functions that you can add to your XPath addresses. For instance, //*[count(*)=2] selects all elements that have two children.

math operator()

XPath has numerous math operators that you can add to your XPath addresses. For instance, /ABC|position() mod 2 = 0] selects all even elements in ABC.

The complete list of operators can be seen at http://www.w3.org/TR/XPath.

Procedure To build an expression using XPath

  1. Open a component.

  2. Select the Map action from the Action menu.

  3. Ensure that the XPath radio button is selected.

  4. Click the Expression Builder button. The Source XPath dialog displays.

    7sourceXpath

  5. Create an expression by doubleclicking on the items from the panes.

  6. Verify that your expression's syntax is correct (using the Validate button).

  7. Click OK.

Using the ECMAScript Expression Builder

When you select the ECMAScript radio button in the Map action, the ECMAScript Expression Builder appears and helps you construct valid ECMAScript syntax. This is desirable when you want to go beyond strict XPath addressing and use some of the more powerful features of Composer's ECMAScript addressing.

The illustration below shows the ECMAScript Expression Builder.

7sourceexpression

Objects in the pick-lists are ordered with most frequently used objects first. All properties and methods for an object are also ordered. Properties are always listed first alphabetically, followed by all the object's methods alphabetically.

All of the items in the Functions/Methods pick-list and the Operators pick-list have tool tips associated with them. To view a tool tip, simply hover your cursor over the item you'd like to know more about. If you hover your cursor over the items in the Variables pick-list, data associated with that item will be displayed.

NOTE:   While you can create complex ECMAScript expressions, they must evaluate to a document context consisting of a DOM and an address within the DOM.

Procedure To build an expression using ECMAScript:

  1. Open a component.

  2. Select the Map action from the Action menu.

  3. Select the radio button next to Expression.

  4. Click the Expression Builder button. The Source Expression dialog displays.

    7sourceexpression

  5. Create an expression by doubleclicking on the items from the panes.

  6. Optionally click Validate to verify that your expression's syntax is correct. (This does not execute the expression. The expression is merely parsed.)

  7. Click OK.

 
Top of page

The Send Mail Action

The Send Mail action creates and sends e-mail messages dynamically during the execution of a component. When you create a Send Mail action, you specify the various parameters needed in order for Composer to know where and how to send the e-mail. The parameters can be hard-coded or (alternatively) ECMAScript expressions that evaluate at runtime.

Some possible uses of the Send Mail action include:

The e-mail you send with the Send Mail action can have attachments of any arbitrary MIME type. Also, various Send Mail actions can use various mail servers (with or without user name and password).

 
Top of section

Mail via SMTP Simple Authentication

Although some in-house mail servers might not require a user name or password for outbound mail, many SMTP servers issue an authentication challenge before granting access. If your Send Mail actions will be using a mail server that requires user ID/password authentication, you will need to create a Mail Simple Authentication connection resource. This resource simply stores the network address for the mail server you want to use, along with a user name and password. The resource, once created, can be reused by any number of components and/or services within your project.

It's worth noting that you are not required to create one Mail via SMTP resource for each server (or for each user name and password combo) you intend to use. All parameters in the Mail via SMTP connection resource can be indirected through ECMAScript, so that server names or user credentials (or both) are late-bound— perhaps obtained by lookup from a directory or database, at runtime. Using ECMAScript, you can apply your own business logic to decide which mail server (or which credentials) to use in a given circumstance at runtime.

NOTE:   See the discussion at "About Constant vs. Expression Driven Connections" (in the chapter on Resources) for additional information on how ECMAScript can be used for late binding of connection-resource parameter values.

Procedure To create a Mail Simple Authentication connection resource:

  1. Under Resource in the navigation (explorer) frame, right-click on Connection and choose New from the context menu as shown below:

    7SendMailSMPTResource

  2. In the wizard pane that appears (see below), enter an arbitrary Name for this connection resource and (optionally) descriptive text.

    7SMPTConnection1

  3. Click Next. The second (and final) panel of the wizard appears:

    7SMPTConnection2

  4. Using the pulldown menu control, select Mail via SMTP Simple Authentication as the Connection Type.

  5. Next to SMTP Server, enter the name or IP address of the mail server you intend to use.

  6. Next to User ID, enter the user name associated with the mail account you wish to use.

  7. Next to Password, enter the password associated with the user account in question.

    NOTE:   Again, note that any of these parameters may be entered as ECMAScript expressions. See the discussion at "About Constant vs. Expression Driven Connections" (in the chapter on Resources) for additional information on using ECMAScript here.

  8. Click Finish.

 
Top of section

How to Create a Send Mail Action

Procedure To create a Send Mail action:

  1. Open a Component.

  2. Select a line in the Action Model where you want to place the Send Mail action. The new action will be inserted below the line you select.

  3. From the Action menu, select New Action, then Send Mail. The Send Mail dialog appears. Note the presence of three tabs: Message, Server, and Attachments.

  4. Select the Message tab if it is not already selected.

    8email01

  5. In the Mail Recipient field, type an ECMAScript expression to specify the e-mail address of a recipient. The expression should evaluate to a string of the general form name@domain.extension. If you are hard-coding a string value, make sure the text is enclosed in quotation marks.

  6. In the Mail Sender field, enter an ECMAScript expression to specify the string you wish to show as the sender's e-mail address. (It can be any arbitrary string; it does not have to be an actual e-mail address.) Again, if you are hard-coding a text value, make sure the text is enclosed in quotation marks.

  7. In the Mail Subject field, type a valid ECMAScript expression to specify the e-mail subject or type a subject line. Again, if you are hard-coding a string, make sure the text is enclosed in quotation marks.

  8. In the Mail Body field, type a valid ECMAScript expression to specify the e-mail body text (or type the body text enclosed in quotation marks).

  9. Under Encoding, specify (using the pulldown menu) the type of encoding your message should use. The default is ASCII.

  10. Select (click on) the Server tab. The dialog changes appearance:

    7SendmailServerTab

  11. Click the Mail Server radio button if you wish to specify an ECMAScript expression that will resolve to your mail server's address (as shown above). Alternatively, click the Connection Name radio button if you wish to use a server that has been specified in a "Mail via SMTP Simple Authentication" connection resource. (See the discussion of this resource type at "Mail via SMTP Simple Authentication" earlier in this section.) You would use the latter option in cases where user authentication (via username and password) is required in order to access the server.

  12. If you want to include attachments with the e-mail, click the Attachments tab. (Otherwise, click OK to return to the component editor.) The dialog changes appearance:

    7SendMailAttachmentsTab

  13. Click the plus-sign (+) button to add an attachment.

  14. Under Type, specify String or URL (using the pulldown menu control).

  15. Under Content-Type, specify the MIME type of the attachment. You can either choose from the MIME types shown in the dropdown menu, or you can enter your own MIME type in the editable field.

  16. Under Attachment, enter the ECMAScript expression that will serve as the attachment content (if you chose String under Type) or as the URL to the file you wish to send. In the example above, the first attachment is a String consisting of the data associated with the /message node of the component's Input document. The second attachment (a JPEG image) specifies a URL string contained in the previously declared ECMAScript variable named "image." The variable in question could resolve at runtime to something like "file:///d:/server-1/resourcestore/images/stockimage.jpg."

  17. Click OK. A new Send Mail action appears in the action model of your component:

    7SendMailActionModelLine

 
Top of page

The Switch Action

The Switch Action (inspired by the Java and C-language switch statement) is designed to allow your application to branch to the appropriate custom logic based on the value of a particular input variable or XPath expression. The Switch Action is a convenience action that obviates the need for a series of nested Decision Actions. It increases the readability of your action model significantly by eliminating multiple actions and consolidating them into one coherent, easily documented, easy-to-read action.

 
Top of section

About Cases

The Switch Action compares a series of values or choices ("cases")—which may be either static or dynamic—against an input value. If an exact match occurs between the input value and one of the available choices, execution branches to the action(s) listed underneath the choice. Just as with a series of if/else statements, cases are tested in the order listed; and once a match is found, execution of the match logic precludes execution of any other logic in the Switch Action.

The custom logic associated with any Case can consist of a single action or a block of actions; and the actions can include any of the standard (basic or advanced) Composer actions, as well as actions specific to a particular Connect.

A Switch Example

Suppose your incoming XML document represents a retail order for goods, and one of the tasks your application must perform is the determination of a shipping method based on the customer's location. The input to the Switch Action might be an XPath expression like:

  $Input/Order/Customer/Address/Country

The case values for the Switch Action, and the associated logic for each choice, might look like:

  CASE:"USA"
     CALL shipMethod = (weight < 10) ? "FedEx" : "UPS";
  CASE:"ANGOLA"
     CALL shipMethod = "Air Gemini";
  CASE:"ARGENTINA"
     CALL shipMethod = "International First Services";
  CASE:"AUSTRALIA"
     CALL shipMethod = "Ansett International";
  .
  .
  .
  DEFAULT:
     CALL shipMethod = "UPS";

At runtime, the value of the Input DOM element at Order/Customer/Address/Country will be checked against each successive Case value, starting with "USA," until a match is reached. In this example, if the match occurs at "ANGOLA", the Function Action that assigns "Air Gemini" to the (ECMAScript) variable shipMethod will execute, then the Switch Action will exit immediately, and execution will continue with the first action (if any) following the Switch Action.

NOTE:   No explicit Break action need be inserted in any Case action group, because the built-in "fall-through" behavior of Java and C-language case statement is not a feature of Composer's Switch Action. Once a match happens, fall-through to the next Case never occurs.

The foregoing example could be equivalently written as a series of Decision Actions. The pseudo-logic for the chain of Decision Actions would be:

  country = inputValue
  if (country == USA)
     ship via A or B
     else if (country == ANGOLA)
        ship via C
        else if (country == ARGENTINA)
           ship via D
           else if (country == AUSTRALIA)
              ship via E
  [etc]
                 else ship via Default shipper
  

The Switch construct eliminates the stairstep indentation and repetitive if/else logic that characterize this kind of code. It also results in easier-to-read-and-maintain code. In general, any time you are faced with a long series of conditionals, you should consider using a Switch Action.

 
Top of section

About the Default Case

The final "Case" under every Switch action is always labelled Default. This line is generated automatically and cannot be removed. Actions placed under Default are executed if and only if the Switch Action, at runtime, encounters no matching Case in the list of Cases.

NOTE:   While you are not required to place actions under Default, it is good programming practice to have at least some kind of fallback logic for the "no match" case, even if it's only a Log action or a Raise Error action.

Procedure To add a Switch action:

  1. Open a component.

  2. Select a line in the Action Model where you want to place a Switch Action. The new action will be inserted below the line you selected.

  3. From the Action menu, select New Action, then Switch. The Switch Action dialog appears. (The text values in the dialog shown below are not defaults. Values were entered for purposes of illustration only.)

    8SwitchDialog

  4. Enter an XPath or ECMAScript expression in the top of the dialog under Expression. This is the input value to the Switch Action.

  5. In the combo box, enter the static string values or the ECMAScript expressions that will be checked against the input value that you specified in the previous step. Remember that at runtime, each Case value will be checked in turn, in the order you list them. (Tip: For optimal performance, list the most likely matches first.)

    NOTE:   New Case entries are, by default, added to the end of the existing list. But you can change the order of the choices by highlighting a given choice and clicking the Up and Down buttons as need be.

  6. Click OK. The dialog goes away and the new Switch Action appears in your action model. See example below.

    7Switch

Once you have added a Switch Action to your action model, you will see a list of Case values. To associate your own custom logic with a given Case, click on the Case, then add new actions one at a time as needed, by clicking the right mouse button and choosing New Action from the context menu. Your Actions block can contain any number of actions (of any type).

Procedure To add custom case-handling logic:

  1. In the action model, find the Case to which you want to add processing logic.

  2. Click on the Actions line below the Case.

  3. Right-click to bring up the context menu. Select New Action and pick from any of the actions available on the submenus.

  4. Repeat the previous step as needed to add additional actions.

Editing Switch Actions

The primary tool for editing Switch Actions is the Switch Action dialog, which allows you to edit the input expression, reorder Cases, edit Case expressions, and add or delete Case values. To access this dialog, just doubleclick on any Switch Action within an action model.

Only a limited amount of editing can be done from the action model itself (without opening the settings dialog). The following limitations apply:

 
Top of page

The Todo Action

Developing Web Services and XML-integration applications can be a very complex undertaking. Composer provides the ability for you to maintain a Todo list to help you organize and manage the many tasks associated with application development.

Procedure To add a Todo action:

  1. Open a component.

  2. Select a line in the Action Model after which you want to place your Todo list. The list item will be inserted below the line you selected.

  3. From the Action menu, select New Action, then Todo. The Todo dialog appears.

    7TodoAction

  4. Enter a Description for the item that will be displayed in your Todo list.

  5. If desired, enter a Note containing additional information. This text displays as part of the item's tool tip when the mouse pointer is over the item.

  6. Use the down arrow to select a Percent Done value for your task, or leave it at 0. As tasks near completion, you should edit this action item and update the percentage complete.

  7. Click OK to add the item to your Action model.

Project-Wide Todo Lists

Todo Lists are not only available within components. They can also be associated directly with a project.

Procedure To add a Todo list outside of a component:

  1. Open a project.

  2. Click on the Todo tab in the Message Frame (see "Navigation, Message, and Content Frames" on page 38.

  3. Right-click with your mouse and select Add Item to add a new Todo list item. Create the item as indicated above.

Tracking Todo items using the Message Frame tab

Once it has been added to your component or project, you will be able to track the progress of the Todo Item using the Todo tab on the Message Frame.

When viewing items in the Todo tab, you will be able to see at a glance how far along you are in your list:

Todo items can be managed either from the Action Model or by right clicking on them in the Todo tab of the Message frame. Items can be edited, added and deleted and re-grouped in the list using the Indent and Outdent menu selections.

7TodoTab




Copyright © 2004 Novell, Inc. All rights reserved. Copyright © 1997, 1998, 1999, 2000, 2001, 2002, 2003 SilverStream Software, LLC. All rights reserved.  more ...