dol: initial dol commit
[jump.git] / dol / src / dol / datamodel / pn / Resource.java
1 /* $Id: Resource.java 1 2010-02-24 13:03:05Z haidw $ */
2 package dol.datamodel.pn;
3
4 import java.util.Vector;
5
6 import dol.visitor.PNVisitor;
7
8 /**
9  * This class is the basic class which abstracts a resource of a generic
10  * process network. The resource has a name and a list of ports.
11  */
12 public class Resource {
13
14     /**
15      *  Constructor to create a resource with a name and an empty
16      *  portList.
17      */
18     public Resource(String name) {
19         _name = name;
20         _basename = name;
21         _portList = new Vector<Port>();
22         _srcList = new Vector<SourceCode>();
23         _cfgList = new Vector<Configuration>();
24         _profilingList = new Vector<ProfilingConfiguration>();
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 resource.
38      *
39      * @return new instance of the resource.
40      */
41     @SuppressWarnings("unchecked")
42     public Object clone() {
43         try {
44             Resource newObj = (Resource) super.clone();
45             newObj.setName(_name);
46             newObj.setType(_type);
47             newObj.setBasename(_basename);
48             newObj.setPortList((Vector)_portList.clone() );
49             newObj.setSrcList((Vector)_srcList.clone() );
50             newObj.setCfgList((Vector)_cfgList.clone() );
51             newObj.setProfilingList((Vector)_profilingList.clone() );
52             return (newObj);
53         } catch (CloneNotSupportedException e) {
54             System.out.println("Error Clone not Supported");
55         }
56         return null;
57     }
58
59     public String getBasename() {
60         return _basename;
61     }
62
63     public void setBasename(String basename) {
64         _basename = basename;
65     }
66
67     /**
68      * Get the name of this resource.
69      *
70      * @return name of the resource
71      */
72     public String getName() {
73         return _name;
74     }
75
76     /**
77      * Set the name of this resource.
78      *
79      * @param name name of the resource
80      */
81     public void setName(String name) {
82         _name = name;
83     }
84
85     /**
86      * Get the type of this resource.
87      *
88      * @return type of the resource
89      */
90     public String getType() {
91         return _type;
92     }
93
94     /**
95      * Set the type of this resource.
96      *
97      * @param type type of the resource
98      */
99     public void setType(String type) {
100         _type = type;
101     }
102
103     /**
104      * Get the list of source codes of this resource.
105      *
106      * @return list of source codes
107      */
108     public Vector<SourceCode> getSrcList() {
109         return _srcList;
110     }
111
112     /**
113      * Get the list of ports of this resource.
114      *
115      * @return list of ports
116      */
117     public Vector<Port> getPortList() {
118         return _portList;
119     }
120
121     /**
122      * Set the list of ports of this resource.
123      *
124      * @param portList port list
125      */
126     public void setPortList(Vector<Port> portList) {
127         _portList = portList;
128     }
129     
130     /**
131      * Get the list of configurations of this resource.
132      *
133      * @return list of configurations
134      */
135     public Vector<Configuration> getCfgList() {
136         return _cfgList;
137     }
138
139     /**
140      * Set the list of configurations of this resource.
141      *
142      * @param cfgList configuration list
143      */
144     public void setCfgList(Vector<Configuration> cfgList) {
145         _cfgList = cfgList;
146     }
147
148     /**
149      * Get the list of profiling info of this resource.
150      *
151      * @return list of profiling info
152      */
153     public Vector<ProfilingConfiguration> getProfilingList() {
154         return _profilingList;
155     }
156
157     /**
158      * Set the list of profiling info of this resource.
159      *
160      * @param cfgList profiling info list
161      */
162     public void setProfilingList(Vector<ProfilingConfiguration> cfgList) {
163         _profilingList = cfgList;
164     }
165
166     /**
167      * Return a profiling which has a specific name. Return null when it
168      * cannot be found.
169      *
170      * @param name name of the profiling to search for
171      * @return profiling with the specified name
172      */
173     public ProfilingConfiguration getProfilingCfg(String name) {
174         for (ProfilingConfiguration cfg : _profilingList) {
175             if (cfg.getName().equals(name)) {
176                 return cfg;
177             }
178         }
179         return null;
180     }
181
182     /**
183      * Set the list of source code of this resource.
184      *
185      * @param srcList port list
186      */
187     public void setSrcList(Vector<SourceCode> srcList) {
188         _srcList = srcList;
189     }
190
191     /**
192      * Get the hierarchical parent of this resource.
193      *
194      * @return parent of this resource
195      */
196      public Resource getParentResource() {
197         return _parentResource;
198     }
199
200     /**
201      * Set the hierarchical parent of this resource.
202      *
203      * @param parentResource new parent
204      */
205     public void setParentResource(Resource parentResource) {
206         _parentResource = parentResource;
207     }
208
209     /**
210      * Return a string representation of the resource.
211      *
212      * @return string representation of the resource
213      */
214     public String toString() {
215         return "Resource: " + _name;
216     }
217
218     /**
219      * Return a port which has a specific name. Return null when port
220      * cannot be found.
221      *
222      * @param name name of the port to search for
223      * @return port with the specified name
224      */
225     public Port getPort(String name) {
226         for (Port port : _portList) {
227             if (port.getName().equals(name)) {
228                 return port;
229             }
230         }
231         return null;
232     }
233
234     /**
235      * Return a port which has a specific name. Return null when port
236      * cannot be found.
237      *
238      * @return port with the specified name
239      */
240     public Port getFirstPort() {
241         return (Port) _portList.firstElement();
242     }
243
244     /** name of the resource */
245     protected String _name = null;
246
247     /** type of the resource */
248     protected String _type = null;
249
250     /** basename of the resource, if no basename, store the name */
251     protected String _basename = null;
252
253     /** list of the ports of the Resource */
254     protected Vector<Port> _portList = null;
255
256     /** list of the source codes of the Resource */
257     protected Vector<SourceCode> _srcList = null;
258
259     /** list of the configurations of the Resource */
260     protected Vector<Configuration> _cfgList = null;
261
262     /** list of the profiling info of the Resource */
263     protected Vector<ProfilingConfiguration> _profilingList = null;
264
265     /**
266      * parent resource of this resource in a hierarchical process network
267      */
268     protected Resource _parentResource = null;
269 }