property

Obtains a property of a Java object.

The property expression specifies the name of the Java method to call, and:

The property expression allows CER to leverage the power of Java classes without having to replicate an arbitrary subset of methods as CER expressions. For example, java.util.List contains a size method, and so CER contains no explicit expression for calculating the counting the number of items in a list.

However, to comply with CER's principle of immutability, only Java methods which do not alter the "value" of any object may be called. CER only allows a "property" method to be called if the method is included on the "safe list" of methods for the object's class (or one of its ancestor classes or interfaces).

A method is deemed safe if it is explicitly marked as such in the safe list. If it is not present in the safe list, then the CER rule set validator will issue an error.

Tip: The explicit setting of safety as false is unnecessary but can be included for documentation completeness, as is the case with the safe lists included with CER.

The safe list for a class is a properties file in the same package as the class, named <classname>_CREOLE.properties.

CER includes safe lists for the following Java classes and interfaces:

Figure 1. Safe list for java.lang.Object methods
# Safe list for java.lang.Object

# safe
toString.safe=true

# force equality to be evaluated using <equals>
equals.safe=false

# not exposed, even though they're "safe"
hashCode.safe=false
getClass.safe=false
Figure 2. Safe list for java.lang.Number methods
# Safe list for java.lang.Number

byteValue.safe=true
doubleValue.safe=true
floatValue.safe=true
intValue.safe=true
longValue.safe=true
shortValue.safe=true
Figure 3. Safe list for java.util.List methods
# Safe list for java.util.List

contains.safe=true
containsAll.safe=true


get.safe=true

indexOf.safe=true
isEmpty.safe=true
lastIndexOf.safe=true
size.safe=true
subList.safe=true


# not exposed
hashCode.safe=false
listIterator.safe=false
iterator.safe=false
toArray.safe=false

# mutators - unsafe
add.safe=false
addAll.safe=false
clear.safe=false
remove.safe=false
removeAll.safe=false
retainAll.safe=false

For a description of some of the useful properties on the List Java interface, see Useful List Operations.

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

  <Class name="Person">
    <Attribute name="children">
      <type>
        <javaclass name="List">
          <ruleclass name="Person"/>
        </javaclass>
      </type>
      <derivation>
        <specified/>
      </derivation>
    </Attribute>

    <!-- Whether this person has any children.

         Tests the isEmpty property of List. -->
    <Attribute name="hasChildren">
      <type>
        <javaclass name="Boolean"/>
      </type>
      <derivation>
        <not>
          <property name="isEmpty">
            <object>
              <reference attribute="children"/>
            </object>
          </property>
        </not>

      </derivation>
    </Attribute>

    <!-- All this person's children, excluding the first child.

         Uses the subList property of List, passing in:
         - (inclusive) from item at position "1" (denoting the
 second
           member in the list; lists in Java are zero-based)
         - (exclusive) to item at position "size of list" (denoting
           the position after the last item in the list)
    -->
    <Attribute name="secondAndSubsequentChildren">
      <type>
        <javaclass name="List">
          <ruleclass name="Person"/>
        </javaclass>
      </type>
      <derivation>
        <property name="subList">
          <object>
            <reference attribute="children"/>
          </object>
          <arguments>
            <!-- The number must be converted to an integer
                 (as required by List.subList). -->
            <property name="intValue">
              <object>
                <Number value="1"/>
              </object>
            </property>
            <property name="size">
              <object>
                <reference attribute="children"/>
              </object>
            </property>

          </arguments>
        </property>

      </derivation>
    </Attribute>

  </Class>

</RuleSet>
CAUTION:
Since Cúram V6, CER and the Dependency Manager supports the storage of calculated attribute values on the database, together with automatic recalculation of attribute values if their dependencies change.

If you change the implementation of a property method, CER and the Dependency Manager will not automatically know to recalculate attribute values that were calculated using the old version of your property method.

Once a property method has been used in a production environment for stored attribute values, rather than changing the implementation you should instead create a new property method (with the required new implementation), and change your rule sets to use the new property method. When you publish your rule set changes to point to the new property method, CER will automatically recalculate all instances of the affected attribute values.