1/*2 * Copyright 2000-2001,2004 The Apache Software Foundation.3 * 4 * Licensed under the Apache License, Version 2.0 (the "License");5 * you may not use this file except in compliance with the License.6 * You may obtain a copy of the License at7 * 8 * http://www.apache.org/licenses/LICENSE-2.09 * 10 * Unless required by applicable law or agreed to in writing, software11 * distributed under the License is distributed on an "AS IS" BASIS,12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13 * See the License for the specific language governing permissions and14 * limitations under the License.15 */1617packageorg.apache.jetspeed.webservices.finance.stockmarket;
1819import org.xml.sax.helpers.XMLFilterImpl;
20import org.xml.sax.ContentHandler;
21import org.xml.sax.*;
2223/***24 SAX-based XML event handler (filter). Works with org.xml.sax.XMLReader to filter25 standard SAX events. This class maps the XML represention of a stock array into a java classes.2627 @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>28 @version $Id: StockQuoteArrayHandler.java,v 1.3 2004/02/23 03:15:29 jford Exp $29*/3031publicclassStockQuoteArrayHandlerextends XMLFilterImpl
32 {
33StockQuote[] array = newBaseStockQuote[0];
34StockQuoteHandler currentVal = null;
35boolean inElement;
3637publicvoid startElement(String uri, String localName, String qName, Attributes attributes)
38 throws SAXException
39 {
40if (attributes.getValue("href") != null)
41thrownew SAXNotSupportedException("href attributes not supported");
42 inElement = true;
43 currentVal = newStockQuoteHandler();
44 currentVal.setParent(this);
45 setContentHandler(currentVal);
46 }
4748publicvoid endElement(String uri, String localName, String qName)
49 throws SAXException
50 {
51if (inElement)
52 {
53 inElement = false;
54StockQuote theVal = currentVal.getResult();
55StockQuote[] newar = newBaseStockQuote[array.length+1];
56 System.arraycopy(array,0,newar,0,array.length);
57 newar[array.length] = theVal;
58 array = newar;
59 } else60 {
61 ContentHandler handler = (ContentHandler)getParent();
62 getParent().setContentHandler(handler);
63 handler.endElement(uri,localName,qName);
64 }
65 }
6667publicvoidcharacters(char[] ch, int start, int length) throws SAXException
68 {
69 }
7071publicStockQuote[] getResult()
72 {
73return array;
74 }
7576publicvoid setContentHandler(ContentHandler handler)
77 {
78 ((XMLReader)getParent()).setContentHandler(handler);
79 }
8081 }
82