01: package jimm.datavision.source;
02:
03: import jimm.datavision.source.Column;
04: import org.xml.sax.*;
05: import org.xml.sax.helpers.DefaultHandler;
06:
07: import javax.xml.parsers.SAXParserFactory;
08:
09: /**
10: * Reads metadata from XML, creates columns, and hands them to a data source.
11: *
12: * @author Jim Menard, <a href="mailto:jimm@io.com">jimm@io.com</a>
13: * @see DataSource
14: */
15: class MetadataReader extends DefaultHandler {
16:
17: protected DataSource source;
18:
19: MetadataReader(DataSource source) {
20: this .source = source;
21: }
22:
23: public void read(InputSource inputSource) throws Exception {
24: SAXParserFactory.newInstance().newSAXParser().parse(
25: inputSource, this );
26: }
27:
28: public void startElement(final String namespaceURI,
29: final String localName, final String qName,
30: final Attributes attributes) throws SAXException {
31: String tagName = localName;
32: if (tagName == null || tagName.length() == 0)
33: tagName = qName;
34:
35: if ("column".equals(tagName)) {
36: String colName = attributes.getValue("name");
37: int type = Column.typeFromString(attributes
38: .getValue("type"));
39: Column col = new Column(colName, colName, type);
40: col.setDateParseFormat(attributes.getValue("date-format"));
41:
42: source.addColumn(col);
43: }
44: }
45:
46: }
|