dol: initial dol commit
[jump.git] / dol / src / dol / datamodel / architecture / Node.java
1 /* $Id: Node.java 1 2010-02-24 13:03:05Z haidw $ */
2 package dol.datamodel.architecture;
3
4 import java.util.Vector;
5
6 import dol.visitor.ArchiVisitor;
7
8 /**
9  * This class represents a node in the archietcture.
10  */
11 public class Node implements Cloneable {
12
13     /**
14      * Constructor to create a Node with a name and an empty
15      * portList.
16      */
17     public Node(String name) {
18         _name = name;
19         _basename = name;
20         _portList = new Vector<PortNode>();
21     }
22
23     /**
24      * Accept a Visitor
25      * @param x A Visitor Object.
26      */
27     public void accept(ArchiVisitor x) {
28         x.visitComponent(this);
29     }
30
31     /**
32      * Clone this Node
33      *
34      * @return a new instance of the Node.
35      */
36     public Object clone() {
37         try {
38             Node newObj = (Node) super.clone();
39             newObj.setName(_name);
40             newObj.setBasename(_basename);
41             return (newObj);
42         } catch (CloneNotSupportedException e) {
43             System.out.println("Error Clone not Supported");
44         }
45         return null;
46     }
47
48     /**
49      * Get the range of this node.
50      *
51      * @return range
52      */
53    public String getRange() {
54         return _range;
55     }
56
57     /**
58      * Set the range of this node.
59      *
60      * @param range new range value
61      */
62      public void setRange(String range) {
63         _range= range;
64     }
65
66
67     /**
68      * Get the name of this node.
69      *
70      * @return name of the node
71      */
72     public String getName() {
73         return _name;
74     }
75
76     /**
77      * Set the name of this node.
78      *
79      * @param name name of the node
80      */
81     public void setName(String name) {
82         _name = name;
83     }
84
85     /**
86      * Get the basename of this node.
87      *
88      * @return basename of the node
89      */
90     public String getBasename() {
91         return _basename;
92     }
93
94     /**
95      * Set the basename of this node.
96      *
97      * @param basename name of the node
98      */
99     public void setBasename(String basename) {
100         _basename = basename;
101     }
102
103     /**
104      * Has this node IN/OUT/INOUT ports?
105      *
106      * @return boolean value
107      */
108     public boolean hasInPorts() {
109         for (PortNode port : getPortList()) {
110             if (port.isInPort())
111                 return true;
112         }
113         return false;
114     }
115
116     public boolean hasOutPorts() {
117         for (PortNode port : getPortList()) {
118             if (port.isOutPort())
119                 return true;
120         }
121         return false;
122     }
123
124     public boolean hasInOutPorts() {
125         for (PortNode port : getPortList()) {
126             if (port.isInOutPort())
127                 return true;
128         }
129         return false;
130    }
131
132     /**
133      * Return a port which has a specific name. Return null when port
134      * cannot be found.
135      *
136      * @param name name of the port to search for
137      * @return port with the specified name
138      */
139     public PortNode getPort(String name) {
140         for (PortNode port : getPortList()) {
141             if (port.getName().equals(name)) {
142                 return port;
143             }
144         }
145         return null;
146     }
147
148     /**
149      * Return the first port on the List.
150      *
151      * @return first port element
152      */
153     public PortNode getFirstPort() {
154         return (PortNode) _portList.firstElement();
155     }
156
157    /**
158     * Get the corresponding ArchiResource.
159     *
160     * @return the corresponding ArchiResource
161     */
162     public ArchiResource getCorrespResource() {
163         return _correspResource;
164     }
165
166    /**
167     * Set the corresponding ArchiResource.
168     *
169     * @param correspResource new ArchiResource
170     */
171     public void setCorrespResource(ArchiResource correspResource) {
172         _correspResource = correspResource;
173     }
174
175     /**
176      * Get the port list of a Node.
177      *
178      * @return the port list
179      */
180     public Vector<PortNode> getPortList() {
181         return _portList;
182     }
183
184     /**
185      * Set the port list of a Node.
186      *
187      * @param portList The new list
188      */
189     public void setPortList( Vector<PortNode> portList ) {
190         _portList = portList;
191     }
192
193     /**
194      * Return a description of the node.
195      *
196      * @return a description of the node.
197      */
198     public String toString() {
199         return "Node: " + getName();
200     }
201
202     /**
203      * Range of the iterator when the instance belongs to an iterated
204      * series of nodes.
205      */
206     protected String _range;
207     protected String _name = null;
208     protected String _basename = null;
209     protected ArchiResource _correspResource = null;
210     protected Vector<PortNode> _portList = null;
211 }