1 /* $Id: ProcessNetwork.java 1 2010-02-24 13:03:05Z haidw $ */
2 package dol.datamodel.pn;
4 import java.util.Vector;
6 import dol.visitor.PNVisitor;
10 * This class defines a process network.
12 public class ProcessNetwork extends Resource {
15 * Constructor to create a process network with a name,
16 * empty process list and empty channel list.
18 public ProcessNetwork(String name) {
20 _processList = new Vector<Process>();
21 _channelList = new Vector<Channel>();
22 _varList = new Vector<Variable>();
23 _connectionList = new Vector<Connection>();
29 * @param x visitor object
31 public void accept(PNVisitor x) {
32 x.visitComponent(this);
36 * Clone this ProcessNetwork.
38 * @return new instance of the ProcessNetwork
40 @SuppressWarnings("unchecked")
41 public Object clone() {
42 ProcessNetwork newObj = (ProcessNetwork) super.clone();
43 newObj.setProcessList((Vector<Process>)_processList.clone());
44 newObj.setChannelList((Vector<Channel>)_channelList.clone());
45 newObj.setVarList((Vector<Variable>)_varList.clone());
46 newObj.setConnectionList((Vector<Connection>)_connectionList.clone());
51 * Get the process list of a ProcessNetwork.
53 * @return the process list
55 public Vector<Process> getProcessList() {
60 * Get the process basenames.
62 * @return process basenames
64 public Vector<String> getProcessBasenames() {
65 Vector<String> basenames = new Vector<String>();
66 for (Process p : _processList) {
67 String basename = p.getBasename();
68 if (!basenames.contains(basename)) {
69 basenames.add(basename);
76 * Set the process list of a ProcessNetwork.
78 * @param processList The new list
80 public void setProcessList(Vector<Process> processList) {
81 _processList = processList;
85 * Get the channel list of a ProcessNetwork
87 * @return the channel list
89 public Vector<Channel> getChannelList() {
94 * Set the channel list of a ProcessNetwork
96 * @param channelList The new list
98 public void setChannelList(Vector<Channel> channelList) {
99 _channelList = channelList;
102 public Vector<Variable> getVarList() { return _varList; }
103 public void setVarList(Vector<Variable> list) { _varList = list; }
105 public void setConnectionList(Vector<Connection> list) { _connectionList = list; }
106 public Vector<Connection> getConnectionList() { return _connectionList; }
110 * Return a description of the ProcessNetwork.
112 * @return a description of the ProcessNetwork.
114 public String toString() {
115 return "ProcessNetwork: " + getName();
119 * Return a process which has a specific name. Return null if
120 * process cannot be found.
122 * @param name the name of the process to search for.
123 * @return the process with the specific name.
125 public Process getProcess(String name) {
126 for (Process process : _processList) {
127 if (process.getName().equals(name)) {
135 * Return a channel which has a specific name. Return null if
138 * @param name the name of the channel to search for.
139 * @return the channel with the specific name.
141 public Channel getChannel(String name) {
142 for (Channel c : _channelList) {
143 if (c.getName().equals(name)) {
151 * In this version, we only deal with the flattened process network.
152 * Connection infomation is filled to each process and channel for fast
155 public void fillPortPeerInfo() throws Exception {
156 for (Connection c : getConnectionList()) {
157 Port originPort = c.getOriginPort();
158 Port targetPort = c.getTargetPort();
159 originPort.setPeerResource(c.getTarget());
160 originPort.setPeerPort(targetPort);
161 targetPort.setPeerResource(c.getOrigin());
162 targetPort.setPeerPort(originPort);
165 //for each sw channel, determine which processes it connects
166 for (Connection c : getConnectionList()) {
167 if (c.getOrigin() instanceof Process) {
168 Channel channel = (Channel)c.getTarget();
169 channel.setOrigin((Process)c.getOrigin());
171 else if (c.getOrigin() instanceof Channel) {
172 Channel channel = (Channel)c.getOrigin();
173 channel.setTarget((Process)c.getTarget());
178 /** list of the processes in the ProcessNetwork. */
179 protected Vector<Process> _processList = null;
181 /** list of the channels in the ProcessNetwork. */
182 protected Vector<Channel> _channelList = null;
184 /** list of variables in the ProcessNetwork */
185 protected Vector<Variable> _varList = null;
187 /** list of connections in the ProcessNetwork */
188 protected Vector<Connection> _connectionList = null;