Retrieves the value of an attribute from a rule object.
The reference expression may optionally contain a child expression which determines the rule object from which to obtain the attribute; if omitted, the rule object containing the reference will be used.
The reference expression is the key to building rules which are reusable and understandable. You can use a reference to a named attribute in place of any expression. The CER rule set validator will issue an error if the type of the referenced attribute does not match the type required by the expression.
<?xml version="1.0" encoding="UTF-8"?>
<RuleSet name="Example_reference"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation=
"http://www.curamsoftware.com/CreoleRulesSchema.xsd">
<Class name="Person">
<Attribute name="name">
<type>
<javaclass name="String"/>
</type>
<derivation>
<specified/>
</derivation>
</Attribute>
<Attribute name="age">
<type>
<javaclass name="Number"/>
</type>
<derivation>
<specified/>
</derivation>
</Attribute>
<!-- A simple reference to another
attribute on this rule class -->
<Attribute name="ageNextYear">
<type>
<javaclass name="Number"/>
</type>
<derivation>
<arithmetic operation="+">
<!-- This <reference> has no child element,
so the rule object is taken to be "this rule
object"-->
<reference attribute="age"/>
<Number value="1"/>
</arithmetic>
</derivation>
</Attribute>
<Attribute name="favoritePet">
<type>
<ruleclass name="Pet"/>
</type>
<derivation>
<specified/>
</derivation>
</Attribute>
</Class>
<Class name="Pet">
<Attribute name="name">
<type>
<javaclass name="String"/>
</type>
<derivation>
<specified/>
</derivation>
</Attribute>
<Attribute name="species">
<type>
<javaclass name="String"/>
</type>
<derivation>
<specified/>
</derivation>
</Attribute>
</Class>
<Class name="Household">
<!-- All the people in the household -->
<Attribute name="members">
<type>
<javaclass name="List">
<ruleclass name="Person"/>
</javaclass>
</type>
<derivation>
<specified/>
</derivation>
</Attribute>
<!-- One special person is designated
as the "head" of the household -->
<Attribute name="headOfHousehold">
<type>
<ruleclass name="Person"/>
</type>
<derivation>
<specified/>
</derivation>
</Attribute>
<!-- A reference to an attribute on a
different rule object:
name OF favoritePet OF headOfHousehold
In a programming language, this might be
written back-to-front using a dereferencing
"dot" notation like this:
headOfHousehold.favoritePet.name
-->
<Attribute name="nameOfHeadOfHouseholdsFavoritePet">
<type>
<javaclass name="String"/>
</type>
<derivation>
<!-- The name... -->
<reference attribute="name">
<!-- ...of the favorite pet... -->
<reference attribute="favoritePet">
<!-- ...of the head of household. -->
<!-- The inner-most reference must refer to
an attribute on this rule object. -->
<reference attribute="headOfHousehold"/>
</reference>
</reference>
</derivation>
</Attribute>
<!-- Identifies the dog owners in the household
by checking which people have a favorite
pet which is a dog. -->
<Attribute name="dogOwners">
<type>
<javaclass name="List">
<ruleclass name="Person"/>
</javaclass>
</type>
<derivation>
<filter>
<list>
<!-- simple reference to the members
of the household -->
<reference attribute="members"/>
</list>
<listitemexpression>
<equals>
<String value="Dog"/>
<!-- A reference to an attribute on an item
in the list. -->
<reference attribute="species">
<reference attribute="favoritePet">
<current/>
</reference>
</reference>
</equals>
</listitemexpression>
</filter>
</derivation>
</Attribute>
</Class>
</RuleSet>