skip to main content
Programmers documentation > Business objects and data sources > Data sources > Adding dynamic business objects
 
Adding dynamic business objects
To create a dynamic business object, all you have to do is create an instance of IlpDefaultObject for an IlpClass, generally an IlpDefaultClass.
Here is an example:
How to create a dynamic business object
 
IlpDefaultObject bo = new IlpDefaultObject(alarmClass, "Alarm1");
bo.setAttributeValue(severityAttribute, new Integer(2));
bo.setAttributeValue(ackAttribute, Boolean.FALSE);
Note that here the identifier of the object is a string, but it does not have to be. This identifier could be of any class, provided that instances of that class can be read from and converted to String using the type converter.
JViews TGO tries to figure out how to convert the object identifier from Object to String, and vice versa. This costly process can affect the data source performance unless an efficient type converter is provided (see Type converter).
The interface IlpObject also contains convenience methods to retrieve and set attribute values based on the attribute name. These convenience methods can be easily implemented as follows:
 
public Object getAttributeValue (String attribute) {
  IlpAttribute attr = getAttributeGroup().getAttribute(attribute);
  if (attr != null)
    return getAttributeValue(attr);
  return IlpAttributeValueHolder.VALUE_NOT_SET;
}
 
public void setAttributeValue (String attributeName, Object value) {
  IlpAttribute attr = getAttributeGroup().getAttribute(attribute);
  if (attr != null)
    setAttributeValue(attr, value);
}
Adding business objects to the data source
The default data source implementation, IltDefaultDataSource, provides methods to add and remove business objects. Once a business object is added into a data source that is connected to a graphic component, it can be automatically displayed by the graphic component.
If you want to add your business objects to the data source without having their graphic representation created, you need to use an IlpFilter and apply it to the IlpAbstractAdapter in charge. In this way, the objects are filtered out and not included in the graphic representation model. No graphic representation will be created at rendering time. You can, at a later stage, change the filter to make more objects visible as needed.
NOTE The filter must be set on the IlpAbstractAdapter before the business objects are added to the data source.
Such filters allow the business objects to be managed by the data source and still not be represented graphically.
The following methods are available to add business objects to a data source:
*void
addObject. Adds a single object to the data source
*void addObjects Adds a collection of objects to the data source.
Whenever possible, large series of IlpObject instances should be added as collections instead of one by one. This is typically the case when you initialize the application.
For example, the code sample below:
 
for (...) {
  parent = new IltNetworkElement("ROOT");
  dataSource.addObject(parent);
 
  for (...) {
    child = new IltNetworkElement("NE");
    dataSource.setParent(child, parent);
    dataSource.addObject(child);
  }
}
Could be improved to:
 
List objects = new ArrayList();
for (...) {
  parent = new IltNetworkElement("ROOT");
  objects.add(parent);
  for (...) {
    child = new IltNetworkElement("NE");
    dataSource.setParent(child, parent);
    objects.add(child);
  }
}
dataSource.addObjects(objects);
Removing business objects from the data source
When the business objects are no longer needed by the application, they can be removed from the data source using one of the following methods:
*IlpObject removeObject(Object idOrIlpObject, boolean childrenToo) : Removes the required object from the data source. The argument "childrenToo" is used to indicate if the whole object subtree should be removed from the data source at the same time.
*List removeObjects(List idsOrIlpObjects, boolean childrenToo) : Removes a collection of objects from the data source.
*void clear() : Removes all business objects from the data source.
Whenever possible, large series of IlpObject instances should be removed as collections instead of removing the objects one by one.

Copyright © 2018, Rogue Wave Software, Inc. All Rights Reserved.