mapss.dif.graph.hierarchy
Class Port

java.lang.Object
  extended by mapss.dif.graph.hierarchy.Port

public class Port
extends java.lang.Object

Port class for interfacing of hierarchy objects with other hierarchies.

Inside a hierarchy, A Port of this hierarchy can relate to a single Node or relate to a port of a super node inside this hierarchy. We use "relate" to associate node inside a hierarchy.

A port A connect to a port B (B in higher hierarchy), which means B relate to A.

We restrict that a port can connect to either single edge or a single port in higher hierarchy, but not both. We use "connect" to associate edges or a port outside a hierarchy.

For more information about how to use this class refer to the package documentation.

Version:
$Id: Port.java 409 2007-05-13 19:47:16Z plishker $
Author:
Fuat Keceli
See Also:
Graph

Field Summary
static int IN
          Indicates that a port is an input port.
static int INOUT
          Indicates that a port is a bi-directional port.
static int OUT
          Indicates that a port is an output port.
 
Constructor Summary
Port(java.lang.String name, Hierarchy hierarchy)
          Construct an undirected port.
Port(java.lang.String name, Hierarchy hierarchy, int direction)
          Construct a directed port.
 
Method Summary
 java.lang.Object connect(mocgraph.Edge edge)
          Connect a port to an edge.
 java.lang.Object connect(Port port)
          Connect a port to another port.
 java.lang.Object disconnect()
          Disconnects a port from its edge or super-port.
 void dispose()
          Disposes an unconnected port.
 java.lang.Object getConnection()
          Returns the edge or port connected to this port.
 int getDirection()
          Returns the direction of a port.
 Hierarchy getHierarchy()
          Returns the hierarchy that this port belongs.
 java.lang.String getName()
          Returns the name of this port.
 mocgraph.Node getNode()
          Returns the node associated with this port.
 Port getRelatedPort()
          Returns the port that is connected to this port from the inside of the hierarchy.
 boolean isConnected()
          Returns true if the port is connected, false otherwise.
 boolean isDisposed()
          Returns true if this object is disposed and not available for future usage.
 boolean isRelated()
          Returns true if the port is related, false otherwise.
 Port mirror(Hierarchy hierarchy, mocgraph.analysis.strategy.MirrorTransformerStrategy transformation)
          Mirrors a port without copying its connection field.
 java.lang.Object relate(mocgraph.Node node)
          Defines an inner connection between a node and a port of a hierarchy.
 java.lang.Object relate(Port port)
          Defines an inner connection between a sub-port and a port of a hierarchy.
 java.lang.String toString()
          Returns the long name of this port.
 java.lang.Object unrelate()
          Disconnects the inner connection of this port.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

IN

public static final int IN
Indicates that a port is an input port.

See Also:
Constant Field Values

OUT

public static final int OUT
Indicates that a port is an output port.

See Also:
Constant Field Values

INOUT

public static final int INOUT
Indicates that a port is a bi-directional port.

See Also:
Constant Field Values
Constructor Detail

Port

public Port(java.lang.String name,
            Hierarchy hierarchy)
Construct an undirected port.

Parameters:
name - Name of the port.
hierarchy - The hierarchy that contains this port.
Throws:
HierarchyException - If HierarchyException.checkPort(mapss.dif.graph.hierarchy.Hierarchy, mapss.dif.graph.hierarchy.Port) returns an exception.
HierarchyException - If Conventions.labelConvention(java.lang.String) returns an error.

Port

public Port(java.lang.String name,
            Hierarchy hierarchy,
            int direction)
Construct a directed port.

Parameters:
name - Name of the port.
hierarchy - The hierarchy that contains this port.
direction - IN or OUT.
Throws:
HierarchyException - If HierarchyException.checkPort(mapss.dif.graph.hierarchy.Hierarchy, mapss.dif.graph.hierarchy.Port) returns an exception.
HierarchyException - If Conventions.labelConvention(java.lang.String) returns an error.
Method Detail

connect

public java.lang.Object connect(mocgraph.Edge edge)
Connect a port to an edge.

