Creating a port with the API

When you create a port with the API, you must provide its type, which can be set through the constructor or through the setAttributeValue method.

How to create a port with the API

The following sample shows how to create a port of type Centronics_36f.
// Create a shelf, set its position and add to data source
IltShelf s1 = new IltShelf(2, 65, 3, 20, 0);
s1.setAttributeValue(IltShelf.PositionAttribute, new IlpPoint(20, 50));
dataSource.addObject(s1);

// create a card, set its position (relative to s1) and 
// add to data source
IltCard c1 = new IltCard();
c1.setAttributeValue(IltCard.PositionAttribute, 
  new IlpShelfItemPosition(0, 1, 1, 1));
dataSource.addObject(c1);

// create shelf item, set its position (relative to c1) and
// add it to data source
IltPort port = new IltPort("port", IltPort.Type.Centronics_36f, null);
port.setAttributeValue(IltPort.PositionAttribute, 
                       new IlpRelativePoint(33, 10));
dataSource.addObject(port);

// set relationship
dataSource.setParent(port.getIdentifier(), c1.getIdentifier());
dataSource.setParent(c1.getIdentifier(), s1.getIdentifier());
The result looks like this:
portwithapi103.gif
A shelf containing a card with a port