Dynamic Objects

The JadeDynamicObject class implements the structure and behavior of dynamic objects. A JADE dynamic object is a self-describing object whose attributes are determined at run time.

The JadeDynamicObject class has two fixed attributes: type and name, which you can use to determine the runtime type of a dynamic object. The JADE Inspector displays the type, name, and dynamic attribute names and values of JadeDynamicObject instances.

In the following example, a dynamic object is created and the three properties called Item, Quantity, and Available are added and their values are set. At the end of the method, the names and values of the properties are displayed.

vars
    jdo : JadeDynamicObject;
    i : Integer;
    str : String;
begin
    create jdo;
    jdo.addProperty("Item", String);
    jdo.setPropertyValue("Item", "calculator");
    jdo.addProperty("Quantity", Integer);
    jdo.setPropertyValue("Quantity", 100);
    jdo.addProperty("Available", Boolean);
    jdo.setPropertyValue("Available", true);
    foreach i in 1 to jdo.propertyCount do
        str := str & CrLf & jdo.getPropertyName(i) & " = "
               & jdo.getPropertyValueByIndex(i).String;
    endforeach;
    write str;
epilog
    delete jdo;
end;

The output from the previous method is as follows.

Item = calculator
Quantity = 100
Available = true

The method in the following example creates a dynamic object and passes this to the Collection class getStatistics method, which populates the object with various statistical attributes and their values, returning the dynamic object to the caller. The method then uses the getPropertyName, getPropertyValueByIndex, and propertyCount methods to display the statistical attribute name and value pairs. As the calling method created the jdo variable, it is also responsible for deletion, which is performed in an epilog.

vars
    jdo   : JadeDynamicObject;
    str   : String;
    int   : Integer;
    count : Integer;
begin
    create jdo;
    node.processes.getStatistics(jdo);
    str := '---' & jdo.getName & '(' & jdo.type.String & ')---';
    count := jdo.propertyCount;
    foreach int in 1 to count do
        str := str & CrLf & jdo.getPropertyName(int) &
                         " = " & jdo.getPropertyValueByIndex(int).String;
    endforeach;
    write str;
epilog
    delete jdo;
end;

For details about the properties and methods defined in the JadeDynamicObject class, see "JadeDynamicObject Properties" and "JadeDynamicObject Methods", in Chapter 1 of the JADE Encyclopaedia of Classes.