01: /* Copyright 2001 The JA-SIG Collaborative. All rights reserved.
02: * See license distributed with this file and
03: * available online at http://www.uportal.org/license.html
04: */
05:
06: package org.jasig.portal.tools.dbloader;
07:
08: import org.xml.sax.Attributes;
09: import org.xml.sax.helpers.DefaultHandler;
10:
11: /**
12: * Class for handling SAX events during parsing of dbloader.xml.
13: * All configuration values are stored in a passed in Configuration
14: * object.
15: *
16: * @author Ken Weiner, kweiner@unicon.net
17: * @author Mark Boyd {@link <a href="mailto:mark.boyd@engineer.com">mark.boyd@engineer.com</a>}
18: * @version $Revision: 36690 $
19: */
20: class PropertiesHandler extends DefaultHandler {
21:
22: private static StringBuffer charBuff = null;
23:
24: Configuration properties = null;
25: DbTypeMapping dbTypeMapping;
26: Type type;
27:
28: PropertiesHandler(Configuration config) {
29: this .properties = config;
30: }
31:
32: public void startDocument() {
33: }
34:
35: public void endDocument() {
36: properties.getLog().println("");
37: }
38:
39: public void startElement(String namespaceURI, String localName,
40: String qName, Attributes atts) {
41: charBuff = new StringBuffer();
42:
43: if (qName.equals("db-type-mapping"))
44: dbTypeMapping = new DbTypeMapping();
45: else if (qName.equals("type"))
46: type = new Type();
47: }
48:
49: public void endElement(String namespaceURI, String localName,
50: String qName) {
51: if (qName.equals("drop-tables")) // drop tables ("true" or "false")
52: properties.setDropTables(charBuff.toString());
53: else if (qName.equals("create-tables")) // create tables ("true" or "false")
54: properties.setCreateTables(charBuff.toString());
55: else if (qName.equals("populate-tables")) // populate tables ("true" or "false")
56: properties.setPopulateTables(charBuff.toString());
57: else if (qName.equals("tables-uri")) // tables URI
58: properties.setTablesUri(charBuff.toString());
59: else if (qName.equals("tables-xsl-uri")) // tables xsl URI
60: properties.setTablesXslUri(charBuff.toString());
61: else if (qName.equals("data-uri")) // data xml URI
62: properties.setDataUri(charBuff.toString());
63: else if (qName.equals("create-script")) // create script ("true" or "false")
64: properties.setCreateScript(charBuff.toString());
65: else if (qName.equals("script-file-name")) // script file name
66: properties.setScriptFileName(charBuff.toString());
67: else if (qName.equals("statement-terminator")) // statement terminator
68: properties.setStatementTerminator(charBuff.toString());
69: else if (qName.equals("db-type-mapping"))
70: properties.addDbTypeMapping(dbTypeMapping);
71: else if (qName.equals("db-name")) // database name
72: dbTypeMapping.setDbName(charBuff.toString());
73: else if (qName.equals("db-version")) // database version
74: dbTypeMapping.setDbVersion(charBuff.toString());
75: else if (qName.equals("driver-name")) // driver name
76: dbTypeMapping.setDriverName(charBuff.toString());
77: else if (qName.equals("driver-version")) // driver version
78: dbTypeMapping.setDriverVersion(charBuff.toString());
79: else if (qName.equals("type"))
80: dbTypeMapping.addType(type);
81: else if (qName.equals("generic")) // generic type
82: type.setGeneric(charBuff.toString());
83: else if (qName.equals("local")) // local type
84: type.setLocal(charBuff.toString());
85: }
86:
87: public void characters(char ch[], int start, int length) {
88: charBuff.append(ch, start, length);
89: }
90: }
|