Business Objects and Data Sources > The Business Model > Business Model API

The following figure illustrates the various elements that compose the business object model.

images/tgo_business_model2.png

Figure 2.2 The Business Model API

The business model API is composed of the following APIs:

Business Class API

The interface IlpClass defines static classes. It provides methods to:

The interface IlpMutableClass defines dynamic classes. In addition to the methods listed above, it provides methods to:

JViews TGO provides a few convenience implementations of these interfaces that you can use directly or subclass when building an application:

Business Object API

The interface IlpObject defines instances of business classes. These instances (business objects) contain values for the attributes defined by the corresponding class. They also have an attribute group that can be the IlpClass itself or an extension allowing you to define new attributes at the object level.

Each business object must be assigned to an identifier when it is created. The identifier must be unique (even across data sources); it is used to identify and retrieve the IlpObject. The object identifier can be of any type, as long as it satisfies the following constraints:

  1. The identifier must be convertible to String, through an IlpTypeConverter installed in the IlpContext. The IlpDefaultTypeConverter uses the Object.toString() method to convert objects of unknown types to String. The String that results from this conversion must be unique.
  2. It must be possible to create or retrieve the identifier Object, given the corresponding String, by using the IlpTypeConverter installed in the IlpContext. The IlpDefaultTypeConverter uses a constructor with a single String argument to create instances of unknown types.
  3. The identifier Object itself must not be an instance of IlpObject.

Please note the following recommendations:

Note that once the proper implementation for the IlpTypeConverter is created (normally you do this by subclassing IlpDefaultTypeConverter), you can register it with the IlpContext implementation as follows:

IlpContext context = ...;
context.addService(IlpTypeConverter.class, new CustomTypeConverter(context));

For more information about how to customize and extend the behavior of the default type converter, refer to Type Converter in the Context and Deployment Descriptor documentation and to Complex Types in this documentation.

The IlpObject interface has methods to:

JViews TGO provides the following convenience implementations of this interface that you can use directly when building your application:

Attribute API

Attributes are the properties that qualify a business class. For example, an object of type alarm can be qualified by a severity and a description. An attribute is identified by its name and its value and is typed by a Java class.

The following figure illustrates the attribute API:

images/tgo_business_model_attribute3.png

Figure 2.3 The Attribute API

The interface IlpAttribute defines attributes. It provides the following methods:

JViews TGO provides a set of convenience implementations for IlpAttribute that you can use directly or subclass in order to obtain application-specific behavior:

Attribute Group

Attributes are logically gathered in attribute groups. An attribute group can be static or dynamic. Static attribute groups are defined by the interface IlpAttributeGroup and dynamic attribute groups are defined by IlpMutableAttributeGroup.

These interfaces provide methods that allow you to perform the following operations:

JViews TGO provides the following convenience implementations of IlpAttributeGroup:

Attribute Value Holder

In JViews TGO, an attribute value is not carried by the attribute itself but by an attribute value holder because this value is specific to the object with which the attribute is associated. An attribute value holder is defined by the IlpAttributeValueHolder interface. Business objects and representation objects carry attribute values, and as such they implement this interface. The IlpAttributeValueHolder interface includes methods to retrieve and set the value of an attribute, and notify interested objects about changes in attribute values.

Attribute values may be set using the following method:

public void setAttributeValue (IlpAttribute attribute, Object value)

where value may be null.

In cases where attributes have not been set or initialized, the value is IlpAttributeValueHolder.VALUE_NOT_SET.

Attribute values may be retrieved using the following method:

public Object getAttributeValue (IlpAttribute attribute)

Computed Attributes

A computed attribute is an attribute which value is derived from the value of one or more other attributes. To implement a computed attribute, you need to extend the abstract class IlpComputedAttribute and implement its abstract part and a constructor. The abstract part of this class is also known as the IlpAttributeValueProvider interface.

The IlpAttributeValueProvider interface contains the following methods:

public Object getValue (IlpAttributeValueHolder h);
public boolean isDependentOn (IlpAttribute a) ; 

The getValue() method returns a value that is computed from its attribute value holder parameter. The isDependentOn() method specifies the attributes used to calculate the value of the computed attribute. Whenever the value of one of these attributes changes, the object carrying this attribute notifies its listeners that the computed attribute value has been modified. Note that the computed value is cached. Therefore, calling the getAttributeValue() method of IlpAttributeValueHolder twice calls the method IlpComputedAttribute.getValue() only once. This cached value is erased whenever the value of an attribute on which the computed attribute depends is modified.

The example below shows how to define a computed attribute that returns a sorted array of integers calculated from another array of integers.

How to Define a Computed Attribute
class  SortIntAttribute extends IlpComputedAttribute {
    IlpAttribute arrayAttribute; 
    public SortIntAttribute(String name,
      IlpAttributeGroup model,
      IlpAttribute arrayAttribute) {
      super(name, model, arrayAttribute.getValueClass());
      this.arrayAttribute = arrayAttribute;
    }
 
    public Object getValue(IlpAttributeValueHolder h) { 
      Object value = h.getAttributeValue(arrayAttribute);
      if (value != IlpAttributeValueHolder.VALUE_NOT_SET) {
        int[] array = (int [])h.getAttributeValue(arrayAttribute);
        array = (int [])array.clone();
        Arrays. sort(array);
        return array;
      }
      return IlpAttributeValueHolder.VALUE_NOT_SET;
    }
 
    public boolean isDependentOn (IlpAttribute a) {
      return a == arrayAttribute;
    }
}

The constructor of SortIntAttributes takes three arguments:

The getValue method computes the attribute value. Computation is protected. As a consequence, if the value of the attribute on which the computed attribute depends is not initialized, or in other words if its value is IlpAttributeValueHolder.VALUE_NOT_SET, the method does not perform the computation and returns IlpAttributeValueHolder.VALUE_NOT_SET. In this example, when the value is set, the returned array is duplicated, sorted, and returned.

The implementation of the isDependentOn method is quite straightforward, since in this example the computed attribute depends only on one other attribute, which is specified in the constructor.