e82e46e8b6ea38375ca416fd643066c51d23edf7
[jump.git] / dol / src / dol / datamodel / pn / Port.java
1 /* $Id: Port.java 1 2010-02-24 13:03:05Z haidw $ */
2 package dol.datamodel.pn;
3
4 import dol.visitor.PNVisitor;
5
6 /**
7  * This class represents a port of a process or channel.
8  */
9 public class Port {
10
11     /**
12      *  Constructor to create a Port with a name.
13      */
14     public Port(String name) {
15         _name = name;
16         _isInPort = false;
17         _isOutPort = false;
18     }
19
20     public Port(String name, boolean type) {
21         _name = name;
22         _isInPort = (type == INPORT);
23         _isOutPort = (type == OUTPORT);
24     }
25
26
27     /**
28      * Accept a visitor.
29      *
30      * @param x visitor object
31      */
32     public void accept(PNVisitor x) {
33         x.visitComponent(this);
34     }
35
36     /**
37      * Clone this Port
38      *
39      * @return new instance of the Port
40      */
41     public Object clone() {
42         try {
43             Port newObj = (Port) super.clone();
44             newObj.setName(_name);
45             newObj.setBasename(_basename);
46             newObj.setPeerPort(_peerPort);
47             newObj.setPeerResource(_peerResource);
48             newObj.setResource(_resource );
49             return (newObj);
50         } catch (CloneNotSupportedException e) {
51             System.out.println("Error Clone not Supported");
52         }
53         return null;
54     }
55
56     /**
57      * Check whether this port is an inport.
58      *
59      * @return true if this port is an inport, otherwise false
60      */
61     public boolean isInPort() {
62         return _isInPort;
63     }
64
65     /**
66      * Check whether this port is an outport.
67      *
68      * @return true if this port is an outport, otherwise false
69      */
70     public boolean isOutPort() {
71         return _isOutPort;
72     }
73
74     /**
75      * Get the name of this port.
76      *
77      * @return name of the port
78      */
79     public String getName() {
80         return _name;
81     }
82
83     /**
84      * Set the name of this port.
85      *
86      * @param name name of the port
87      */
88     public void setName(String name) {
89         _name = name;
90     }
91
92     /**
93      * Get the range of this port.
94      *
95      * @return range of the port
96      */
97     public String getRange() {
98         return _range;
99     }
100
101     /**
102      * Set the range of this port.
103      *
104      * @param range range of the port
105      */
106     public void setRange(String range) {
107         _range= range;
108     }
109
110     /**
111      * Get the resource of this port.
112      *
113      * @return the resource
114      */
115     public Resource getResource() {
116         return _resource;
117     }
118
119     /**
120      * Set the process of this port.
121      *
122      * @param  resource The new resource
123      */
124     public void setResource(Resource resource) {
125         _resource = resource;
126     }
127
128     public void setBasename(String basename) { _basename = basename; }
129     public String getBasename() { return _basename; }
130
131     // for channel port
132     public void setPeerPort(Port peer) { _peerPort = peer; }
133     public Port getPeerPort() { return _peerPort; }
134
135     // for process port: peer channel name
136     public void setPeerResource(Resource n) { _peerResource = n; }
137     public Resource getPeerResource() { return _peerResource; }
138
139     public String getType() {
140         if (_isInPort) return  "input";
141         else if (_isOutPort) return "output";
142         else return "";
143     }
144
145     /**
146      * Return a string representation of the port.
147      *
148      * @return string representation of the port
149      */
150     public String toString() {
151         return "Port: " + _name;
152     }
153
154     /** constant for inport for usage in the constructor **/
155     public static final boolean INPORT = true;
156
157     /** constant for outport for usage in the constructor **/
158     public static final boolean OUTPORT = false;
159
160     /** defines whether this port is an inport **/
161     protected boolean _isInPort = false;
162
163     /** defines whether this port is an outport **/
164     protected boolean _isOutPort = false;
165
166     /** name of the port */
167     protected String _name = null;
168
169     /** basename of the resource, if no basename, store the name */
170     protected String _basename = null;
171
172     /** resource (process or channel) this port belongs to */
173     protected Resource _resource = null;
174
175     /** resource which peerPort belongs to */
176     protected Resource _peerResource = null;
177
178     /** connected peer port name */
179     protected Port _peerPort = null;
180
181     /** peer channel name */
182     protected String _channelName = null;
183
184     /**
185      * Range of the iterator when the instance belongs to an iterated
186      * series of ports.
187      */
188     protected String _range = "";
189 }