dol: initial dol commit
[jump.git] / dol / src / dol / datamodel / architecture / PortNode.java
1 /* $Id: PortNode.java 1 2010-02-24 13:03:05Z haidw $ */
2 package dol.datamodel.architecture;
3
4 import dol.visitor.ArchiVisitor;
5
6 /**
7  * This class represents a port of an architectural node.
8  */
9 public class PortNode implements Cloneable {
10     /**
11      *  Constructor to create a PortNode with a name.
12      */
13     public PortNode(String name) {
14         _name = name;
15         _isInPort = false;
16         _isOutPort = false;
17         _isInOutPort = false;
18     }
19
20     /**
21      *  Constructor to create a PortNode with a name and a type.
22      */
23     public PortNode(String name, boolean type) {
24         _name = name;
25         _isInPort = (type == INPORT);
26         _isOutPort = (type == OUTPORT);
27         _isInOutPort = (type == INOUTPORT);
28     }
29
30     /**
31      * Accept a visitor.
32      *
33      * @param x visitor object
34      */
35     public void accept(ArchiVisitor x) {
36         x.visitComponent(this);
37     }
38
39     /**
40      * Clone this PortNode
41      *
42      * @return new instance of the PortNode
43      */
44     public Object clone() {
45         try {
46             PortNode newObj = (PortNode) super.clone();
47             newObj.setName(_name);
48             newObj.setBasename(_basename);
49             newObj.setPeerPort(_peerPort);
50             newObj.setPeerResource(_peerResource);
51             newObj.setPeerNode(_peerNode);
52             newObj.setResource(_resource );
53             newObj.setNode(_node);
54             return (newObj);
55         } catch (CloneNotSupportedException e) {
56             System.out.println("Error Clone not Supported");
57         }
58         return null;
59     }
60
61     /**
62      * Check whether this port is an inport.
63      *
64      * @return true if this port is an inport, otherwise false
65      */
66     public boolean isInPort() {
67         return _isInPort;
68     }
69
70     /**
71      * Check whether this port is an outport.
72      *
73      * @return true if this port is an outport, otherwise false
74      */
75     public boolean isOutPort() {
76         return _isOutPort;
77     }
78
79     /**
80      * Check whether this port is an inoutport.
81      *
82      * @return true if this port is an inoutport, otherwise false
83      */
84     public boolean isInOutPort() {
85         return _isInOutPort;
86     }
87
88     /**
89      * Get the name of this port.
90      *
91      * @return name of the port
92      */
93     public String getName() {
94         return _name;
95     }
96
97     /**
98      * Set the name of this port.
99      *
100      * @param name name of the port
101      */
102     public void setName(String name) {
103         _name = name;
104     }
105
106     public void setBasename(String basename) { _basename = basename; }
107     public String getBasename() { return _basename; }
108
109     /**
110      * Get the range of this port.
111      *
112      * @return range of the port
113      */
114     public String getRange() {
115         return _range;
116     }
117
118     /**
119      * Set the range of this port.
120      *
121      * @param range range of the port
122      */
123     public void setRange(String range) {
124         _range= range;
125     }
126
127     /**
128      * Get the resource/node of this port.
129      *
130      * @return the resource/node
131      */
132     public ArchiResource getResource() {
133         return _resource;
134     }
135     public Node getNode() {
136         return _node;
137     }
138
139     /**
140      * Set the resource/node of this port.
141      *
142      * @param resource
143      */
144     public void setResource(ArchiResource resource) {
145         _resource = resource;
146     }
147     public void setNode(Node node) {
148         _node = node;
149     }
150
151     /**
152      * Set the peer resource/node/port of this port.
153      *
154      * @param peer The new node
155      */
156     public void setPeerPort(PortNode peer) { _peerPort = peer; }
157
158     /**
159      *
160      */
161     public void setPeerResource(ArchiResource n) { _peerResource = n; }
162
163     /**
164      *
165      */
166     public void setPeerNode(Node n) { _peerNode = n; }
167
168     /**
169      * Get the peer resource/node/port of this port.
170      *
171      * @return the peer resource/node/port
172      */
173     public PortNode getPeerPort(){ return _peerPort; }
174
175     /**
176      *
177      */
178     public ArchiResource getPeerResource() { return _peerResource; }
179
180     /**
181      *
182      */
183     public Node getPeerNode() { return _peerNode; }
184
185     /**
186      * Get the type of this port.
187      *
188      * @return type of this port
189      */
190     public String getType() {
191         if (_isInPort) return  "input";
192         if (_isOutPort) return "output";
193         if (_isInOutPort) return "duplex";
194         return "type not set.";
195     }
196
197     /**
198      * Return a string representation of the port.
199      *
200      * @return string representation of the port
201      */
202     public String toString() {
203         return "PortNode: " + _name;
204     }
205
206     /** constant for inport for usage in the constructor **/
207     public static final boolean INPORT = true;
208
209     /** constant for outport for usage in the constructor **/
210     public static final boolean OUTPORT = false;
211
212     /** constant for inoutport for usage in the constructor **/
213     public static final boolean INOUTPORT = false;
214
215     /** defines whether this port is an inport **/
216     protected boolean _isInPort = false;
217
218     /** defines whether this port is an outport **/
219     protected boolean _isOutPort = false;
220
221     /** defines whether this port is an inout **/
222     protected boolean _isInOutPort = false;
223
224     /** name of the port */
225     protected String _name = null;
226
227     /** basename of the resource, if no basename, store the name */
228     protected String _basename = null;
229
230     /** resource (process or channel) this port belongs to */
231     protected ArchiResource _resource = null;
232
233     /** node this port belongs to */
234     protected Node _node = null;
235
236     /** resource which peerPort belongs to */
237     protected ArchiResource _peerResource = null;
238
239     /** node which peerPort belongs to */
240     protected Node _peerNode = null;
241
242     /** connected peer port name */
243     protected PortNode _peerPort = null;
244
245     /** peer channel name */
246     protected String _channelName = null;
247
248     /**
249      * Range of the iterator when the instance belongs to an iterated
250      * series of ports.
251      */
252     protected String _range = null;
253 }