KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > clif > scenario > util > isac > engine > EngineScenarioAnalyzer


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;
24
25 import javax.xml.parsers.DocumentBuilder JavaDoc;
26 import javax.xml.parsers.DocumentBuilderFactory JavaDoc;
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 JavaDoc;
33 import org.w3c.dom.Element JavaDoc;
34 import org.w3c.dom.Node JavaDoc;
35 import org.w3c.dom.NodeList JavaDoc;
36 import org.xml.sax.InputSource JavaDoc;
37
38 /**
39  * This class implements methods which will be used to analyze a scenario file
40  * in the engine of the isac module
41  *
42  * @author JC Meillaud
43  * @author A Peyrard
44  */

45 public class EngineScenarioAnalyzer {
46     // statics attributes
47
private static SessionObjectManager sessionObjectManager;
48
49     private static BehaviorManager behaviorManager;
50
51     private static GroupDescriptionManager groupDescriptionManager;
52
53     /**
54      * This method analyse a scenario file
55      *
56      * @param fileName
57      * The file name to be analyzed
58      * @param cl
59      * The class loader to load the scenario file
60      * @param som
61      * The session object manager
62      * @param bm
63      * The behavior manager
64      * @param gdm
65      * The group description manager
66      */

67     public static void analyseScenarioFile(String JavaDoc fileName, ClassLoader JavaDoc cl,
68             SessionObjectManager som, BehaviorManager bm,
69             GroupDescriptionManager gdm) {
70         // store the references of the managers
71
sessionObjectManager = som;
72         behaviorManager = bm;
73         groupDescriptionManager = gdm;
74
75         Document JavaDoc document = null;
76         try {
77             InputSource JavaDoc is = new InputSource JavaDoc(cl.getResourceAsStream(fileName));
78             DocumentBuilderFactory JavaDoc factory = DocumentBuilderFactory
79                     .newInstance();
80             DocumentBuilder JavaDoc builder = factory.newDocumentBuilder();
81             document = builder.parse(is);
82         } catch (Exception JavaDoc e) {
83             throw new IsacRuntimeException(
84                     "Unable to parse the scenario file : " + fileName, e);
85         }
86         // analyse the dom tree
87
visit(document);
88     }
89
90     /**
91      * This method visit the tree build by the DOM parser
92      *
93      * @param node
94      * The root node of the tree
95      */

96     private static void visit(Node JavaDoc node) {
97         // boolean which will store if we need to analyse the node children
98
boolean analyseChild = true;
99         // switch between node type
100
String JavaDoc tagName = null;
101         switch (node.getNodeType()) {
102         case Node.ELEMENT_NODE:
103             tagName = ((Element JavaDoc) node).getTagName();
104             // switch between tag names
105
if (tagName
106                     .equals(org.objectweb.clif.scenario.util.isac.util.tree.Node.PLUGINS)) {
107                 // do nothing
108
}
109             if (tagName
110                     .equals(org.objectweb.clif.scenario.util.isac.util.tree.Node.USE)) {
111                 // add a new session object into the session object manager
112
sessionObjectManager.addSessionObject(node);
113                 // don't analyze the children because we already analyze them in
114
// the manager
115
analyseChild = false;
116             }
117             if (tagName
118                     .equals(org.objectweb.clif.scenario.util.isac.util.tree.Node.BEHAVIORS)) {
119                 // do nothing
120
}
121             if (tagName
122                     .equals(org.objectweb.clif.scenario.util.isac.util.tree.Node.BEHAVIOR)) {
123                 // add a new behavior into the behavior manager
124
behaviorManager.addBehavior(node);
125                 // don't analyze the children because we already analyze them in
126
// the manager
127
analyseChild = false;
128             }
129             if (tagName
130                     .equals(org.objectweb.clif.scenario.util.isac.util.tree.Node.LOAD_PROFILE)) {
131                 // do nothing
132
}
133             if (tagName
134                     .equals(org.objectweb.clif.scenario.util.isac.util.tree.Node.GROUP)) {
135                 // add a group into the group description manager
136
groupDescriptionManager.addGroupDescription(node);
137                 // don't analyze the children because we already analyze them in
138
// the manager
139
analyseChild = false;
140             }
141         }
142         // analyse the child
143
if (node.hasChildNodes() && analyseChild) {
144             NodeList JavaDoc children = node.getChildNodes();
145             for (int i = 0; i < children.getLength(); i++) {
146                 Node JavaDoc tempNode = children.item(i);
147                 if (tempNode.getNodeType() == Node.ELEMENT_NODE) {
148                     visit(tempNode);
149                 }
150             }
151         }
152     }
153 }
Popular Tags