KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jimm > datavision > source > MetadataReader


1 package jimm.datavision.source;
2 import jimm.datavision.source.Column;
3 import org.xml.sax.*;
4 import org.xml.sax.helpers.DefaultHandler JavaDoc;
5
6 import javax.xml.parsers.SAXParserFactory JavaDoc;
7
8 /**
9  * Reads metadata from XML, creates columns, and hands them to a data source.
10  *
11  * @author Jim Menard, <a HREF="mailto:jimm@io.com">jimm@io.com</a>
12  * @see DataSource
13  */

14 class MetadataReader extends DefaultHandler JavaDoc {
15
16 protected DataSource source;
17
18 MetadataReader(DataSource source) {
19     this.source = source;
20 }
21
22 public void read(InputSource inputSource) throws Exception JavaDoc {
23     SAXParserFactory.newInstance().newSAXParser().parse(inputSource, this);
24 }
25
26 public void startElement(final String JavaDoc namespaceURI, final String JavaDoc localName,
27              final String JavaDoc qName, final Attributes attributes)
28     throws SAXException
29 {
30     String JavaDoc tagName = localName;
31     if (tagName == null || tagName.length() == 0)
32         tagName = qName;
33
34     if ("column".equals(tagName)) {
35     String JavaDoc colName = attributes.getValue("name");
36     int type = Column.typeFromString(attributes.getValue("type"));
37     Column col = new Column(colName, colName, type);
38     col.setDateParseFormat(attributes.getValue("date-format"));
39
40     source.addColumn(col);
41     }
42 }
43
44 }
45
Popular Tags