Defining business object relationships

Business object relationships, such as links or containment, are defined in the data source using the following methods:
  • void setLink (Object idOrIlpObject, Object fromIdOrIlpObject, Object toIdOrIlpObject)
    This method declares an object as being a link, connecting the from business object to the to business object. The structural information of the link is defined by the interface IlpLink.
  • void setParent (Object idOrIlpObject, Object parentIdOrIlpObject)
    This method declares an object as being the parent of another object.
  • void setChildren (Object idOrIlpObject, List childrenIdsOrIlpObjects)
    This method declares an object as being the parent of the given list of child objects.

How to define parent-child relationships between business objects

The following example illustrates the use of the methods setParent and setChildren in a default data source.
IlpObject parent = new IltNetworkElement("NE1");
IlpObject child = new IltNetworkElement("NE1_1");
dataSource.setParent(child, parent);
dataSource.addObject(child);
dataSource.addObject(parent);
or
IlpObject parent = new IltNetworkElement("NE1");
IlpObject child1 = new IltNetworkElement("NE1_1");
IlpObject child2 = new IltNetworkElement("NE1_2");
IlpObject child3 = new IltNetworkElement("NE1_3");
List children = new ArrayList();
children.add(child1);
children.add(child2);
children.add(child3);
dataSource.setChildren(parent, children);
dataSource.addObjects(children);
dataSource.addObject(parent);

How to define a link between business objects

The following example illustrates the use of the method setLink in a default data source.
IlpObject fromEnd = new IltNetworkElement("NE1");
IlpObject toEnd = new IltNetworkElement("NE2");
IlpObject link = new IltLink("NE1<->NE2");

dataSource.setLink (link, fromEnd, toEnd);
List objects = new ArrayList();
objects.add(fromEnd);
objects.add(toEnd);
dataSource.addObjects(objects);
dataSource.addObject(link);
Whenever possible, first add all end-point objects to the data source, then add the corresponding link objects. This avoids internal checks and temporary object storage to properly create and arrange the object hierarchy.
To improve the data source and component performance, it is also recommended to avoid changing relationships after the objects have been added to the data source. For example:

Less efficient:

dataSource.addObject(object);
dataSource.setParent(object, parent);

More efficient:

dataSource.setParent(object, parent);
dataSource.addObject(object);

How to define an intergraph link

JViews TGO is able to display links connecting objects in different hierarchies. These links are known as intergraph links. To have an intergraph link properly displayed, you need to take care of how the link object is created in the data source, specially at which hierarchy level the link object is added.
To illustrate an intergraph link use case, let’s imagine the following object hierarchy:
ObjectHierarchyExample.gif
Object hierarchy
Suppose you wanted to create a link connecting Leaf A and Leaf B. You would have to add it to the data source in the following way:
ArrayList objects = new ArrayList();
IltNetworkElement net = new IltNetworkElement("Network");
net.setName("Network");

IltNetworkElement branchA = new IltNetworkElement("BranchA");
branchA.setName("A");
IltNetworkElement branchB = new IltNetworkElement("BranchB");
branchB.setName("B");

objects.add(net);
objects.add(branchA);
objects.add(branchB);

dataSource.setParent(branchA, net);
dataSource.setParent(branchB, net);

IltNetworkElement leafA = new IltNetworkElement("LeafA");
leafA.setType(IltNetworkElement.Type.NMW);
leafA.setPosition(new IlpPoint(100,100));
leafA.setName("Leaf A");
IltNetworkElement leafB = new IltNetworkElement("LeafB");
leafB.setType(IltNetworkElement.Type.NMW);
leafB.setPosition(new IlpPoint(250,250));
leafB.setName("Leaf B");

dataSource.setParent(leafA, branchA);
dataSource.setParent(leafB, branchB);
objects.add(leafA);
objects.add(leafB);

// Creating the intergraph link
IltLink link = new IltLink("LeafA-LeafB");
link.setName("LeafA-LeafB");
dataSource.setLink(link, leafA, leafB);
// Setting the link hierarchy level
dataSource.setParent(link, net);
objects.add(link);
dataSource.addObjects(objects);
The intergraph link should be placed at the highest hierarchy level common to both end points. This is illustrated in the example above where the link is set as a child of the "network" business object.

How to retrieve business object structural information

The current implementation of IltDefaultDataSource handles structural information, such as child-parent relationships described earlier, pertaining to IlpObject instances independently of the objects themselves. This implementation makes it possible for you to load objects on demand. See How to implement load-on-demand in a data source for more information.
The structural information is defined in JViews TGO through the following interfaces:
  • IlpChild—This interface defines the method Object getParent(IlpObject object) , which returns the parent object identifier from the given business object.
  • IlpContainer—This interface defines the method Collection getChildren(IlpObject object) , which returns the list of child identifiers from the given business object.
  • IlpLink—This interface defines the structural information needed to indicate that a business object is a link between two other business objects. This interface declares the methods Object getFrom(IlpObject object) and Object getTo(IlpObject object) .
  • IlpLinkExtremity—This interface defines the structural information to indicate that a business object is the end of links. This interface declares method Collection getLinks(IlpObject object) .
The default data source implementation provides the following methods to retrieve each one of these interfaces:
  • IlpChild getChildInterface (Object childIdOrIlpObject)
  • IlpContainer getContainerInterface (Object containerIdOrIlpObject)
  • IlpLink getLinkInterface (Object linkIdOrIlpObject)
  • IlpLinkExtremity getLinkExtremityInterface (Object linkIdOrIlpObject)
You can use the following convenience methods to retrieve the structural information. These methods return the structural information based on the fact that the queried business objects are all present in the data source. If this is not the case, you should retrieve the structural information using the interfaces instead.
  • IlpObject getParent (IlpObject object) : Returns the parent of the given object.
  • Collection getChildren (IlpObject object) : Returns the collection of child objects for the given object.
  • Collection getLinks (IlpObject node) : Returns the collection of links that have the given node as an end point.
  • IlpObject getFrom (IlpObject link) : Returns the from end point of the given link object.
  • IlpObject getTo (IlpObject link) : Returns the to end point of the given link object.