4.1.4 Ports
While the Diagram Editor does not provide as extensive editing
options for ports as it provides for most other metatypes, ports still remain an
important diagram element type. The strength of ports is their ability to
characterize how the roles are connected with objects in bindings, making them a
prominent concept during the relationships and role creation when
present.
Static ports
Static ports are – as their name implies – defined
as constant static parts in object symbols, so all instances of a given type
have the same ports. For example, in
Figure 4–16 below, both A and B
have explicit rectangular areas that stand for the IN and OUT ports:

Figure 4–16. Static ports.
During relationship or
role creation the ports are offered as connectable areas when the cursor is over
them, as shown in
Figure
4–17:

Figure 4–17. Connecting to a port.
The connection is
validated when the binding is completed. Ports, if present in the metamodel, add
more precision to the binding semantics, enabling us to define such advanced
binding rules like ‘connections from the OUT port must connect to the IN
port at the other end’, as in our example above. The static ports also
have properties that can be used to form even more precise rules. For example,
if our OUT and IN ports have a property Voltage, we could say that the
connection between them is possible only when the value for the Voltage property
is the same for both ports (i.e. only 5V IN can be connected with 5V OUT). These
rules are defined by the metamodeler, and the port property values are not
directly visible to the modeler: the rule will be explained when the modeler
tries to break it.
Dynamic ports
The main difference between static and dynamic ports is that
while the former are always defined as constant part of the object’s
symbol and refer to an existing Port instance, the latter are dynamically
created references to other Objects in the model. Dynamic ports are fetched at
runtime and they can come from various sources: they can be in the host
object’s properties or objects from its subgraph, or they can be collected
with a generator. Once fetched, the dynamic ports are shown as part of the
object’s symbol, as in
Figure
4–18.

Figure 4–18. Dynamic ports allocated as part of the object symbols.
Dynamic
ports are revealed as connectables during relationship or role creation, in a
similar way to static ports, and they provide similar ways to extend the binding
semantics. There is, however, one difference between static and dynamic ports
when they are connected: while static ports are always fixed to the location
defined by the symbol, dynamic ports can be moved if the metamodel allows it. To
move a dynamic port, select the role attached to it and drag the handle at the
port end of the role.
 | As
dynamic ports are created at run-time from sources that do not necessarily
remain unchanged over the time, it is possible that a dynamic port may not
always be available or may disappear completely. If there has been a connection
to such a dynamic port, the role will be automatically connected to the host
object’s default connectable. Sometimes this may require refreshing the
diagram (certain operations – like scrolling the drawing area – may
update the object that has been changed but not invalidate the existing role
line, resulting in visually incorrect diagram display until the diagram is
explicitly refreshed). |