Parameters:
edge - Edge to be connected.
Returns:
Previous connection if it existed, null otherwise.
Throws:
HierarchyException - If HierarchyException.checkConnection(mocgraph.Edge, mapss.dif.graph.hierarchy.Port) returns an exception.
HierarchyException - If the port was disposed.

connect

public java.lang.Object connect(Port port)
Connect a port to another port.

Parameters:
port - A port in the super hierarchy of this hierarchy.
Returns:
Previous connection (a port or an edge), null if it doesn't exist.
Throws:
HierarchyException - If HierarchyException.checkConnection(mocgraph.Edge, mapss.dif.graph.hierarchy.Port) returns an exception.
HierarchyException - If the port was disposed.

disconnect

public java.lang.Object disconnect()
Disconnects a port from its edge or super-port. If the connection is a super-port superPort.unrelate() is called too.

Returns:
Previous connection (a port or an edge), null if it doesn't exist.

dispose

public void dispose()
Disposes an unconnected port. Removes it from the hierarchy port list and clears all connections of the port.

Throws:
HierarchyException - If the port was already disposed.

getConnection

public java.lang.Object getConnection()
Returns the edge or port connected to this port.

Returns:
An edge or port in the super hierarchy.

getDirection

public int getDirection()
Returns the direction of a port.

Returns:
A positive integer for "out", a negative integer for "in" and zero for an undirected port.

getHierarchy

public Hierarchy getHierarchy()
Returns the hierarchy that this port belongs.

Returns:
The hierarchy that this port belongs.

getName

public java.lang.String getName()
Returns the name of this port.

Returns:
The name of this port.

getNode

public mocgraph.Node getNode()
Returns the node associated with this port.

Returns:
A node of this hierarchy.

getRelatedPort

public Port getRelatedPort()
Returns the port that is connected to this port from the inside of the hierarchy.

Returns:
A port from a sub-hierarchy. Null if it doesn't exist.

isConnected

public boolean isConnected()
Returns true if the port is connected, false otherwise.

Returns:
True if the port is connected, false otherwise.

isDisposed

public boolean isDisposed()
Returns true if this object is disposed and not available for future usage.

Returns:
True if the object is disposed.

isRelated

public boolean isRelated()
Returns true if the port is related, false otherwise.

Returns:
True if the port is related, false otherwise.

mirror

public Port mirror(Hierarchy hierarchy,
                   mocgraph.analysis.strategy.MirrorTransformerStrategy transformation)
Mirrors a port without copying its connection field. This method is mainly useful for mirroring hierarchies. To be able to use method a copy of the hierarchy graph should be obtained using MirrorTransformerStrategy and the hierarchy that is backed by the copy graph should be passed to this method. The associated node of the port will be automatically converted but connection of the port will be left undefined.

Parameters:
hierarchy - The copy hierarchy backed up by the mirrored graph.
transformation - Transformer that mirrored the original graph.
Returns:
The mirrored port.
See Also:
Hierarchy.mirror(boolean)

relate

public java.lang.Object relate(mocgraph.Node node)
Defines an inner connection between a node and a port of a hierarchy. This method is different than connect(mocgraph.Edge) in the way that, connect defines a connection with a super hierarchy.

Parameters:
node - A node in the hierarchy to which this node belongs.
Returns:
Previous inner connection (a node or a port), null if it doesn't exist.

relate

public java.lang.Object relate(Port port)
Defines an inner connection between a sub-port and a port of a hierarchy. This method is different than connect(mocgraph.Edge) in the way that, connect defines a connection with a super hierarchy.

Parameters:
port - A port in a sub-hierarchy of this hierarchy.
Returns:
Previous inner connection (a node or a port), null if it doesn't exist.
Throws:
HierarchyException - If HierarchyException.checkConnection(mocgraph.Edge, mapss.dif.graph.hierarchy.Port) returns an exception.

toString

public java.lang.String toString()
Returns the long name of this port.

Overrides:
toString in class java.lang.Object
Returns:
Long name of the port: hierarchyName.portName

unrelate

public java.lang.Object unrelate()
Disconnects the inner connection of this port. If the inner connection is another port outer connection of that port is disconnected too.

Returns:
The cancelled connection (a node or a port), null if it doesn't exist.