Evaluating Expressions

In this section:

iWay Service Manager supports built-in functions for parameter entry. These functions perform some expressible operation on their operands, and are evaluated to a string result, which in turn becomes the parameter. Expressions are of two classes, those that can be evaluated at init() time and those that must be evaluated at message execution time. An expression can only be evaluated at init() time if all of its operands depend only on values not related to the message being processed. An example of such an expression is the FILE(<filename>) function, if the name of the file is constant, and is not itself taken from a special register or from the message.

Init time functions are automatically evaluated by the time that your init() function is called in an exit. You simply get the result of the evaluation. For execution time evaluation, or in a protocol listener or emitter, you must evaluate the expression yourself. The engine provides an evaluation service to do the actual evaluation.

The complete list of built-in functions, which can be combined, are explained in iWay Service Manager configuration documentation. Some examples of built-in functions are shown in the following table.

Function

Returns

Description

_ALL

True/False

Modifier for COND.

_ANY

True/False

Modifier for COND.

_ATTCNT()

Integer

Number of attachments.

_COND

True/False

Evaluates expression for truth.

_CONTAINS(string, string2)

True/False

If substring is contained.

_COUNT(parm1)

Integer

Number of elements in expression.

_ENDSWITH(string1, string2)

True/False

Does parameter end with value?

_FILE

String

Gets contents of a file.

_FLATOF()

String

Returns flat value of the document.

_ISERROR()

True/False

Is document in error state?

_ISFLAT()

True/False

Is document flat?

_ISXML()

True/False

Is document XML?

_LDAP

String

Looks up value in an LDAP.

_LENGTH(string1)

Integer

Returns value length of the parameter.

_SREG

String

Returns value of a special register.

_STARTSWITH(string1, string2)

True/False

Does parameter start with value?

_SUBSTR(string1, startindex [,endindex])

String

Returns substring of parameters.

_XPATH

String

Gets value(s) from an XML document.

The evaluate() service evaluates any expression of any built-in functions described in iWay Service Manager configuration documentation.

You can pass any String value to the evaluate() service. The method returns a String of the evaluation, which your program should use as the value of the parameter. Evaluation is done right to left, inside to outside. So an expression of

FILE(SREG(XPATH(/root/childone)))

returns the contents of the file whose name is in a special register the name of which is in the incoming document. This example is for illustration, and such complexity is probably a poor idea in a real application.

To evaluate, use the static method evaluate()

String XDUtil.evaluate(String parm, XDDocument doc, ISpecregMgr ism)

where:

parm

Is the expression to be evaluated. The parm must be a properly formed expression. Null is returned if the expression cannot be evaluated. The evaluation of a literal is the literal itself.

doc

Is the XDDocument that is to be the subject of any XPATH built-in function. Even if you know that there are no XPATH function calls, pass the current document if you have one. In listeners or preparsers, this must be null, as no document yet exists.

ism

A special register manager. You can obtain the local register manager by calling getSRM() in your context.

logger

Standard context logger. You can object the local logger by calling getLogger().

For example:

File c:\x.txt in Windows contains the value "ABC".
  String r = XDUtil.evaluate("COND(FILE(c:\\x.txt),EQ,DEF)",null,this);
  logger.debug("val is "+r);  // prints "false".

Top of page

x
User Functions

Special-purpose functions can be written and added to the system. They must be in the classpath and properly registered. The actual writing of functions is explained in Writing Management Components.


iWay Software