ComponentX Calculator Example

Overview

The calculator example is intended to demonstrate several techniques for performing logic and computation. Three different implementations of a 4-function calculator contract is included. One implementation primarily performs the logic tests and computation in an XSL script. The second performs the same type logic and computation using separate Component-X components. The third is an alternate to the second which makes uses of extended expressions that can access data retained in variables.

Details

The problem being solved is to provide a component that accepts documents of the form:

    <oper operator="+" operand="10">

where the attribute operator can have either "+", "-", "*", "/", or "clr" and the operand attribute is any number, and returns a running total as a result of performing the specified operation against the previous total. The result is expressed in a document of the form:

    <accm value="10">

The calcXsl component within the example uses an XSL script to perform logic and computation againts a input document. Other components are needed to merge the input request with the last reply document in order to send all in information to the XSL script.

The calculator component replaces the XSL script with several distinct components each performing a single piece of the required functionality.

The calcNew component simplifies the implementation by using extended expressions to access the value of variables. This removed the need to merge documents thereby elmininating several contained components.

Running the example

To run the example first load the project using the open project menu item or tool bar button and choose calc.cxp from the examples\calc directory. To see any of the implementation in operation, open the desired component and doubled click on oper and accm ports. Enter input documents of the form stated previously into the oper window, click the send button, and observe the result in the accm window. You can use the file open button in the oper window to load any of the sample input documents.

Other information

To learn more about how to load and run applications using ComponentX review the tutorial which can be accessed from the readme.

Copyright 2000,2001 Data Access Technologies