create

Gets a new instance of a rule class in the session's memory. Any initialization values required by the rule object must be specified as child elements of the create expression.

Since Cúram V6, create can be used to create an new instance of a rule class from a different rule set, by setting the value of the optional ruleset XML attribute.

Note: Rule objects created using create cannot be retrieved during rules execution, as to do so would violate CER's ordering principle.

Since Cúram V6, there is a choice of syntax when passing values to a created rule object:

Since Cúram V6, created rule objects are "pooled" within the session. This pool enables identical requests to create a rule object to be served by a single rule object, which can conserve memory usage and also prevent identical calculations from taking place, leading to lower CPU load. Two requests to create a rule object are considered identical if they request the same rule class and the values of all initialized and specified attributes are equal.

In the example below, if a person's work phone number is identical to the person's home phone number, then a single rule object will be used for each number, and thus the derived value for isOutOfThisArea will only be calculated once. Otherwise if the work and home phone numbers are different then two different rule objects will be created.

<?xml version="1.0" encoding="UTF-8"?>
<RuleSet name="Example_create"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:noNamespaceSchemaLocation=
"http://www.curamsoftware.com/CreoleRulesSchema.xsd">

  <Class name="Person">

    <!-- Phone number details as gathered in evidence -->
    <Attribute name="homePhoneAreaCode">
      <type>
        <javaclass name="Number"/>
      </type>
      <derivation>
        <specified/>
      </derivation>
    </Attribute>

    <Attribute name="homePhoneNumber">
      <type>
        <javaclass name="Number"/>
      </type>
      <derivation>
        <specified/>
      </derivation>
    </Attribute>

    <Attribute name="workPhoneAreaCode">
      <type>
        <javaclass name="Number"/>
      </type>
      <derivation>
        <specified/>
      </derivation>
    </Attribute>

    <Attribute name="workPhoneNumber">
      <type>
        <javaclass name="Number"/>
      </type>
      <derivation>
        <specified/>
      </derivation>
    </Attribute>

    <!-- Create PhoneNumber rule objects
         and place them in a list -->
    <Attribute name="phoneNumbers">
      <type>
        <javaclass name="List">
          <ruleclass name="PhoneNumber"/>
        </javaclass>
      </type>
      <derivation>
        <fixedlist>
          <listof>
            <ruleclass name="PhoneNumber"/>
          </listof>

          <members>

            <!-- Phone Number for the home details. -->
            <create ruleclass="PhoneNumber">
              <!-- The value for PhoneNumber.owner -->
              <this/>
              <!-- The value for PhoneNumber.number -->
              <reference attribute="homePhoneNumber"/>
              <specify attribute="areaCode">
                <!-- The value for PhoneNumber.areaCode -->
                <reference attribute="homePhoneAreaCode"/>
              </specify>
            </create>

            <!-- Phone Number for the work details.

                 If a person's work phone number is identical to the
                 person's home phone number (i.e. the area code and
                 number are the same), then this <create> expression
                 will return the same rule object as the rule object
                 returned by the <create> expression above.  If the
                 phone numbers are not identical, then two different
                 rule objects will be returned.-->
            <create ruleclass="PhoneNumber">
              <this/>
              <reference attribute="workPhoneNumber"/>
              <specify attribute="areaCode">
                <reference attribute="workPhoneAreaCode"/>
              </specify>
            </create>

          </members>
        </fixedlist>
      </derivation>
    </Attribute>

  </Class>

  <Class name="PhoneNumber">

    <Initialization>
      <!-- The values for these attributes must be passed, in order,
           by any <create> expression. -->
      <Attribute name="owner">
        <type>
          <ruleclass name="Person"/>
        </type>
      </Attribute>
      <Attribute name="number">
        <type>
          <javaclass name="Number"/>
        </type>
      </Attribute>
    </Initialization>


    <!-- The value for this attribute may be passed by a <specify>
         element within a <create> expression, which will override
         the default derivation here. -->
    <Attribute name="areaCode">
      <type>
        <javaclass name="Number"/>
      </type>
      <derivation>
        <!-- Default implementation, used if the <create> expression
             does not <specify> a value for this attribute. -->
        <Number value="123"/>
      </derivation>
    </Attribute>

    <!-- For a pooled rule object, this derived value will only be
         calculated once.

         For example, if a person's work phone number is identical
         to the person's home phone number, then the same rule
         object will be used for both home and work phone numbers,
         and the "isOutOfThisArea" value for this single rule
         object will be calculated only once.
      -->
    <Attribute name="isOutOfThisArea">
      <type>
        <javaclass name="Boolean"/>
      </type>
      <derivation>
        <not>
          <equals>
            <reference attribute="areaCode"/>
            <!-- The area code for the agency's area -->
            <Number value="123"/>
          </equals>
        </not>
      </derivation>
    </Attribute>
  </Class>
</RuleSet>