KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jmeter > protocol > http > modifier > UserParameterXMLContentHandler


1 // $Header: /home/cvs/jakarta-jmeter/src/protocol/http/org/apache/jmeter/protocol/http/modifier/UserParameterXMLContentHandler.java,v 1.4 2004/02/12 00:29:49 sebb Exp $
2
/*
3  * Copyright 2001-2004 The Apache Software Foundation.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17 */

18
19 package org.apache.jmeter.protocol.http.modifier;
20
21 import java.io.CharArrayWriter JavaDoc;
22 import java.util.HashMap JavaDoc;
23 import java.util.LinkedList JavaDoc;
24 import java.util.List JavaDoc;
25 import java.util.Map JavaDoc;
26
27 import org.xml.sax.Attributes JavaDoc;
28 import org.xml.sax.ContentHandler JavaDoc;
29 import org.xml.sax.Locator JavaDoc;
30 import org.xml.sax.SAXException JavaDoc;
31
32 /**
33  * The handler used to read in XML parameter data.
34  *
35  * @author Mark Walsh
36  * @version $Revision: 1.4 $
37  */

38 public class UserParameterXMLContentHandler implements ContentHandler JavaDoc
39 {
40     //-------------------------------------------
41
// Constants and Data Members
42
//-------------------------------------------
43

44     // Note UserParameterXML accesses this variable
45
// to obtain the Set data via method getParsedParameters()
46
private List JavaDoc userThreads = new LinkedList JavaDoc();
47
48     private String JavaDoc paramname = "";
49     private String JavaDoc paramvalue = "";
50     private Map JavaDoc nameValuePair = new HashMap JavaDoc();
51
52     /** Buffer for collecting data from the "characters" SAX event. */
53     private CharArrayWriter JavaDoc contents = new CharArrayWriter JavaDoc();
54
55     //-------------------------------------------
56
// Methods
57
//-------------------------------------------
58

59     /*-------------------------------------------------------------------------
60      * Methods implemented from org.xml.sax.ContentHandler
61      *----------------------------------------------------------------------- */

62     public void setDocumentLocator(Locator JavaDoc locator)
63     {
64     }
65
66     public void startDocument() throws SAXException JavaDoc
67     {
68     }
69
70     public void endDocument() throws SAXException JavaDoc
71     {
72     }
73
74     public void startPrefixMapping(String JavaDoc prefix, String JavaDoc uri)
75         throws SAXException JavaDoc
76     {
77     }
78
79     public void endPrefixMapping(String JavaDoc prefix) throws SAXException JavaDoc
80     {
81     }
82
83     public void startElement(
84         String JavaDoc namespaceURL,
85         String JavaDoc localName,
86         String JavaDoc qName,
87         Attributes JavaDoc atts)
88         throws SAXException JavaDoc
89     {
90
91         contents.reset();
92
93         // haven't got to reset paramname & paramvalue
94
// but did it to keep the code looking correct
95
if (qName.equals("parameter"))
96         {
97             paramname = "";
98             paramvalue = "";
99         }
100
101         // must create a new object,
102
// or else end up with a set full of the same Map object
103
if (qName.equals("thread"))
104         {
105             nameValuePair = new HashMap JavaDoc();
106         }
107
108     }
109
110     public void endElement(String JavaDoc namespaceURI, String JavaDoc localName, String JavaDoc qName)
111         throws SAXException JavaDoc
112     {
113         if (qName.equals("paramname"))
114         {
115             paramname = contents.toString();
116         }
117         if (qName.equals("paramvalue"))
118         {
119             paramvalue = contents.toString();
120         }
121         if (qName.equals("parameter"))
122         {
123             nameValuePair.put(paramname, paramvalue);
124         }
125         if (qName.equals("thread"))
126         {
127             userThreads.add(nameValuePair);
128         }
129     }
130
131     public void characters(char ch[], int start, int length)
132         throws SAXException JavaDoc
133     {
134         contents.write(ch, start, length);
135     }
136
137     public void ignorableWhitespace(char ch[], int start, int length)
138         throws SAXException JavaDoc
139     {
140     }
141
142     public void processingInstruction(String JavaDoc target, String JavaDoc date)
143         throws SAXException JavaDoc
144     {
145     }
146
147     public void skippedEntity(String JavaDoc name) throws SAXException JavaDoc
148     {
149     }
150
151     /*-------------------------------------------------------------------------
152      * Methods (used by UserParameterXML to get XML parameters from XML file)
153      *----------------------------------------------------------------------- */

154
155     /**
156      * results of parsing all user parameter data defined in XML file.
157      * @return all users name value pairs obtained from XML file
158      */

159     public List JavaDoc getParsedParameters()
160     {
161         return userThreads;
162     }
163 }
164
Popular Tags