| 1 23 package org.objectweb.clif.scenario.util.isac.util.tree; 24 25 import java.io.FileInputStream ; 26 import java.util.Hashtable ; 27 import java.util.Vector ; 28 29 import javax.xml.parsers.DocumentBuilder ; 30 import javax.xml.parsers.DocumentBuilderFactory ; 31 32 import org.apache.log4j.Category; 33 import org.objectweb.clif.scenario.util.isac.loadprofile.GroupDescription; 34 import org.objectweb.clif.scenario.util.isac.loadprofile.LoadProfileManager; 35 import org.objectweb.clif.scenario.util.isac.loadprofile.Point; 36 import org.objectweb.clif.scenario.util.isac.loadprofile.RampDescription; 37 import org.objectweb.clif.scenario.util.isac.loadprofile.gui.Size; 38 import org.objectweb.clif.scenario.util.isac.plugin.PluginManager; 39 import org.objectweb.clif.scenario.util.isac.util.tree.nodes.ChoiceNode; 40 import org.objectweb.clif.scenario.util.isac.util.tree.nodes.ControlerNode; 41 import org.w3c.dom.Document ; 42 import org.w3c.dom.Element ; 43 import org.w3c.dom.NamedNodeMap ; 44 import org.w3c.dom.Node ; 45 import org.w3c.dom.NodeList ; 46 import org.xml.sax.InputSource ; 47 48 55 public class LoadScenario { 56 static Category cat = Category.getInstance(LoadScenario.class.getName()); 57 58 static PluginManager pluginManager = PluginManager.getPluginManager(); 59 60 private static TreeManager treeManager = TreeManager.getTreeManager(null); 61 62 private static LoadProfileManager loadProfileManager = LoadProfileManager 63 .getInstance(); 64 65 private static NodeDescription currentDesc = null; 66 67 private static String currentControllerType = null; 68 69 private static ScenarioNode tree = null; 70 71 private static ScenarioNode lastControllerNode = null; 72 73 private static String currentGroupId = null; 74 75 private static RampDescription currentRamp = null; 76 77 private static Point currentEnd = null; 78 79 private static Point currentStart = null; 80 81 private static Point lastEnd = null; 82 83 private static Size maxScale = new Size(0,0) ; 84 85 101 private static boolean visit(ScenarioNode parent, 102 boolean isControllerChild, Node node, Hashtable nodes, Vector errors) { 103 ScenarioNode result = null; 104 105 boolean flag = false; 107 String tagName = null; 108 switch (node.getNodeType()) { 109 case Node.ELEMENT_NODE: 110 tagName = ((Element ) node).getTagName(); 111 if (tagName 112 .equals(org.objectweb.clif.scenario.util.isac.util.tree.Node.BEHAVIORS)) { 113 NodeDescription desc = NodeDescription 114 .createNonePluginNode(org.objectweb.clif.scenario.util.isac.util.tree.Node.BEHAVIORS); 115 int keyInt = desc.hashCode(); 117 while (nodes.containsKey(new String ((new Integer (keyInt)) 119 .toString()))) 120 keyInt++; 121 nodes.put(new String ((new Integer (keyInt)).toString()), desc); 123 result = new ScenarioNode(new String ((new Integer (keyInt)) 125 .toString())); 126 tree = result; 128 } else if (tagName 129 .equals(org.objectweb.clif.scenario.util.isac.util.tree.Node.BEHAVIOR)) { 130 NodeDescription desc = NodeDescription 132 .createNonePluginNode(org.objectweb.clif.scenario.util.isac.util.tree.Node.BEHAVIOR); 133 134 NamedNodeMap attributs = node.getAttributes(); 135 if (attributs.getLength() < 1) { 137 errors.add("WARNING:" + "The node \"" + tagName 138 + "\" must define an attribute \"id\""); 139 140 } else { 141 Node id = attributs.getNamedItem("id"); 142 if (id == null) { 143 errors 144 .add("WARNING:" 145 + "The attribute \"id\" is not defined in a node " 146 + tagName); 147 } else { 148 String idValue = id.getNodeValue(); 149 if (idValue.equals("")) { 150 errors 151 .add("WARNING:" 152 + "The attribute \"id\" is not initialised in a node " 153 + tagName); 154 } else { 155 if (!treeManager.getBehaviorsIds() 157 .contains(idValue)) { 158 desc.getParams().remove("id"); 160 desc.getParams().put("id", idValue); 161 cat.debug("ID OF THE BEHAVIOR="+idValue) ; 162 } 163 else { 164 errors.add("ERROR: The value of this behavior id already exist : " + idValue) ; 165 } 166 } 167 } 168 } 169 int keyInt = desc.hashCode(); 171 while (nodes.containsKey(new String ((new Integer (keyInt)) 173 .toString()))) 174 keyInt++; 175 nodes.put(new String ((new Integer (keyInt)).toString()), desc); 177 result = new ScenarioNode(new String ((new Integer (keyInt)) 179 .toString())); 180 } else if (org.objectweb.clif.scenario.util.isac.util.tree.Node.USE 181 .equals(tagName)) { 182 NamedNodeMap attributs = node.getAttributes(); 183 if (attributs.getLength() < 2) { 185 errors 186 .add("ERROR:" 187 + "The node \"" 188 + tagName 189 + "\" must define two parameters, \"id\" and \"name\""); 190 return false; 191 } 192 Node id = attributs.getNamedItem("id"); 193 if (id == null) { 194 errors 195 .add("ERROR:" 196 + "The parameter \"id\" is not defined in the node " 197 + tagName); 198 return false; 199 } 200 String idValue = id.getNodeValue(); 201 if (idValue.equals("")) { 202 errors 203 .add("ERROR:" 204 + "The parameter \"id\" is not initialised in the node " 205 + tagName); 206 return false; 207 } 208 Node name = attributs.getNamedItem("name"); 209 if (name == null) { 210 errors 211 .add("ERROR:" 212 + "The parameter \"name\" is not defined in the node " 213 + tagName); 214 return false; 215 } 216 String nameValue = name.getNodeValue(); 217 if (nameValue.equals("")) { 218 errors 219 .add("ERROR:" 220 + "The parameter \"name\" is not intialised in the node " 221 + tagName); 222 return false; 223 } 224 Vector descs = pluginManager.createNodesDescriptions(tagName); 225 NodeDescription desc = null; 226 for (int i = 0; i < descs.size(); i++) { 227 if (((NodeDescription) descs.elementAt(i)).getPlugin() 228 .equals(nameValue)) 229 desc = (NodeDescription) descs.elementAt(i); 230 } 231 if (desc == null) { 232 errors.add("ERROR:" 233 + "The plugin used could not be found : " 234 + nameValue); 235 return false; 236 } 237 Hashtable params = desc.getParams(); 239 params.remove("id"); 240 params.put("id", idValue); 241 242 currentDesc = desc; 245 int keyInt = desc.hashCode(); 247 while (nodes.containsKey(new String ((new Integer (keyInt)) 249 .toString()))) 250 keyInt++; 251 nodes.put(new String ((new Integer (keyInt)).toString()), desc); 253 result = new ScenarioNode(new String ((new Integer (keyInt)) 255 .toString())); 256 } else if (org.objectweb.clif.scenario.util.isac.util.tree.Node 257 .isPluginNode(tagName)) { 258 NamedNodeMap attributs = node.getAttributes(); 259 if (attributs.getLength() < 2) { 261 errors 262 .add("ERROR:" 263 + "The node \"" 264 + tagName 265 + "\" must define two parameters, \"use\" and \"name\""); 266 return false; 267 } 268 Node use = attributs.getNamedItem("use"); 269 if (use == null) { 270 errors 271 .add("ERROR:" 272 + "The parameter \"use\" is not defined in the node " 273 + tagName); 274 return false; 275 } 276 String useValue = use.getNodeValue(); 277 if (useValue.equals("")) { 278 errors 279 .add("ERROR:" 280 + "The parameter \"use\" is not initialised in the node " 281 + tagName); 282 return false; 283 } 284 Node name = attributs.getNamedItem("name"); 285 if (name == null) { 286 errors 287 .add("ERROR:" 288 + "The parameter \"name\" is not defined in the node " 289 + tagName); 290 return false; 291 } 292 String nameValue = name.getNodeValue(); 293 if (nameValue.equals("")) { 294 errors 295 .add("ERROR:" 296 + "The parameter \"name\" is not intialised in the node " 297 + tagName); 298 return false; 299 } 300 Hashtable usedPlugins = TreeManager.getUsedPlugins(nodes); 301 if (!usedPlugins.containsKey(useValue)) { 302 errors 303 .add("ERROR:" 304 + "The plugin used in this action could not be found : " 305 + useValue); 306 return false; 307 } else { 308 NodeDescription descPlugin = (NodeDescription) usedPlugins 309 .get(useValue); 310 String pluginName = descPlugin.getPlugin(); 311 NodeDescription desc = pluginManager.createNodeDescription( 312 pluginName, tagName, nameValue); 313 currentDesc = desc; 316 Hashtable params = currentDesc.getParams(); 318 if (params != null) { 319 if (params.containsKey("id")) { 320 params.remove("id"); 322 params.put("id", useValue); 323 } 324 } 325 int keyInt = desc.hashCode(); 327 while (nodes.containsKey(new String ((new Integer (keyInt)) 329 .toString()))) 330 keyInt++; 331 nodes.put(new String ((new Integer (keyInt)).toString()), 333 desc); 334 result = new ScenarioNode(new String ((new Integer (keyInt)) 336 .toString())); 337 } 338 } else if (tagName 339 .equals(org.objectweb.clif.scenario.util.isac.util.tree.Node.PARAMS)) { 340 } else if (tagName 342 .equals(org.objectweb.clif.scenario.util.isac.util.tree.Node.PARAM)) { 343 NamedNodeMap attributs = node.getAttributes(); 344 if (attributs.getLength() < 2) { 346 errors 347 .add("ERROR:" 348 + "The node \"" 349 + tagName 350 + "\" must define two parameters, \"name\" and \"value\""); 351 return false; 352 } 353 Node name = attributs.getNamedItem("name"); 354 if (name == null) { 355 errors 356 .add("ERROR:" 357 + "The parameter \"name\" is not defined in the node " 358 + tagName); 359 return false; 360 } 361 String nameValue = name.getNodeValue(); 362 if (nameValue.equals("")) { 363 errors 364 .add("ERROR:" 365 + "The parameter \"name\" is not initialised in the node " 366 + tagName); 367 return false; 368 } 369 Node value = attributs.getNamedItem("value"); 370 if (value == null) { 371 errors 372 .add("ERROR:" 373 + "The parameter \"value\" is not defined in the node " 374 + tagName); 375 return false; 376 } 377 String valueValue = value.getNodeValue(); 378 if (valueValue.equals("")) { 379 errors 380 .add("WARNING:" 381 + "The parameter \"value\" is not intialised in the node " 382 + tagName); 383 } 384 if (currentDesc != null) { 385 Hashtable params = currentDesc.getParams(); 386 if (params != null) { 387 if (params.containsKey(nameValue)) { 388 params.remove(nameValue); 390 params.put(nameValue, valueValue); 391 } 392 } 393 } 394 } else if (org.objectweb.clif.scenario.util.isac.util.tree.Node 395 .isControllerNode(tagName)) { 396 currentControllerType = tagName; 398 flag = true; 399 } else if (org.objectweb.clif.scenario.util.isac.util.tree.Node.CONDITION 400 .equals(tagName)) { 401 if (currentControllerType != null) { 402 NamedNodeMap attributs = node.getAttributes(); 403 if (attributs.getLength() < 2) { 405 errors 406 .add("ERROR:" 407 + "The node \"" 408 + tagName 409 + "\" must define two parameters, \"use\" and \"name\""); 410 return false; 411 } 412 Node use = attributs.getNamedItem("use"); 413 if (use == null) { 414 errors 415 .add("ERROR:" 416 + "The parameter \"use\" is not defined in the node " 417 + tagName); 418 return false; 419 } 420 String useValue = use.getNodeValue(); 421 if (useValue.equals("")) { 422 errors 423 .add("ERROR:" 424 + "The parameter \"use\" is not initialised in the node " 425 + tagName); 426 return false; 427 } 428 Node name = attributs.getNamedItem("name"); 429 if (name == null) { 430 errors 431 .add("ERROR:" 432 + "The parameter \"name\" is not defined in the node " 433 + tagName); 434 return false; 435 } 436 String nameValue = name.getNodeValue(); 437 if (nameValue.equals("")) { 438 errors 439 .add("ERROR:" 440 + "The parameter \"name\" is not intialised in the node " 441 + tagName); 442 return false; 443 } 444 Hashtable usedPlugins = TreeManager.getUsedPlugins(nodes); 445 if (!usedPlugins.containsKey(useValue)) { 446 errors 447 .add("ERROR: Unable to find the plugin which is used by this action : " 448 + useValue); 449 return false; 450 } else { 451 NodeDescription descPlugin = (NodeDescription) usedPlugins 452 .get(useValue); 453 String pluginName = descPlugin.getPlugin(); 454 NodeDescription desc = ControlerNode 455 .createNodeDescription(pluginName, 456 currentControllerType, nameValue); 457 currentDesc = desc; 460 Hashtable params = currentDesc.getParams(); 462 if (params != null) { 463 if (params.containsKey("id")) { 464 params.remove("id"); 466 params.put("id", useValue); 467 } 468 } 469 int keyInt = desc.hashCode(); 471 while (nodes.containsKey(new String ( 473 (new Integer (keyInt)).toString()))) 474 keyInt++; 475 nodes.put(new String ((new Integer (keyInt)).toString()), 477 desc); 478 result = new ScenarioNode(new String ((new Integer ( 480 keyInt)).toString())); 481 currentControllerType = null; 483 } 484 } 485 } else if (org.objectweb.clif.scenario.util.isac.util.tree.Node.CHOICE 486 .equals(tagName)) { 487 NamedNodeMap attributs = node.getAttributes(); 488 if (attributs.getLength() < 1) { 490 errors 491 .add("ERROR:" 492 + "The node \"" 493 + tagName 494 + "\" must define one parameter, \"proba\""); 495 return false; 496 } 497 Node proba = attributs.getNamedItem("proba"); 498 if (proba == null) { 499 errors 500 .add("ERROR:" 501 + "The parameter \"proba\" is not defined in the node " 502 + tagName); 503 return false; 504 } 505 String probaValue = proba.getNodeValue(); 506 if (probaValue.equals("")) { 507 errors 508 .add("WARNING:" 509 + "The parameter \"proba\" is not initialised in the node " 510 + tagName); 511 } 512 513 NodeDescription desc = ChoiceNode.createNodeDescription(); 514 currentDesc = desc; 515 Hashtable params = currentDesc.getParams(); 517 if (params != null) { 518 if (params.containsKey("proba")) { 519 params.remove("proba"); 521 params.put("proba", probaValue); 522 } 523 } 524 int keyInt = desc.hashCode(); 525 while (nodes.containsKey(new String ((new Integer (keyInt)) 527 .toString()))) 528 keyInt++; 529 nodes.put(new String ((new Integer (keyInt)).toString()), desc); 531 result = new ScenarioNode(new String ((new Integer (keyInt)) 533 .toString())); 534 } 535 else if (org.objectweb.clif.scenario.util.isac.util.tree.Node.LOAD_PROFILE 537 .equals(tagName)) { 538 } else if (org.objectweb.clif.scenario.util.isac.util.tree.Node.GROUP 540 .equals(tagN
|