Business Objects and Data Sources > Subnetworks > Creating a Subnetwork with the API

This section shows how to create a subnetwork through the API and how to add it to a data source.

The following procedure creates the same subnetwork as in Loading a Subnetwork Defined in XML but through coding.

  1. Create the subnetwork
IltNetworkElement subNetwork1 = new IltNetworkElement("SubNetwork1");
subNetwork1.setName("SubNetwork");
subNetwork1.setType(IltNetworkElement.Type.NMW);
  1. Create the first child objects
List children = new ArrayList();
IltNetworkElement subNode1 = new IltNetworkElement("SubNode1");
subNode1.setName("BSC1");
subNode1.setType(IltNetworkElement.Type.BSC);
subNode1.setPosition(new IlpPoint(580, 80));
IltAlarmObjectState alarmState = new IltAlarmObjectState();
IltAlarm.State alarms = (IltAlarm.State)alarmState.getAlarmState();
alarms.setNewAlarmCount(IltAlarm.Severity.Warning, 2);
subNode1.setObjectState(alarmState);
children.add(subNode1);
  1. Add the first child object to the subnetwork
datasource.setParent(subNode1, subNetwork1);
  1. Create the second child object
IltNetworkElement subNode2 = new IltNetworkElement("SubNode2");
subNode2.setName("BTS2");
subNode2.setType(IltNetworkElement.Type.BTS_Image);
subNode2.setPosition(new IlpPoint(620, 180));
IltOSIObjectState osiState = 
  new IltOSIObjectState(new IltOSI.State(IltOSI.State.Operational.Enabled, 
                                         IltOSI.State.Usage.Active, 
                                         IltOSI.State.Administrative.ShuttingDown));
IltAlarm.State alarms = (IltAlarm.State)osiState.getAlarmState();
alarms.setNewAlarmCount(IltAlarm.Severity.Warning, 4);
osiState.set(IltOSI.Procedural.Reporting);
osiState.set(IltOSI.Repair.UnderRepair);
osiState.set(IltPerformance.SecState.Output, new Float(150));
subNode2.setObjectState(ostate);
children.add(subNode2);
  1. Add the second child to the subnetwork
datasource.setParent(subNode2, subNetwork1);
  1. Create an internal link
IltLink link = new IltLink("SubNode1-SubNode2");
link.setName("InternalLink");
link.setMedia(null);
link.setObjectState(new
                    IltBiSONETObjectState(IltSONET.State.ActiveProtecting,
                    null));
children.add(link);
  1. Add the link to the subnetwork
datasource.setParent(link, subNetwork1);
  1. Add the link relationship
datasource.setLink(link, subNode1, subNode2);
  1. Add all the objects to the data source
datasource.addObject(subNetwork1);
datasource.addObjects(children);

Note
For a subnetwork to be properly displayed, the parent object must be customized as a container node. Customization is achieved through CSS using the expansion property. For details, refer to section Customizing Subnetworks in the Styling documentation.