1 23 package org.objectweb.clif.scenario.util.isac.engine.behavior; 24 25 import java.util.Hashtable ; 26 import java.util.Vector ; 27 28 import org.objectweb.clif.scenario.util.isac.engine.behavior.node.ExecutableNode; 29 import org.objectweb.clif.scenario.util.isac.engine.behavior.node.description.ChoiceDescription; 30 import org.objectweb.clif.scenario.util.isac.engine.behavior.node.description.IfDescription; 31 import org.objectweb.clif.scenario.util.isac.engine.behavior.node.description.PreemptiveDescription; 32 import org.objectweb.clif.scenario.util.isac.engine.behavior.node.description.SampleDescription; 33 import org.objectweb.clif.scenario.util.isac.engine.behavior.node.description.TestDescription; 34 import org.objectweb.clif.scenario.util.isac.engine.behavior.node.description.TimerDescription; 35 import org.objectweb.clif.scenario.util.isac.engine.behavior.node.description.WhileDescription; 36 import org.objectweb.clif.scenario.util.isac.util.SessionObjectHashtable; 37 import org.w3c.dom.Element ; 38 import org.w3c.dom.NamedNodeMap ; 39 import org.w3c.dom.Node ; 40 import org.w3c.dom.NodeList ; 41 42 49 public class BehaviorManager { 50 private Hashtable behaviorTable; 53 private Hashtable methodNameConversionTable; 55 56 private Hashtable sessionObjectPluginNameTable; 57 58 private Hashtable sessionObjectTable; 59 private Hashtable sessionObjectForABehavior ; 61 private SampleDescription analyzedSampleDescription; 63 64 private TestDescription analyzedTestDescription; 65 66 private TimerDescription analyzedTimerDescription; 67 68 private Vector analyzedUsedSessionObjects ; 70 71 private ExecutableNode currentNode; 72 73 85 public BehaviorManager(Hashtable mnct, Hashtable sopn, Hashtable sot, Hashtable sofab) { 86 this.behaviorTable = new Hashtable (); 88 this.methodNameConversionTable = mnct; 90 this.sessionObjectPluginNameTable = sopn; 91 this.sessionObjectTable = sot; 92 this.sessionObjectForABehavior = sofab ; 93 } 94 95 102 public void addBehavior(Node node) { 103 NamedNodeMap attributes = node.getAttributes(); 105 String id = attributes.getNamedItem("id").getNodeValue(); 106 ExecutableNode root = new ExecutableNode( 108 org.objectweb.clif.scenario.util.isac.util.tree.Node.BEHAVIOR, 109 null); 110 this.analyzedUsedSessionObjects = new Vector () ; 113 this.visitBehaviorNode(node, root); 115 this.behaviorTable.put(id, root); 117 SessionObjectHashtable cloneableHashtable = new SessionObjectHashtable() ; 119 for (int i=0;i<this.analyzedUsedSessionObjects.size();i++) { 121 String sessionObjectId = (String )this.analyzedUsedSessionObjects.elementAt(i) ; 123 cloneableHashtable.put(sessionObjectId, this.sessionObjectTable.get(sessionObjectId)) ; 125 } 126 this.sessionObjectForABehavior.put(id,cloneableHashtable) ; 128 } 129 130 138 private void visitBehaviorNode(Node node, ExecutableNode parent) { 139 ExecutableNode child = null; 141 String tagName = null; 143 switch (node.getNodeType()) { 144 case Node.ELEMENT_NODE: 145 tagName = ((Element ) node).getTagName(); 146 if (tagName 148 .equals(org.objectweb.clif.scenario.util.isac.util.tree.Node.SAMPLE)) { 149 NamedNodeMap attributes = node.getAttributes(); 151 String methodName = attributes.getNamedItem("name") 152 .getNodeValue(); 153 String usedSessionObject = attributes.getNamedItem("use") 154 .getNodeValue(); 155 if (!this.analyzedUsedSessionObjects.contains(usedSessionObject)) 157 this.analyzedUsedSessionObjects.add(usedSessionObject) ; 158 String pluginName = (String ) this.sessionObjectPluginNameTable 160 .get(usedSessionObject); 161 String key = pluginName + "." + tagName + "." + methodName; 163 int number = ((Integer ) this.methodNameConversionTable.get(key)) 165 .intValue(); 166 SampleDescription sampleDescription = new SampleDescription( 168 usedSessionObject, number); 169 child = new ExecutableNode(tagName, sampleDescription); 171 parent.addChild(child); 173 this.analyzedSampleDescription = sampleDescription; 175 this.currentNode = child; 176 } 177 if (tagName 178 .equals(org.objectweb.clif.scenario.util.isac.util.tree.Node.TIMER)) { 179 NamedNodeMap attributes = node.getAttributes(); 181 String methodName = attributes.getNamedItem("name") 182 .getNodeValue(); 183 String usedSessionObject = attributes.getNamedItem("use") 184 .getNodeValue(); 185 if (!this.analyzedUsedSessionObjects.contains(usedSessionObject)) 187 this.analyzedUsedSessionObjects.add(usedSessionObject) ; 188 String pluginName = (String ) this.sessionObjectPluginNameTable 190 .get(usedSessionObject); 191 String key = pluginName + "." + tagName + "." + methodName; 193 int number = ((Integer ) this.methodNameConversionTable.get(key)) 195 .intValue(); 196 TimerDescription timerDescription = new TimerDescription( 198 usedSessionObject, number); 199 child = new ExecutableNode(tagName, timerDescription); 201 parent.addChild(child); 203 this.analyzedTimerDescription = timerDescription; 205 this.currentNode = child; 206 } 207 if (tagName 208 .equals(org.objectweb.clif.scenario.util.isac.util.tree.Node.IF)) { 209 TestDescription condition = new TestDescription(); 211 IfDescription ifDescription = new IfDescription(condition); 213 child = new ExecutableNode(tagName, ifDescription); 214 parent.addChild(child); 216 this.analyzedTestDescription = condition; 218 this.currentNode = child; 219 } 220 if (tagName 221 .equals(org.objectweb.clif.scenario.util.isac.util.tree.Node.WHILE)) { 222 TestDescription condition = new TestDescription(); 224 WhileDescription whileDescription = new WhileDescription( 226 condition); 227 child = new ExecutableNode(tagName, whileDescription); 228 parent.addChild(child); 230 this.analyzedTestDescription = condition; 232 this.currentNode = child; 233 } 234 if (tagName 235 .equals(org.objectweb.clif.scenario.util.isac.util.tree.Node.PREEMPTIVE)) { 236 TestDescription condition = new TestDescription(); 238 PreemptiveDescription preemptiveDescription = new PreemptiveDescription( 240 condition); 241 child = new ExecutableNode(tagName, preemptiveDescription); 242 parent.addChild(child); 244 this.analyzedTestDescription = condition; 246 this.currentNode = child; 247 } 248 if (tagName 249 .equals(org.objectweb.clif.scenario.util.isac.util.tree.Node.CONDITION)) { 250 NamedNodeMap attributes = node.getAttributes(); 252 String methodName = attributes.getNamedItem("name") 253 .getNodeValue(); 254 String usedSessionObject = attributes.getNamedItem("use") 255 .getNodeValue(); 256 if (!this.analyzedUsedSessionObjects.contains(usedSessionObject)) 258 this.analyzedUsedSessionObjects.add(usedSessionObject) ; 259 String pluginName = (String ) this.sessionObjectPluginNameTable 261 .get(usedSessionObject); 262 String key = pluginName 264 + "." 265 + org.objectweb.clif.scenario.util.isac.util.tree.Node.TEST 266 + "." + methodName; 267 int number = ((Integer ) this.methodNameConversionTable.get(key)) 269 .intValue(); 270 this.analyzedTestDescription.setMethodNumber(number); 272 this.analyzedTestDescription.setSessionObject(usedSessionObject); 273 } 274 if (tagName 275 .equals(org.objectweb.clif.scenario.util.isac.util.tree.Node.NCHOICE)) { 276 child = new ExecutableNode(tagName, null); 278 parent.addChild(child); 280 } 281 if (tagName 282 .equals(org.objectweb.clif.scenario.util.isac.util.tree.Node.THEN)) { 283 child = new ExecutableNode(tagName, null); 285 parent.addChild(child); 287 } 288 if (tagName 289 .equals(org.objectweb.clif.scenario.util.isac.util.tree.Node.ELSE)) { 290 child = new ExecutableNode(tagName, null); 292 parent.addChild(child); 294 } 295 if (tagName 296 .equals(org.objectweb.clif.scenario.util.isac.util.tree.Node.CHOICE)) { 297 NamedNodeMap attributes = node.getAttributes(); 299 String proba = attributes.getNamedItem("proba").getNodeValue(); 300 ChoiceDescription choiceDescription = new ChoiceDescription( 302 (new Integer (proba)).intValue()); 303 child = new ExecutableNode(tagName, choiceDescription); 305 parent.addChild(child); 307 } 308 if (tagName 309 .equals(org.objectweb.clif.scenario.util.isac.util.tree.Node.PARAMS)) { 310 } 312 if (tagName 313 .equals(org.objectweb.clif.scenario.util.isac.util.tree.Node.PARAM)) { 314 NamedNodeMap attributes = node.getAttributes(); 316 String value = attributes.getNamedItem("value").getNodeValue(); 317 String name = attributes.getNamedItem("name").getNodeValue(); 318 if (currentNode 319 .getType() 320 .equals( 321 org.objectweb.clif.scenario.util.isac.util.tree.Node.SAMPLE)) 322 this.analyzedSampleDescription.addParamsValue(name,value); 323 else if (currentNode 324 .getType() 325 .equals( 326 org.objectweb.clif.scenario.util.isac.util.tree.Node.TIMER)) 327 this.analyzedTimerDescription.addParamsValue(name,value); 328 else if (org.objectweb.clif.scenario.util.isac.util.tree.Node 329 .isControllerNode(currentNode.getType())) 330 this.analyzedTestDescription.addParamsValue(name,value); 331 } 332 } 333 if (node.hasChildNodes()) { 335 NodeList children = node.getChildNodes(); 336 for (int i = 0; i < children.getLength(); i++) { 337 Node tempNode = children.item(i); 338 if (tempNode.getNodeType() == Node.ELEMENT_NODE) { 339 if (child == null) 340 visitBehaviorNode(tempNode, parent); 341 else 342 visitBehaviorNode(tempNode, child); 343 } 344 } 345 } 346 } 347 348 355 public ExecutableNode getBehavior(String id) { 356 return (ExecutableNode) this.behaviorTable.get(id); 357 } 358 359 } | Popular Tags |