dol: initial dol commit
[jump.git] / dol / src / dol / datamodel / pn / Port.java
diff --git a/dol/src/dol/datamodel/pn/Port.java b/dol/src/dol/datamodel/pn/Port.java
new file mode 100644 (file)
index 0000000..e82e46e
--- /dev/null
@@ -0,0 +1,189 @@
+/* $Id: Port.java 1 2010-02-24 13:03:05Z haidw $ */
+package dol.datamodel.pn;
+
+import dol.visitor.PNVisitor;
+
+/**
+ * This class represents a port of a process or channel.
+ */
+public class Port {
+
+    /**
+     *  Constructor to create a Port with a name.
+     */
+    public Port(String name) {
+        _name = name;
+        _isInPort = false;
+        _isOutPort = false;
+    }
+
+    public Port(String name, boolean type) {
+        _name = name;
+        _isInPort = (type == INPORT);
+        _isOutPort = (type == OUTPORT);
+    }
+
+
+    /**
+     * Accept a visitor.
+     *
+     * @param x visitor object
+     */
+    public void accept(PNVisitor x) {
+        x.visitComponent(this);
+    }
+
+    /**
+     * Clone this Port
+     *
+     * @return new instance of the Port
+     */
+    public Object clone() {
+        try {
+            Port newObj = (Port) super.clone();
+            newObj.setName(_name);
+            newObj.setBasename(_basename);
+            newObj.setPeerPort(_peerPort);
+            newObj.setPeerResource(_peerResource);
+            newObj.setResource(_resource );
+            return (newObj);
+        } catch (CloneNotSupportedException e) {
+            System.out.println("Error Clone not Supported");
+        }
+        return null;
+    }
+
+    /**
+     * Check whether this port is an inport.
+     *
+     * @return true if this port is an inport, otherwise false
+     */
+    public boolean isInPort() {
+        return _isInPort;
+    }
+
+    /**
+     * Check whether this port is an outport.
+     *
+     * @return true if this port is an outport, otherwise false
+     */
+    public boolean isOutPort() {
+        return _isOutPort;
+    }
+
+    /**
+     * Get the name of this port.
+     *
+     * @return name of the port
+     */
+    public String getName() {
+        return _name;
+    }
+
+    /**
+     * Set the name of this port.
+     *
+     * @param name name of the port
+     */
+    public void setName(String name) {
+        _name = name;
+    }
+
+    /**
+     * Get the range of this port.
+     *
+     * @return range of the port
+     */
+    public String getRange() {
+        return _range;
+    }
+
+    /**
+     * Set the range of this port.
+     *
+     * @param range range of the port
+     */
+    public void setRange(String range) {
+        _range= range;
+    }
+
+    /**
+     * Get the resource of this port.
+     *
+     * @return the resource
+     */
+    public Resource getResource() {
+        return _resource;
+    }
+
+    /**
+     * Set the process of this port.
+     *
+     * @param  resource The new resource
+     */
+    public void setResource(Resource resource) {
+        _resource = resource;
+    }
+
+    public void setBasename(String basename) { _basename = basename; }
+    public String getBasename() { return _basename; }
+
+    // for channel port
+    public void setPeerPort(Port peer) { _peerPort = peer; }
+    public Port getPeerPort() { return _peerPort; }
+
+    // for process port: peer channel name
+    public void setPeerResource(Resource n) { _peerResource = n; }
+    public Resource getPeerResource() { return _peerResource; }
+
+    public String getType() {
+        if (_isInPort) return  "input";
+        else if (_isOutPort) return "output";
+        else return "";
+    }
+
+    /**
+     * Return a string representation of the port.
+     *
+     * @return string representation of the port
+     */
+    public String toString() {
+        return "Port: " + _name;
+    }
+
+    /** constant for inport for usage in the constructor **/
+    public static final boolean INPORT = true;
+
+    /** constant for outport for usage in the constructor **/
+    public static final boolean OUTPORT = false;
+
+    /** defines whether this port is an inport **/
+    protected boolean _isInPort = false;
+
+    /** defines whether this port is an outport **/
+    protected boolean _isOutPort = false;
+
+    /** name of the port */
+    protected String _name = null;
+
+    /** basename of the resource, if no basename, store the name */
+    protected String _basename = null;
+
+    /** resource (process or channel) this port belongs to */
+    protected Resource _resource = null;
+
+    /** resource which peerPort belongs to */
+    protected Resource _peerResource = null;
+
+    /** connected peer port name */
+    protected Port _peerPort = null;
+
+    /** peer channel name */
+    protected String _channelName = null;
+
+    /**
+     * Range of the iterator when the instance belongs to an iterated
+     * series of ports.
+     */
+    protected String _range = "";
+}