Obtains a property of a Java object.
The property expression specifies the name of the Java method to call, and:
The Java object on which to operate; and
Optionally, a list of arguments to pass to the Java method.
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.
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:
# 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
# Safe list for java.lang.Number byteValue.safe=true doubleValue.safe=true floatValue.safe=true intValue.safe=true longValue.safe=true shortValue.safe=true
# 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>
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.