dol: initial dol commit
[jump.git] / dol / src / dol / datamodel / architecture / Path.java
1 /* $Id: Path.java 1 2010-02-24 13:03:05Z haidw $ */
2 package dol.datamodel.architecture;
3
4 import java.util.Iterator;
5 import java.util.Vector;
6
7 /**
8  * Path consisting of write path and read path.
9  */
10 public class Path {
11     /**
12      * Default constructor.
13      */
14     public Path() {
15         _path = new Vector<ArchiResource>();
16     }
17
18     /**
19      * Set the read path of this path.
20      */
21     public void setReadPath(ReadPath readPath) {
22         _readPath = readPath;
23         computeArchitectureResources();
24     }
25
26     /**
27      * Return the read path of this path.
28      *
29      * @return read path
30      */
31     public ReadPath getReadPath() {
32         return _readPath;
33     }
34
35     /**
36      * Set the write path of this path.
37      */
38     public void setWritePath(WritePath writePath) {
39         _writePath = writePath;
40         computeArchitectureResources();
41     }
42
43     /**
44      * Return the write path of this path.
45      *
46      * @return write path
47      */
48     public WritePath getWritePath() {
49         return _writePath;
50     }
51
52     /**
53      * Return all resources contained in this path.
54      *
55      * @return all resources contained in this path
56      */
57     public Vector<ArchiResource> getPath() {
58         return _path;
59     }
60
61     /**
62      * Return the processor where this path starts.
63      *
64      * @return processor where this path starts
65      */
66     public Processor getStartProcessor() {
67         if (_path.size() == 0)
68             return null;
69
70         return (Processor)_path.elementAt(0);
71     }
72
73     /**
74      * Return the processor where this path ends.
75      *
76      * @return processor where this path ends
77      */
78     public Processor getTargetProcessor() {
79         if (_path.size() == 0)
80             return null;
81
82         return (Processor)_path.elementAt(_path.size() - 1);
83     }
84
85     /**
86      * Compute the vector of all resources contained in this path.
87      */
88     protected void computeArchitectureResources() {
89         _path.clear();
90
91         if (_readPath == null || _writePath == null)
92             return;
93
94         _path.add(_writePath.getProcessor());
95         _path.add(_writePath.getTXBuf());
96         Iterator<HWChannel> channelIterator =
97                 _writePath.getHWChannelList().iterator();
98         while (channelIterator.hasNext()) {
99             _path.add(channelIterator.next());
100         }
101         _path.add(_readPath.getCHBuf());
102         channelIterator = _readPath.getHWChannelList().iterator();
103         while (channelIterator.hasNext()) {
104             _path.add(channelIterator.next());
105         }
106         _path.add(_readPath.getRXBuf());
107         _path.add(_readPath.getProcessor());
108     }
109
110     /** read path of this path*/
111     protected ReadPath _readPath = null;
112
113     /** write path of this path */
114     protected WritePath _writePath = null;
115
116     /** resources contained in this path */
117     Vector<ArchiResource> _path;
118 }