KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > clif > scenario > util > isac > plugin > parser > AnalyseSaxPlugin


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.plugin.parser;
24
25 import java.util.Hashtable JavaDoc;
26 import java.util.StringTokenizer JavaDoc;
27 import java.util.Vector JavaDoc;
28
29 import org.apache.log4j.Category;
30 import org.objectweb.clif.scenario.util.isac.plugin.ObjectDescription;
31 import org.objectweb.clif.scenario.util.isac.plugin.ParameterDescription;
32 import org.objectweb.clif.scenario.util.isac.plugin.PluginDescription;
33 import org.objectweb.clif.scenario.util.isac.plugin.SampleDescription;
34 import org.objectweb.clif.scenario.util.isac.plugin.TestDescription;
35 import org.objectweb.clif.scenario.util.isac.plugin.TimerDescription;
36 import org.objectweb.clif.scenario.util.isac.util.tree.Node;
37 import org.xml.sax.Attributes JavaDoc;
38 import org.xml.sax.helpers.DefaultHandler JavaDoc;
39 /**
40  * This class build a new sax handler, which analyse a plugin xml definition file
41  *
42  * @author JC Meillaud
43  * @author A Peyrard
44  */

45 public class AnalyseSaxPlugin extends DefaultHandler JavaDoc {
46     static Category cat = Category.getInstance(AnalyseSaxPlugin.class.getName()) ;
47     
48     private String JavaDoc pluginName;
49     private Hashtable JavaDoc samples;
50     private Hashtable JavaDoc timers;
51     private Hashtable JavaDoc tests;
52     private ObjectDescription object;
53     private String JavaDoc clazz;
54     private String JavaDoc method;
55     private String JavaDoc name;
56     private String JavaDoc number;
57     private String JavaDoc paramName;
58     private String JavaDoc paramType;
59     private Vector JavaDoc params;
60     private boolean inHelp;
61     private Vector JavaDoc help;
62     private PluginDescription plugin ;
63
64     /**
65      * Build a new handler object, whic object is made to analyse a plugin definition file
66      */

67     public AnalyseSaxPlugin() {
68         super();
69         cat.debug("-> constructor") ;
70         this.plugin = null ;
71         this.pluginName = null;
72         this.samples = new Hashtable JavaDoc();
73         this.timers = new Hashtable JavaDoc();
74         this.tests = new Hashtable JavaDoc();
75         this.object = null;
76         this.name = null;
77         this.clazz = null;
78         this.method = null;
79         this.number = null;
80         this.paramName = null;
81         this.paramType = null;
82         this.params = new Vector JavaDoc();
83         this.inHelp = false;
84         this.help = null;
85     }
86
87     public void startElement(
88         String JavaDoc namespaceURI,
89         String JavaDoc localName,
90         String JavaDoc qName,
91         Attributes JavaDoc atts) {
92         cat.debug("-> startElement") ;
93         if (qName.equals("sample")) {
94             this.name = atts.getValue(0);
95             this.clazz = atts.getValue(1);
96             this.method = atts.getValue(2);
97         } else if (qName.equals("object")) {
98             // initialise the name for the object
99
this.name = "SessionObject";
100             this.clazz = atts.getValue(0);
101         } else if (qName.equals("timer")) {
102             this.name = atts.getValue(0);
103             this.number = atts.getValue(1);
104         } else if (qName.equals("test")) {
105             this.name = atts.getValue(0);
106             this.number = atts.getValue(1);
107         } else if (qName.equals("params")) {
108             // do nothing
109
} else if (qName.equals("param")) {
110             ParameterDescription param =
111                 new ParameterDescription(atts.getValue(0), atts.getValue(1));
112             this.params.add(param);
113         } else if (qName.equals("plugin")) {
114             this.pluginName = atts.getValue(0);
115         } else if (qName.equals("help")) {
116             this.inHelp = true;
117             this.help = new Vector JavaDoc();
118         }
119     }
120
121     public void endElement(
122         String JavaDoc namespaceURI,
123         String JavaDoc localName,
124         String JavaDoc qName) {
125         cat.debug("-> endElement") ;
126         // if the tag closed is a plugin node, add the id parameter to it
127
if (Node.isPluginNode(qName) || qName.equals("object")) {
128             cat.warn("ADD A PLUGIN ACTION ID PARAMETER !!! " + qName + " " + this.name) ;
129             this.params.add(new ParameterDescription("id", "String")) ;
130         }
131         if (qName.equals("sample")) {
132             SampleDescription temp =
133                 new SampleDescription(
134                     this.name,
135                     this.clazz,
136                     this.method,
137                     (Vector JavaDoc)this.params.clone(),
138                     this.help);
139             this.samples.put(this.name, temp);
140             this.params.clear() ;
141             this.help = null;
142         } else if (qName.equals("timer")) {
143             TimerDescription temp =
144                 new TimerDescription(
145                     this.name,
146                     this.number,
147                     (Vector JavaDoc)this.params.clone(),
148                     this.help);
149             this.timers.put(this.name, temp);
150             this.params.clear();
151             this.help = null;
152         } else if (qName.equals("test")) {
153             TestDescription temp =
154                 new TestDescription(
155                     this.name,
156                     this.number,
157                     (Vector JavaDoc)this.params.clone(),
158                     this.help);
159             this.tests.put(this.name, temp);
160             this.params.clear();
161             this.help = null;
162         } else if (qName.equals("object")) {
163             cat.warn("CREATE A NEW object " + this.name + " " + this.pluginName) ;
164             cat.warn("Size of params : " + this.params.size()) ;
165             this.object =
166                 new ObjectDescription(
167                     this.name,
168                     this.clazz,
169                     (Vector JavaDoc)this.params.clone(),
170                     this.help);
171             this.params.clear();
172             this.help = null;
173         } else if (qName.equals("help")) {
174             this.inHelp = false;
175         } else if (qName.equals("plugin")) {
176             this.plugin = new PluginDescription(this.pluginName, this.samples, this.tests, this.timers,this.object, this.help) ;
177         }
178     }
179
180     public void characters(char[] ch, int debut, int l) {
181         cat.debug("-> characters") ;
182         // if we are not between tag help, we go away of the function
183
if (!this.inHelp)
184             return;
185         // add help lines
186
String JavaDoc sg;
187         sg = new String JavaDoc(ch, debut, l);
188         // search the caracter which show the break lines
189
StringTokenizer JavaDoc st = new StringTokenizer JavaDoc(sg, "\\");
190         while (st.hasMoreTokens()) {
191             String JavaDoc line = st.nextToken();
192             this.help.add(line);
193         }
194     }
195
196     public PluginDescription getPluginDescription() {
197         return this.plugin ;
198     }
199 }
200
Popular Tags