Extending predefined business classes

To extend a predefined business class dynamically, you can:
  • Create a new instance of IlpDefaultClass directly or create it from an XML description of the class.
  • Create a new Java™ class and its associated IlpClass.

Creating a subclass of a predefined business class dynamically

The following example demonstrates how to create a subclass of a predefined business class in XML.

How to create a subclass of a predefined business object in XML

<class>
    <name>Element</name>
    <superClass>ilog.tgo.model.IltNetworkElement</superClass>
    <attribute>
      <name>throughput</name>
      <javaClass>java.lang.Integer</javaClass>
    </attribute>
</class>
The syntax is the same as for creating a regular class with XML. See Defining the business model in XML.
The newly created class extends the IltNetworkElement predefined business class and has an additional attribute ( throughput ).
This class is an instance of both the IlpClass Element and the Java class ilog.tgo.model.IltNetworkElement .
As shown in the following figure, an instance of Element derives from two class hierarchies: the dynamic class hierarchy and the Java class hierarchy.
tgo_predefined_class_inheritance.png
Deriving instances from the dynamic and the Java class hierarchies
If you create an instance of the IlpClass Element with XML or with the API, the created object will be an instance of the Java class IltNetworkElement.
For example:

How to extend predefined business object classes for use with the Java API

IlpClass elementClass =
  classManager.getClass("Element");
IlpObject element = elementClass.newInstance("element 1", true);
The method newInstance is available in business classes to create new instances. This method has two arguments:
  • object identifier: a unique object identifier used by the new instance
  • boolean initializeAttributeValues : a flag which indicates whether the new instance has its default attribute values initialized. It is important to note that predefined business objects and their subclasses always have their default attributes initialized when a new instance is created. In this case, the second parameter is ignored.

Creating a Java subclass of a predefined business class

Creating a Java subclass of a predefined business class is similar to what is described in Adding predefined business objects with the following differences:
  • Methods getIdentifier , getIlpClass , getAttributeValue and setAttributeValue should not be overridden.
  • You must implement the following constructors:
    public MyClass (Object identifier) {
      super(identifier);
    }
    
    and
    public MyClass (IlpClass ilpclass, Object identifier) {
      super(ilpclass, identifier);
    }
    
  • You must call the superclass in the constructor.
  • You must create a static instance of IltObjectInfo that will store the business class information so that it is recognized as an JViews TGO business class.
  • You must implement the method GetIlpClass. This method allows your new business class to be automatically recognized by the Class Manager service.
  • Your new accessor methods (for example, getThroughput / setThroughput ) should call getAttributeValue and setAttributeValue with the appropriate parameters. These methods already provide the mechanism to store the objects internally as well as notification support.
The following example illustrate the implementation of a new business object class that inherits from IltNetworkElement. This new business class contains a new attribute, called THROUGHPUT .

How to create a new business class from a predefined business class

public class CustomNetworkElement extends IltNetworkElement {

  // Create the business class 
  static IltObjectInfo metainfo = new IltObjectInfo(CustomNetworkElement.class,
      "CustomNetworkElement");

  // Create the business attribute and register in the class
  public static final IlpAttribute THROUGHPUT = new IltAttribute("throughput",
                                                                 Integer.class, 
                                                                 metainfo,
                                                                 new
                                                                 Integer(0));
  // Register the new attribute in this business class
  static {
    metainfo.addAttribute(THROUGHPUT);
  }

  // Implement method GetIlpClass so that this class is automatically
  // recognized as a business class by the Class Manager service
  public static IltObjectInfo GetIlpClass() {
    return metainfo;
  }

  // Implement the class constructor
  public CustomNetworkElement (Object identifier) {
    super(identifier);
  }

  // Implement the class constructor
  public CustomNetworkElement (IlpClass clazz, Object identifier) {
    super(clazz, identifier);
  }

  public int getThroughput() {
    Object v = getAttributeValue(THROUGHPUT);
    if (v == ilog.cpl.model.IlpAttributeValueHolder.VALUE_NOT_SET)
      return 0;
    else
      return ((Integer)v).intValue();
  }

  public void setThroughput(int throughput) {
    setAttributeValue(THROUGHPUT, new Integer(throughput));
  }
}