1 Properties

1.1 Accessing Properties

Any class can export properties by implementing the interface HasProperties:

interface HasProperties
{
   // get a handle for a specific named property
   Property getProperty (String name);
   // get a list of all properties associated with this class
   PropertyInfoList getAllPropertyInfo ();
}

Each property is associated with a name, which must be a valid Java identifier. The getProperty() method returns a Property handle to the named property, which can in turn be used to access that property’s values or obtain other information about it. getAllPropertyInfo() returns a PropertyInfoList providing information about all the properties associated with the class.

A Property handle supplies the following methods:

interface Property
{
   Object get();
   void set (Object value);
   Range getRange ();
   HasProperties getHost();
   PropertyInfo getInfo();
}
get()

Returns the property’s value. As a rule, returned returned values should be treated as read-only.

set()

Sets the property’s value (unless it is read-only, see Section 1.2).

getRange()

Returns a Range object for a property (see Section 1.1.1), which is used to determine which values are admissible to set. If all values are admissible, getRange() can return null.

getHost()

Returns the object to which this property handle belongs.

getInfo()

Returns static information about this property (see Section 1.2).

A simple example of property usage is given below. Assume that we have a class called DeformableModel which contains a property called stiffness, and we want to set the stiffness to 1000. This could be done as follows:

   DeformableModel defo = new DeformableModel();
   Property stiff = defo.getProperty("stiffness");
   stiff.set (1000.0); // (uses Java 1.5 autoboxing to turn
                       // 1000.0 into Double(1000.0)

Of course, DeformableModel will likely have a method called setStiffness that can be used to set the stiffness directly, without having to got through the Property interface. However, the purpose of properties is not to facilitate attribute access within specially constructed code; it is to facilitate attribute access within generic code that is hidden from the user. For instance, suppose I want to query a property value from a GUI. The GUI must obtain the name of the desired property from the user (e.g., through a menu or a text box), and then given only that name, it must go and obtain the necessary information from the object exporting that property. A Property allows this to be done in a manner independent of the nature of the property itself.

1.1.1 Why Property Handles?

In theory, one could embed the methods of Property directly within the HasProperties interface, using methods with signatures like

   Object getPropertyValue (String name);
   void setPropertyValue (String name, Object value);

The main reason for not doing this is performance: a property handle can access the attribute quickly, without having to resolve the property’s name each time.

Each property handle contains a back-pointer to the object containing, or hosting, the property, which can be obtained with the getHost() method.