skip to main content
TGO > Programmers documentation > Business objects and data sources > Links > Link programming examples
 
Link programming examples
The same example using XML can be found in <installdir>/samples/network/links.
How to create a network
The network is created using the network component and the data source API, as illustrated in the following code:
 
 /**
   * Execute the main part of the sample.
   */
  void doSample (Container container) {
   try {
      // Initialize JTGO
      // Read a deployment descriptor file to initialize JTGO services
      IltSystem.Init("deploy.xml");
 
      // Create a datasource
      IltDefaultDataSource dataSource = new IltDefaultDataSource();
      fillNetwork(dataSource);
 
      // Create a network component
      IlpNetwork networkComponent = new IlpNetwork();
 
      // Connect network component to datasource
      networkComponent.setDataSource(dataSource);
 
      // Add view to the frame
      container.add(networkComponent);
    }
    catch(Exception e){
      e.printStackTrace();
    }
  }
How to add network elements and links to the network
The function fillNetwork creates network elements and links and adds these instances to the given data source. Then the data source is linked to the network component.
 
  /**
   * Adds nodes and all kinds of links to the network.
   */
  public void fillNetwork (IltDefaultDataSource dataSource) {
    // Create the network elements.
    IltNetworkElement paris;
    IltNetworkElement berlin;
    IltNetworkElement oslo;
    IltNetworkElement nwest;
 
    paris =
      new IltNetworkElement("Paris",
                            IltNetworkElement.Type.NE,
                            IltNetworkElement.Function.SwitchCrossConnect,
                            null,
                            new IltBellcoreObjectState());
    berlin =
      new IltNetworkElement("Berlin",
                            IltNetworkElement.Type.NE,
                            IltNetworkElement.Function.TransportCrossConnect,
                            IltNetworkElement.Family.OC12,
                            new IltBellcoreObjectState());
    oslo =
      new IltNetworkElement("Oslo",
                            IltNetworkElement.Type.NE,
                            IltNetworkElement.Function.Transport,
                            null,
                            new IltBellcoreObjectState());
    nwest =
      new IltNetworkElement("North West",
                            IltNetworkElement.Type.NMW,
                            new IltBellcoreObjectState());
 
    // Place the network elements at the right location while inserting
    // them in the network.
    paris.setState(IltBellcore.State.EnabledActive);
    paris.setAttributeValue(IltObject.PositionAttribute, new IlpPoint(120,
                                                                      365));
    berlin.setState(IltBellcore.State.EnabledActive);
    berlin.setAttributeValue(IltObject.PositionAttribute, new IlpPoint(300,
                                                                         250));
    oslo.setState(IltBellcore.State.EnabledActive);
    oslo.setAttributeValue(IltObject.PositionAttribute, new IlpPoint(190,
                                                                     100));
    nwest.setState(IltBellcore.State.EnabledActive);
    nwest.setAttributeValue(IltObject.PositionAttribute, new IlpPoint(37, 40));
 
    dataSource.addObject(paris);
    dataSource.addObject(berlin);
    dataSource.addObject(oslo);
    dataSource.addObject(nwest);
 
    // Add all kinds of links
    addSelfLink(dataSource, paris);
    addBiSONETLinks(dataSource, oslo, nwest);
  }
How to create a self-link
The addSelfLink method creates a self link to Paris with an associated state and an arrow. Note that in self-links the "From" and "To" nodes are the same.
 
/**
 * Adds a link with the given node as both its from and to end.
 */
public void addSelfLink (IltDefaultDataSource dataSource, IltObject node) {
  IltLink link = new IltLink(new IltSONETObjectState(), null);
  link.setState(IltSONET.State.Active);
  dataSource.addObject(link);
  dataSource.setLink(link.getIdentifier(),
                     node.getIdentifier(),
                     node.getIdentifier());
}
How to create links with BiSONET object states
The addBiSONETLinks method creates two links with an object state of type IltBiSONETObjectState. The setReverseState method is used to set the state of the link in the opposite direction.
 
/**
 * Adds some bi-SONET links between the given nodes.
 */
public void addBiSONETLinks (IltDefaultDataSource dataSource,
                             IltObject node1,
                             IltObject node2) {
  // Create a bi-SONET link.
  IltBiSONETObjectState biState = new IltBiSONETObjectState();
  IltLink link = new IltLink(biState);
  // Set its two states.
  biState.setState(IltSONET.State.TroubledProtected);
  biState.setReverseState(IltSONET.State.Active);
  dataSource.addObject(link);
  dataSource.setLink(link.getIdentifier(),
                     node1.getIdentifier(),
                     node2.getIdentifier());
 
  IltBiSONETObjectState biState2 = new IltBiSONETObjectState();
  IltLink link2 = new IltLink(biState2);
  biState2.setState(IltSONET.State.ActiveProtecting);
  biState2.setReverseState(IltSONET.State.TroubledUnprotected);
  dataSource.addObject(link2);
  dataSource.setLink(link2.getIdentifier(),
                       node2.getIdentifier(),
                       node1.getIdentifier());
}

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