Code

A literal constant value representing a code from an application code table.

The Code expression specifies a code table name, and takes a single argument specifying the value of the code required from the table.

Note: You must specify the code's String value; code table generated constants cannot be used, as CER is a fully dynamic language and cannot be dependent on build-time constructs.
<?xml version="1.0" encoding="UTF-8"?>
<RuleSet name="Example_Code"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:noNamespaceSchemaLocation=
"http://www.curamsoftware.com/CreoleRulesSchema.xsd">
  <Class name="Person">

    <!-- Boolean representation of gender -->
    <Attribute name="isMale">
      <type>
        <javaclass name="Boolean"/>
      </type>
      <derivation>
        <specified/>
      </derivation>
    </Attribute>

    <!-- Code representation of gender -->
    <Attribute name="gender">
      <type>
        <codetableentry table="Gender"/>
      </type>
      <derivation>
        <Code table="Gender">
          <choose>
            <type>
              <javaclass name="String"/>
            </type>
            <when>
              <condition>
                <reference attribute="isMale"/>
              </condition>
              <value>
                <!-- use the "MALE" code from the codetable -->
                <String value="MALE"/>
              </value>
            </when>
            <otherwise>
              <value>
                <!-- use the "FEMALE" code from the codetable -->
                <String value="FEMALE"/>
              </value>
            </otherwise>
          </choose>
        </Code>
      </derivation>
    </Attribute>

  </Class>

</RuleSet>