1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.jetspeed.webservices.finance.stockmarket;
18
19 import org.xml.sax.helpers.XMLFilterImpl;
20 import org.xml.sax.ContentHandler;
21 import org.xml.sax.*;
22
23 /***
24 SAX-based XML event handler (filter). Works with org.xml.sax.XMLReader to filter
25 standard SAX events. This class maps the XML represention of a stock array into a java classes.
26
27 @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 */
30
31 public class StockQuoteArrayHandler extends XMLFilterImpl
32 {
33 StockQuote[] array = new BaseStockQuote[0];
34 StockQuoteHandler currentVal = null;
35 boolean inElement;
36
37 public void startElement(String uri, String localName, String qName, Attributes attributes)
38 throws SAXException
39 {
40 if (attributes.getValue("href") != null)
41 throw new SAXNotSupportedException("href attributes not supported");
42 inElement = true;
43 currentVal = new StockQuoteHandler();
44 currentVal.setParent(this);
45 setContentHandler(currentVal);
46 }
47
48 public void endElement(String uri, String localName, String qName)
49 throws SAXException
50 {
51 if (inElement)
52 {
53 inElement = false;
54 StockQuote theVal = currentVal.getResult();
55 StockQuote[] newar = new BaseStockQuote[array.length+1];
56 System.arraycopy(array,0,newar,0,array.length);
57 newar[array.length] = theVal;
58 array = newar;
59 } else
60 {
61 ContentHandler handler = (ContentHandler)getParent();
62 getParent().setContentHandler(handler);
63 handler.endElement(uri,localName,qName);
64 }
65 }
66
67 public void characters(char[] ch, int start, int length) throws SAXException
68 {
69 }
70
71 public StockQuote[] getResult()
72 {
73 return array;
74 }
75
76 public void setContentHandler(ContentHandler handler)
77 {
78 ((XMLReader)getParent()).setContentHandler(handler);
79 }
80
81 }
82