1 /* $Id: ArchiResource.java 1 2010-02-24 13:03:05Z haidw $ */
2 package dol.datamodel.architecture;
4 import java.util.Iterator;
5 import java.util.StringTokenizer;
6 import java.util.Vector;
8 import dol.visitor.ArchiVisitor;
11 * This class is the basic class which abstracts an architectural resource
12 * of a generic architecture. The architectural resource has a name and a
13 * list of included nodes.
15 public class ArchiResource implements Cloneable {
17 * Constructor to create an architectural resource with a name and
20 public ArchiResource(String name) {
23 _nodeList = new Vector<Node>();
24 _cfgList = new Vector<Configuration>();
30 * @param x visitor object
32 public void accept(ArchiVisitor x) {
33 x.visitComponent(this);
37 * Clone this architectural resource.
39 * @return new instance of the architectural resource.
41 @SuppressWarnings("unchecked")
42 public Object clone() {
44 ArchiResource newObj = (ArchiResource) super.clone();
45 newObj.setName(_name);
46 newObj.setBasename(_basename);
47 newObj.setNodeList((Vector)_nodeList.clone() );
48 newObj.setCfgList((Vector)_cfgList.clone() );
50 } catch (CloneNotSupportedException e) {
51 System.out.println("Error Clone not Supported");
57 * Get the name of this architectural resource.
59 * @return name of the architectural resource
61 public String getName() {
66 * Set the name of this architectural resource.
68 * @param name name of the architectural resource
70 public void setName(String name) {
75 * Get the basename of this architectural resource.
77 * @return basename of the architectural resource
79 public String getBasename() {
84 * Set the basename of this architectural resource.
86 * @param basename name of the architectural resource
88 public void setBasename(String basename) {
93 * Get the iterator indices of this process.
97 public Vector<Integer> getIteratorIndices() {
98 Vector<Integer> indices = new Vector<Integer>();
99 StringTokenizer tokenizer =
100 new StringTokenizer(_name.replaceAll(_basename, ""), "_");
101 while (tokenizer.hasMoreTokens()) {
102 indices.add(Integer.valueOf(tokenizer.nextToken()));
108 * Get the list of nodes of this architectural resource.
110 * @return list of nodes
112 public Vector<Node> getNodeList() {
117 * Set the list of nodes of this architectural resource.
119 * @param nodeList nodes list
121 public void setNodeList(Vector<Node> nodeList) {
122 _nodeList = nodeList;
126 * Get the hierarchical parent of this architectural resource.
128 * @return parent of this architectural resource
130 public ArchiResource getParentResource() {
131 return _parentResource;
135 * Set the hierarchical parent of this architectural resource.
137 * @param parentResource new parent
139 public void setParentResource(ArchiResource parentResource) {
140 _parentResource = parentResource;
144 * Return a string representation of the architectural resource.
146 * @return string representation of the architectural resource
148 public String toString() {
149 return "ArchiResource: " + _name;
153 * Return a node (which has a specific name). Return null when node
156 * @param name of the node to search for
157 * @return node with the specified name
159 public Node getNode(String name) {
161 i = _nodeList.iterator();
162 while (i.hasNext()) {
163 Node node = i.next();
164 if (node.getName().equals(name)) {
172 * Return a node. Return null when node cannot be found.
176 public Node getNode() {
178 i = _nodeList.iterator();
179 while (i.hasNext()) {
180 Node node = i.next();
187 * Has this resource nodes?
189 * @return boolean value
191 public boolean hasNodes() {
192 return !_nodeList.isEmpty();
197 * Return the first node of the nodelist.
199 * @return the first node of the nodelist.
201 public Node getFirstNode() {
202 return (Node) _nodeList.firstElement();
206 * Get the list of configurations of this resource.
208 * @return list of configurations
210 public Vector<Configuration> getCfgList() {
215 * Set the list of configurations of this resource.
217 * @param cfgList configuration list
219 public void setCfgList(Vector<Configuration> cfgList) {
224 * Return a configuration which has a specific name. Return
225 * null when configuration cannot be found.
227 * @param name name of the configuration to search for
228 * @return configuration with the specified name
230 public Configuration getCfg(String name) {
231 for (Configuration config : _cfgList) {
232 if (config.getName().equals(name)) {
240 /** list of the configurations of the ArchiResource */
241 protected Vector<Configuration> _cfgList = null;
243 /** name of the architectural resource */
244 protected String _name = null;
246 /** basename of the architectural resource, if no basename, store the name */
247 protected String _basename = null;
249 /** list of the nodes, paths of the architectural resource */
250 protected Vector<Node> _nodeList = null;
252 /** parent resource of this architectural resource */
253 protected ArchiResource _parentResource = null;