KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jetspeed > webservices > finance > stockmarket > StockQuoteArrayHandler


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 at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * 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 and
14  * limitations under the License.
15  */

16
17 package org.apache.jetspeed.webservices.finance.stockmarket;
18
19 import org.xml.sax.helpers.XMLFilterImpl JavaDoc;
20 import org.xml.sax.ContentHandler JavaDoc;
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 JavaDoc
32 {
33     StockQuote[] array = new BaseStockQuote[0];
34     StockQuoteHandler currentVal = null;
35     boolean inElement;
36
37     public void startElement(String JavaDoc uri, String JavaDoc localName, String JavaDoc 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 JavaDoc uri, String JavaDoc localName, String JavaDoc 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 JavaDoc handler = (ContentHandler JavaDoc)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 JavaDoc handler)
77     {
78         ((XMLReader)getParent()).setContentHandler(handler);
79     }
80
81 }
82
83
Popular Tags