KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > clif > scenario > util > isac > engine > behavior > node > ExecutableNode


1 /*
2 * CLIF is a Load Injection Framework
3 * Copyright (C) 2004 France Telecom R&D
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 *
19 * CLIF
20 *
21 * Contact: clif@objectweb.org
22 */

23 package org.objectweb.clif.scenario.util.isac.engine.behavior.node;
24
25 import java.util.Vector JavaDoc;
26
27 /**
28  * This class implements a behavior executable node. This kind of node will be used
29  * in the execution of a behavior, in 'BehaviorExecutionThread'. A node has some
30  * datas stored into it, and has references to it children, so it represent a tree.
31  *
32  * @author JC Meillaud
33  * @author A Peyrard
34  */

35 public class ExecutableNode {
36     // attributes
37
private String JavaDoc type ;
38     private Object JavaDoc description ;
39     private ExecutableNode parent ;
40     private Vector JavaDoc children ;
41     
42     /**
43      * Constructor, build a new ExecutableNode with the specifiad parameters
44      * @param type The type of the node
45      */

46     public ExecutableNode(String JavaDoc type) {
47         this.type = type ;
48         this.description = null ;
49         this.children = new Vector JavaDoc() ;
50     }
51     
52     /**
53      * Constructor, build a new ExecutableNode with the specifiad parameters
54      * @param type The type of the node
55      * @param description The execution description of the node
56      */

57     public ExecutableNode(String JavaDoc type, Object JavaDoc description) {
58         this.type = type ;
59         this.description = description ;
60         this.children = new Vector JavaDoc() ;
61     }
62     
63     //////////////////////////////////
64
// Methods to manage the tree
65
//////////////////////////////////
66

67     /**
68      * This method adds a new child to the current node
69      * @param child The child to add
70      */

71     public void addChild(ExecutableNode child) {
72         // set the parent of the child
73
child.setParent(this) ;
74         // add the child to the vector which store each child
75
// of the current node
76
this.children.add(child) ;
77     }
78     
79     //////////////////////////////////
80
// Attribute getters and setters
81
//////////////////////////////////
82

83     /**
84      * @return Returns the parent.
85      */

86     public ExecutableNode getParent() {
87         return parent;
88     }
89     /**
90      * @param parent The parent to set.
91      */

92     public void setParent(ExecutableNode parent) {
93         this.parent = parent;
94     }
95     /**
96      * @return Returns the children.
97      */

98     public Vector JavaDoc getChildren() {
99         return children;
100     }
101     /**
102      * @return Returns the type.
103      */

104     public String JavaDoc getType() {
105         return type;
106     }
107     /**
108      * @return Returns the description.
109      */

110     public Object JavaDoc getDescription() {
111         return description;
112     }
113     /**
114      * @param description The description to set.
115      */

116     public void setDescription(Object JavaDoc description) {
117         this.description = description;
118     }
119     
120     ////////////////////////////////////////////////
121
// Debug methods
122
////////////////////////////////////////////////
123

124     public void printNode() {
125         printNode(this,0) ;
126     }
127     
128     public void printWithoutChildrenNode() {
129         System.out.println("type="+this.getType()) ;
130         System.out.println("desc="+this.getDescription()) ;
131     }
132     
133     public void printNode(ExecutableNode node, int indent) {
134         System.out.println("") ;
135         printIndent(indent) ;System.out.println("type="+node.getType()) ;
136         printIndent(indent) ;System.out.println("desc="+node.getDescription()) ;
137         for (int i=0;i<node.getChildren().size();i++) {
138             printNode((ExecutableNode)node.getChildren().elementAt(i), indent+4) ;
139         }
140     }
141     
142     public void printIndent(int indent) {
143         for (int i=0;i<indent;i++) {
144             System.out.print(" ") ;
145         }
146     }
147 }
148
Popular Tags