dol: initial dol commit
[jump.git] / dol / src / dol / datamodel / pn / Resource.java
diff --git a/dol/src/dol/datamodel/pn/Resource.java b/dol/src/dol/datamodel/pn/Resource.java
new file mode 100644 (file)
index 0000000..d212bbe
--- /dev/null
@@ -0,0 +1,269 @@
+/* $Id: Resource.java 1 2010-02-24 13:03:05Z haidw $ */
+package dol.datamodel.pn;
+
+import java.util.Vector;
+
+import dol.visitor.PNVisitor;
+
+/**
+ * This class is the basic class which abstracts a resource of a generic
+ * process network. The resource has a name and a list of ports.
+ */
+public class Resource {
+
+    /**
+     *  Constructor to create a resource with a name and an empty
+     *  portList.
+     */
+    public Resource(String name) {
+        _name = name;
+        _basename = name;
+        _portList = new Vector<Port>();
+        _srcList = new Vector<SourceCode>();
+        _cfgList = new Vector<Configuration>();
+        _profilingList = new Vector<ProfilingConfiguration>();
+    }
+
+    /**
+     * Accept a Visitor
+     *
+     * @param x visitor object
+     */
+    public void accept(PNVisitor x) {
+        x.visitComponent(this);
+    }
+
+    /**
+     * Clone this resource.
+     *
+     * @return new instance of the resource.
+     */
+    @SuppressWarnings("unchecked")
+    public Object clone() {
+        try {
+            Resource newObj = (Resource) super.clone();
+            newObj.setName(_name);
+            newObj.setType(_type);
+            newObj.setBasename(_basename);
+            newObj.setPortList((Vector)_portList.clone() );
+            newObj.setSrcList((Vector)_srcList.clone() );
+            newObj.setCfgList((Vector)_cfgList.clone() );
+            newObj.setProfilingList((Vector)_profilingList.clone() );
+            return (newObj);
+        } catch (CloneNotSupportedException e) {
+            System.out.println("Error Clone not Supported");
+        }
+        return null;
+    }
+
+    public String getBasename() {
+        return _basename;
+    }
+
+    public void setBasename(String basename) {
+        _basename = basename;
+    }
+
+    /**
+     * Get the name of this resource.
+     *
+     * @return name of the resource
+     */
+    public String getName() {
+        return _name;
+    }
+
+    /**
+     * Set the name of this resource.
+     *
+     * @param name name of the resource
+     */
+    public void setName(String name) {
+        _name = name;
+    }
+
+    /**
+     * Get the type of this resource.
+     *
+     * @return type of the resource
+     */
+    public String getType() {
+        return _type;
+    }
+
+    /**
+     * Set the type of this resource.
+     *
+     * @param type type of the resource
+     */
+    public void setType(String type) {
+        _type = type;
+    }
+
+    /**
+     * Get the list of source codes of this resource.
+     *
+     * @return list of source codes
+     */
+    public Vector<SourceCode> getSrcList() {
+        return _srcList;
+    }
+
+    /**
+     * Get the list of ports of this resource.
+     *
+     * @return list of ports
+     */
+    public Vector<Port> getPortList() {
+        return _portList;
+    }
+
+    /**
+     * Set the list of ports of this resource.
+     *
+     * @param portList port list
+     */
+    public void setPortList(Vector<Port> portList) {
+        _portList = portList;
+    }
+    
+    /**
+     * Get the list of configurations of this resource.
+     *
+     * @return list of configurations
+     */
+    public Vector<Configuration> getCfgList() {
+        return _cfgList;
+    }
+
+    /**
+     * Set the list of configurations of this resource.
+     *
+     * @param cfgList configuration list
+     */
+    public void setCfgList(Vector<Configuration> cfgList) {
+        _cfgList = cfgList;
+    }
+
+    /**
+     * Get the list of profiling info of this resource.
+     *
+     * @return list of profiling info
+     */
+    public Vector<ProfilingConfiguration> getProfilingList() {
+        return _profilingList;
+    }
+
+    /**
+     * Set the list of profiling info of this resource.
+     *
+     * @param cfgList profiling info list
+     */
+    public void setProfilingList(Vector<ProfilingConfiguration> cfgList) {
+        _profilingList = cfgList;
+    }
+
+    /**
+     * Return a profiling which has a specific name. Return null when it
+     * cannot be found.
+     *
+     * @param name name of the profiling to search for
+     * @return profiling with the specified name
+     */
+    public ProfilingConfiguration getProfilingCfg(String name) {
+        for (ProfilingConfiguration cfg : _profilingList) {
+            if (cfg.getName().equals(name)) {
+                return cfg;
+            }
+        }
+        return null;
+    }
+
+    /**
+     * Set the list of source code of this resource.
+     *
+     * @param srcList port list
+     */
+    public void setSrcList(Vector<SourceCode> srcList) {
+        _srcList = srcList;
+    }
+
+    /**
+     * Get the hierarchical parent of this resource.
+     *
+     * @return parent of this resource
+     */
+     public Resource getParentResource() {
+        return _parentResource;
+    }
+
+    /**
+     * Set the hierarchical parent of this resource.
+     *
+     * @param parentResource new parent
+     */
+    public void setParentResource(Resource parentResource) {
+        _parentResource = parentResource;
+    }
+
+    /**
+     * Return a string representation of the resource.
+     *
+     * @return string representation of the resource
+     */
+    public String toString() {
+        return "Resource: " + _name;
+    }
+
+    /**
+     * Return a port which has a specific name. Return null when port
+     * cannot be found.
+     *
+     * @param name name of the port to search for
+     * @return port with the specified name
+     */
+    public Port getPort(String name) {
+        for (Port port : _portList) {
+            if (port.getName().equals(name)) {
+                return port;
+            }
+        }
+        return null;
+    }
+
+    /**
+     * Return a port which has a specific name. Return null when port
+     * cannot be found.
+     *
+     * @return port with the specified name
+     */
+    public Port getFirstPort() {
+        return (Port) _portList.firstElement();
+    }
+
+    /** name of the resource */
+    protected String _name = null;
+
+    /** type of the resource */
+    protected String _type = null;
+
+    /** basename of the resource, if no basename, store the name */
+    protected String _basename = null;
+
+    /** list of the ports of the Resource */
+    protected Vector<Port> _portList = null;
+
+    /** list of the source codes of the Resource */
+    protected Vector<SourceCode> _srcList = null;
+
+    /** list of the configurations of the Resource */
+    protected Vector<Configuration> _cfgList = null;
+
+    /** list of the profiling info of the Resource */
+    protected Vector<ProfilingConfiguration> _profilingList = null;
+
+    /**
+     * parent resource of this resource in a hierarchical process network
+     */
+    protected Resource _parentResource = null;
+}