KickJava   Java API By Example, From Geeks To Geeks.

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


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;
24
25 import java.util.Hashtable JavaDoc;
26
27 import org.xml.sax.Attributes JavaDoc;
28 import org.xml.sax.helpers.DefaultHandler JavaDoc;
29
30 /**
31  * This class is used to parse plugin desciption
32  * file with SAX
33  *
34  * @author JC Meillaud
35  * @author A Peyrard
36  */

37 public class PluginDescriptionFileHandler extends DefaultHandler JavaDoc {
38     // attributes
39
private String JavaDoc methodName ;
40     private String JavaDoc number ;
41     private String JavaDoc clazzName ;
42     private String JavaDoc pluginName ;
43     private Hashtable JavaDoc pluginSessionObjectClassTable ;
44     private Hashtable JavaDoc methodNameConversionTable ;
45     /**
46      * Build a new handler object, which object is made to analyse a plugin definition file
47      * @param pluginName The plugin name
48      * @param psoct the table which store the class name of the session object
49      * @param mnct the table which store the methods names convertions
50      */

51     public PluginDescriptionFileHandler(String JavaDoc pluginName, Hashtable JavaDoc psoct, Hashtable JavaDoc mnct) {
52         super();
53         this.clazzName = null ;
54         this.methodName = null ;
55         this.number = null ;
56         this.pluginName = pluginName ;
57         this.pluginSessionObjectClassTable = psoct ;
58         this.methodNameConversionTable = mnct ;
59     }
60
61     /**
62      * StartElement method will be used when parser find a begining tag
63      */

64     public void startElement(
65         String JavaDoc namespaceURI,
66         String JavaDoc localName,
67         String JavaDoc qName,
68         Attributes JavaDoc atts) {
69         if (qName.equals("sample")) {
70             this.methodName = atts.getValue(0);
71             this.number = atts.getValue(1);
72         } else if (qName.equals("object")) {
73             // initialise the name for the object
74
this.methodName = "SessionObject";
75             this.clazzName = atts.getValue(0);
76         } else if (qName.equals("timer")) {
77             this.methodName = atts.getValue(0);
78             this.number = atts.getValue(1);
79         } else if (qName.equals("test")) {
80             this.methodName = atts.getValue(0);
81             this.number = atts.getValue(1);
82         } else if (qName.equals("params")) {
83             // do nothing
84
} else if (qName.equals("param")) {
85             // do nothing
86
} else if (qName.equals("plugin")) {
87             // do nothing
88
} else if (qName.equals("help")) {
89             // do nothing
90
}
91     }
92
93     /**
94      * endElement method will be used when parser find a ending tag
95      */

96     public void endElement(
97         String JavaDoc namespaceURI,
98         String JavaDoc localName,
99         String JavaDoc qName) {
100         if (qName.equals("sample") || qName.equals("timer") || qName.equals("test")) {
101             String JavaDoc key = this.pluginName + "." + qName + "." + this.methodName ;
102             // add the method to the conversion table
103
this.methodNameConversionTable.put(key, new Integer JavaDoc(this.number)) ;
104         } else if (qName.equals("object")) {
105             // add an entry in the class name table
106
this.pluginSessionObjectClassTable.put(this.pluginName, this.clazzName) ;
107         }
108     }
109
110     public void characters(char[] ch, int debut, int l) {
111         // do nothing
112
}
113 }
114
Popular Tags