Business Objects and Data Sources > Shelves and Cards > Ports > Creating a Port with the API

This section shows how to create a port using the API and how to add it to the data source.

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; the following sample shows how to create a port of type Centronics_36f:

How to Create a Port with the API
// Create a shelf, set its position and add to datasource
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 datasource
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 datasource
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:

images/portwithapi103.gif

Figure 8.16 A Shelf Containing a Card with a Port