+/* $Id: ProcessNetwork.java 1 2010-02-24 13:03:05Z haidw $ */
+package dol.datamodel.pn;
+
+import java.util.Vector;
+
+import dol.visitor.PNVisitor;
+
+
+/**
+ * This class defines a process network.
+ */
+public class ProcessNetwork extends Resource {
+
+ /**
+ * Constructor to create a process network with a name,
+ * empty process list and empty channel list.
+ */
+ public ProcessNetwork(String name) {
+ super(name);
+ _processList = new Vector<Process>();
+ _channelList = new Vector<Channel>();
+ _varList = new Vector<Variable>();
+ _connectionList = new Vector<Connection>();
+ }
+
+ /**
+ * Accept a visitor
+ *
+ * @param x visitor object
+ */
+ public void accept(PNVisitor x) {
+ x.visitComponent(this);
+ }
+
+ /**
+ * Clone this ProcessNetwork.
+ *
+ * @return new instance of the ProcessNetwork
+ */
+ @SuppressWarnings("unchecked")
+ public Object clone() {
+ ProcessNetwork newObj = (ProcessNetwork) super.clone();
+ newObj.setProcessList((Vector<Process>)_processList.clone());
+ newObj.setChannelList((Vector<Channel>)_channelList.clone());
+ newObj.setVarList((Vector<Variable>)_varList.clone());
+ newObj.setConnectionList((Vector<Connection>)_connectionList.clone());
+ return (newObj);
+ }
+
+ /**
+ * Get the process list of a ProcessNetwork.
+ *
+ * @return the process list
+ */
+ public Vector<Process> getProcessList() {
+ return _processList;
+ }
+
+ /**
+ * Get the process basenames.
+ *
+ * @return process basenames
+ */
+ public Vector<String> getProcessBasenames() {
+ Vector<String> basenames = new Vector<String>();
+ for (Process p : _processList) {
+ String basename = p.getBasename();
+ if (!basenames.contains(basename)) {
+ basenames.add(basename);
+ }
+ }
+ return basenames;
+ }
+
+ /**
+ * Set the process list of a ProcessNetwork.
+ *
+ * @param processList The new list
+ */
+ public void setProcessList(Vector<Process> processList) {
+ _processList = processList;
+ }
+
+ /**
+ * Get the channel list of a ProcessNetwork
+ *
+ * @return the channel list
+ */
+ public Vector<Channel> getChannelList() {
+ return _channelList;
+ }
+
+ /**
+ * Set the channel list of a ProcessNetwork
+ *
+ * @param channelList The new list
+ */
+ public void setChannelList(Vector<Channel> channelList) {
+ _channelList = channelList;
+ }
+
+ public Vector<Variable> getVarList() { return _varList; }
+ public void setVarList(Vector<Variable> list) { _varList = list; }
+
+ public void setConnectionList(Vector<Connection> list) { _connectionList = list; }
+ public Vector<Connection> getConnectionList() { return _connectionList; }
+
+
+ /**
+ * Return a description of the ProcessNetwork.
+ *
+ * @return a description of the ProcessNetwork.
+ */
+ public String toString() {
+ return "ProcessNetwork: " + getName();
+ }
+
+ /**
+ * Return a process which has a specific name. Return null if
+ * process cannot be found.
+ *
+ * @param name the name of the process to search for.
+ * @return the process with the specific name.
+ */
+ public Process getProcess(String name) {
+ for (Process process : _processList) {
+ if (process.getName().equals(name)) {
+ return process;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Return a channel which has a specific name. Return null if
+ * not found.
+ *
+ * @param name the name of the channel to search for.
+ * @return the channel with the specific name.
+ */
+ public Channel getChannel(String name) {
+ for (Channel c : _channelList) {
+ if (c.getName().equals(name)) {
+ return c;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * In this version, we only deal with the flattened process network.
+ * Connection infomation is filled to each process and channel for fast
+ * iteration.
+ */
+ public void fillPortPeerInfo() throws Exception {
+ for (Connection c : getConnectionList()) {
+ Port originPort = c.getOriginPort();
+ Port targetPort = c.getTargetPort();
+ originPort.setPeerResource(c.getTarget());
+ originPort.setPeerPort(targetPort);
+ targetPort.setPeerResource(c.getOrigin());
+ targetPort.setPeerPort(originPort);
+ }
+
+ //for each sw channel, determine which processes it connects
+ for (Connection c : getConnectionList()) {
+ if (c.getOrigin() instanceof Process) {
+ Channel channel = (Channel)c.getTarget();
+ channel.setOrigin((Process)c.getOrigin());
+ }
+ else if (c.getOrigin() instanceof Channel) {
+ Channel channel = (Channel)c.getOrigin();
+ channel.setTarget((Process)c.getTarget());
+ }
+ }
+ }
+
+ /** list of the processes in the ProcessNetwork. */
+ protected Vector<Process> _processList = null;
+
+ /** list of the channels in the ProcessNetwork. */
+ protected Vector<Channel> _channelList = null;
+
+ /** list of variables in the ProcessNetwork */
+ protected Vector<Variable> _varList = null;
+
+ /** list of connections in the ProcessNetwork */
+ protected Vector<Connection> _connectionList = null;
+}