X-Git-Url: http://sraa.de/git/?a=blobdiff_plain;f=dol%2Fsrc%2Fdol%2Fdatamodel%2Farchitecture%2FArchiResource.java;fp=dol%2Fsrc%2Fdol%2Fdatamodel%2Farchitecture%2FArchiResource.java;h=04de4069110e1937e467096a8f785383271ae46c;hb=8c411cf24ed0eb889191aaeafd8fa1e69081df42;hp=0000000000000000000000000000000000000000;hpb=dea7a4fb1ed110d3ce6e6d9255103d724bd66c0e;p=jump.git diff --git a/dol/src/dol/datamodel/architecture/ArchiResource.java b/dol/src/dol/datamodel/architecture/ArchiResource.java new file mode 100644 index 0000000..04de406 --- /dev/null +++ b/dol/src/dol/datamodel/architecture/ArchiResource.java @@ -0,0 +1,254 @@ +/* $Id: ArchiResource.java 1 2010-02-24 13:03:05Z haidw $ */ +package dol.datamodel.architecture; + +import java.util.Iterator; +import java.util.StringTokenizer; +import java.util.Vector; + +import dol.visitor.ArchiVisitor; + +/** + * This class is the basic class which abstracts an architectural resource + * of a generic architecture. The architectural resource has a name and a + * list of included nodes. + */ +public class ArchiResource implements Cloneable { + /** + * Constructor to create an architectural resource with a name and + * an empty node list. + */ + public ArchiResource(String name) { + _name = name; + _basename = name; + _nodeList = new Vector(); + _cfgList = new Vector(); + } + + /** + * Accept a Visitor + * + * @param x visitor object + */ + public void accept(ArchiVisitor x) { + x.visitComponent(this); + } + + /** + * Clone this architectural resource. + * + * @return new instance of the architectural resource. + */ + @SuppressWarnings("unchecked") + public Object clone() { + try { + ArchiResource newObj = (ArchiResource) super.clone(); + newObj.setName(_name); + newObj.setBasename(_basename); + newObj.setNodeList((Vector)_nodeList.clone() ); + newObj.setCfgList((Vector)_cfgList.clone() ); + return (newObj); + } catch (CloneNotSupportedException e) { + System.out.println("Error Clone not Supported"); + } + return null; + } + + /** + * Get the name of this architectural resource. + * + * @return name of the architectural resource + */ + public String getName() { + return _name; + } + + /** + * Set the name of this architectural resource. + * + * @param name name of the architectural resource + */ + public void setName(String name) { + _name = name; + } + + /** + * Get the basename of this architectural resource. + * + * @return basename of the architectural resource + */ + public String getBasename() { + return _basename; + } + + /** + * Set the basename of this architectural resource. + * + * @param basename name of the architectural resource + */ + public void setBasename(String basename) { + _basename = basename; + } + + /** + * Get the iterator indices of this process. + * + * @return range + */ + public Vector getIteratorIndices() { + Vector indices = new Vector(); + StringTokenizer tokenizer = + new StringTokenizer(_name.replaceAll(_basename, ""), "_"); + while (tokenizer.hasMoreTokens()) { + indices.add(Integer.valueOf(tokenizer.nextToken())); + } + return indices; + } + + /** + * Get the list of nodes of this architectural resource. + * + * @return list of nodes + */ + public Vector getNodeList() { + return _nodeList; + } + + /** + * Set the list of nodes of this architectural resource. + * + * @param nodeList nodes list + */ + public void setNodeList(Vector nodeList) { + _nodeList = nodeList; + } + + /** + * Get the hierarchical parent of this architectural resource. + * + * @return parent of this architectural resource + */ + public ArchiResource getParentResource() { + return _parentResource; + } + + /** + * Set the hierarchical parent of this architectural resource. + * + * @param parentResource new parent + */ + public void setParentResource(ArchiResource parentResource) { + _parentResource = parentResource; + } + + /** + * Return a string representation of the architectural resource. + * + * @return string representation of the architectural resource + */ + public String toString() { + return "ArchiResource: " + _name; + } + + /** + * Return a node (which has a specific name). Return null when node + * cannot be found. + * + * @param name of the node to search for + * @return node with the specified name + */ + public Node getNode(String name) { + Iterator i; + i = _nodeList.iterator(); + while (i.hasNext()) { + Node node = i.next(); + if (node.getName().equals(name)) { + return node; + } + } + return null; + } + + /** + * Return a node. Return null when node cannot be found. + * + * @return node + */ + public Node getNode() { + Iterator i; + i = _nodeList.iterator(); + while (i.hasNext()) { + Node node = i.next(); + return node; + } + return null; + } + + /** + * Has this resource nodes? + * + * @return boolean value + */ + public boolean hasNodes() { + return !_nodeList.isEmpty(); + } + + + /** + * Return the first node of the nodelist. + * + * @return the first node of the nodelist. + */ + public Node getFirstNode() { + return (Node) _nodeList.firstElement(); + } + + /** + * Get the list of configurations of this resource. + * + * @return list of configurations + */ + public Vector getCfgList() { + return _cfgList; + } + + /** + * Set the list of configurations of this resource. + * + * @param cfgList configuration list + */ + public void setCfgList(Vector cfgList) { + _cfgList = cfgList; + } + + /** + * Return a configuration which has a specific name. Return + * null when configuration cannot be found. + * + * @param name name of the configuration to search for + * @return configuration with the specified name + */ + public Configuration getCfg(String name) { + for (Configuration config : _cfgList) { + if (config.getName().equals(name)) { + return config; + } + } + return null; + } + + + /** list of the configurations of the ArchiResource */ + protected Vector _cfgList = null; + + /** name of the architectural resource */ + protected String _name = null; + + /** basename of the architectural resource, if no basename, store the name */ + protected String _basename = null; + + /** list of the nodes, paths of the architectural resource */ + protected Vector _nodeList = null; + + /** parent resource of this architectural resource */ + protected ArchiResource _parentResource = null; +}