Creating a subnetwork with the API

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);
    
  2. Create the first child objects
    List<IlpObject> children = new ArrayList<IlpObject>();
    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);
    
  3. Add the first child object to the subnetwork
    datasource.setParent(subNode1, subNetwork1);
    
  4. 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 osiAlarms = (IltAlarm.State)osiState.getAlarmState();
    osiAlarms.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(osiState);
    children.add(subNode2);
    
  5. Add the second child to the subnetwork
    datasource.setParent(subNode2, subNetwork1);
    
  6. 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);
    
  7. Add the link to the subnetwork
    datasource.setParent(link, subNetwork1);
    
  8. Add the link relationship
    datasource.setLink(link, subNode1, subNode2);
    
  9. 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 Customizing subnetworks.