1 23 package org.objectweb.clif.scenario.util.isac.engine; 24 25 import javax.xml.parsers.DocumentBuilder ; 26 import javax.xml.parsers.DocumentBuilderFactory ; 27 28 import org.objectweb.clif.scenario.util.isac.engine.behavior.BehaviorManager; 29 import org.objectweb.clif.scenario.util.isac.engine.loadprofile.GroupDescriptionManager; 30 import org.objectweb.clif.scenario.util.isac.engine.sessionobject.SessionObjectManager; 31 import org.objectweb.clif.scenario.util.isac.exception.IsacRuntimeException; 32 import org.w3c.dom.Document ; 33 import org.w3c.dom.Element ; 34 import org.w3c.dom.Node ; 35 import org.w3c.dom.NodeList ; 36 import org.xml.sax.InputSource ; 37 38 45 public class EngineScenarioAnalyzer { 46 private static SessionObjectManager sessionObjectManager; 48 49 private static BehaviorManager behaviorManager; 50 51 private static GroupDescriptionManager groupDescriptionManager; 52 53 67 public static void analyseScenarioFile(String fileName, ClassLoader cl, 68 SessionObjectManager som, BehaviorManager bm, 69 GroupDescriptionManager gdm) { 70 sessionObjectManager = som; 72 behaviorManager = bm; 73 groupDescriptionManager = gdm; 74 75 Document document = null; 76 try { 77 InputSource is = new InputSource (cl.getResourceAsStream(fileName)); 78 DocumentBuilderFactory factory = DocumentBuilderFactory 79 .newInstance(); 80 DocumentBuilder builder = factory.newDocumentBuilder(); 81 document = builder.parse(is); 82 } catch (Exception e) { 83 throw new IsacRuntimeException( 84 "Unable to parse the scenario file : " + fileName, e); 85 } 86 visit(document); 88 } 89 90 96 private static void visit(Node node) { 97 boolean analyseChild = true; 99 String tagName = null; 101 switch (node.getNodeType()) { 102 case Node.ELEMENT_NODE: 103 tagName = ((Element ) node).getTagName(); 104 if (tagName 106 .equals(org.objectweb.clif.scenario.util.isac.util.tree.Node.PLUGINS)) { 107 } 109 if (tagName 110 .equals(org.objectweb.clif.scenario.util.isac.util.tree.Node.USE)) { 111 sessionObjectManager.addSessionObject(node); 113 analyseChild = false; 116 } 117 if (tagName 118 .equals(org.objectweb.clif.scenario.util.isac.util.tree.Node.BEHAVIORS)) { 119 } 121 if (tagName 122 .equals(org.objectweb.clif.scenario.util.isac.util.tree.Node.BEHAVIOR)) { 123 behaviorManager.addBehavior(node); 125 analyseChild = false; 128 } 129 if (tagName 130 .equals(org.objectweb.clif.scenario.util.isac.util.tree.Node.LOAD_PROFILE)) { 131 } 133 if (tagName 134 .equals(org.objectweb.clif.scenario.util.isac.util.tree.Node.GROUP)) { 135 groupDescriptionManager.addGroupDescription(node); 137 analyseChild = false; 140 } 141 } 142 if (node.hasChildNodes() && analyseChild) { 144 NodeList children = node.getChildNodes(); 145 for (int i = 0; i < children.getLength(); i++) { 146 Node tempNode = children.item(i); 147 if (tempNode.getNodeType() == Node.ELEMENT_NODE) { 148 visit(tempNode); 149 } 150 } 151 } 152 } 153 } | Popular Tags |