variable element

The <variable> element defines a variable and contains information in a form that can be referenced by expressions. A variable can be defined at the level of the rule set, a rule block, or a rule.

Details

rule set variable
Applies globally to the rule set and can be referenced by any expression in that rule set.
rule block variable
Applies only within the rule block (and within any contained rule blocks) and can be referenced by any expression within that rule block.
rule variable
Applies only to expressions within that rule.

Variables can have the same name at different levels in the rule hierarchy. When a variable is accessed, the most local definition of the variable is used. For example, if a variable is defined at the rule set level, rule block level, and rule level with the same name, the variable definition at the rule level is used by the expressions within that rule.

When variables are defined at the rule set or rule block level, multiple rules get and set these variables at different times. Therefore, to ensure that variable values are maintained correctly, be aware of how you code the interactions among variables in the rule set.

If the variable is defined at the rule set or rule block level, it is not reinitialized after the rule pattern is matched.

Under either of the following conditions, use locking on the getting and setting of rule set and rule block variables to prevent the variable values from being incorrectly set:
  • If the timer rule gets or sets a variable during an <onTimeOut> action
  • If the application in which the Active Correlation Technology engine is embedded is multithreaded

If a rule is defined with a grouping key, rule variables that are defined by the <variable> element are not valid within life cycle actions or within a <filteringPredicate> element that is contained within an <activateOnEvent> or <deactivateOnEvent> element that is contained within an <activationInterval> element. This is because in this case, the rule variables apply only to a rule instance, and rule instances do not exist at the time that these expressions are run.

Attributes

<variable> has the following attributes:

Table 1. Attributes of the <variable> element
Name Description Data type Required?
name Identifies a specific variable. A variable is referenced by its name. xsd:NMTOKEN Yes
dataType Identifies the type of information that a variable contains. This must be a fully qualified data type such as java.lang.String. xsd:NMTOKEN Yes

Name restrictions for variables

Variable names have certain restrictions. Therefore, the value of the name attribute on the <variable> element has the following restrictions:
  • It can include only the following characters:
    • Uppercase ASCII Latin letters A-Z. The Unicode representation is \u0041-\u005a.
    • Lowercase ASCII Latin letters a-z. The Unicode representation is \u0061-\u007a.
    • The ASCII underscore (_). The Unicode representation is \u005f.
    • The dollar sign ($). The Unicode representation is \u0024.
    • The ASCII digits 0 – 9. The Unicode representation is \u0030-\u0039.
  • It cannot be null.
  • It cannot be an empty string.
  • It cannot contain any blank spaces.
  • It cannot contain a period.
  • It cannot start with act_ in any form (not in uppercase, lowercase, or mixed case).

Contained within

Contains

<variable> contains the following elements.

The elements must be coded in the order that is shown. If an element is optional, it does not need to be coded, but all elements that are coded must follow the correct order.

Table 2. Elements contained within the <variable> element
Element Required or optional?
<comment> Optional. 0 or 1 occurrence is allowed.
<varInitializer> Required. 1 occurrence is allowed.
Related concepts
Variables