001: /*
002: * This software is released under a licence similar to the Apache Software Licence.
003: * See org.logicalcobwebs.proxool.package.html for details.
004: * The latest version is available at http://proxool.sourceforge.net
005: */
006: package org.logicalcobwebs.dbscript;
007:
008: import org.apache.commons.logging.Log;
009: import org.apache.commons.logging.LogFactory;
010: import org.xml.sax.Attributes;
011: import org.xml.sax.SAXException;
012: import org.xml.sax.helpers.DefaultHandler;
013:
014: /**
015: * Parser to get {@link org.logicalcobwebs.dbscript.Script} from XML source
016: *
017: * @version $Revision: 1.9 $, $Date: 2006/01/18 14:40:05 $
018: * @author Bill Horsman (bill@logicalcobwebs.co.uk)
019: * @author $Author: billhorsman $ (current maintainer)
020: * @since Proxool 0.5
021: */
022: class ScriptBuilder extends DefaultHandler {
023:
024: private static final Log LOG = LogFactory
025: .getLog(ScriptBuilder.class);
026:
027: private Script script = null;
028:
029: /**
030: * @see DefaultHandler#startElement
031: */
032: public void startElement(String uri, String localName,
033: String qName, Attributes attributes) throws SAXException {
034:
035: if (qName.equals("script")) {
036: script = new Script();
037: script.setName(attributes.getValue("name"));
038: script.setDriver(attributes.getValue("driver"));
039: script.setUrl(attributes.getValue("url"));
040:
041: } else if (qName.equals("info")) {
042: String name = attributes.getValue("name");
043: String value = attributes.getValue("value");
044: script.addProperty(name, value);
045:
046: } else if (qName.equals("command")) {
047: Command command = new Command();
048: command.setName(attributes.getValue("name"));
049: command.setSql(attributes.getValue("sql"));
050: if (attributes.getValue("load") != null) {
051: int load = Integer
052: .parseInt(attributes.getValue("load"));
053: command.setLoad(load);
054: }
055: if (attributes.getValue("loops") != null) {
056: int loops = Integer.parseInt(attributes
057: .getValue("loops"));
058: command.setLoops(loops);
059: }
060: if (attributes.getValue("exception") != null) {
061: String exception = attributes.getValue("exception");
062: command.setException(exception);
063: }
064: script.addCommand(command);
065: }
066:
067: }
068:
069: /**
070: * Get the script we just built. Call *after* {@link javax.xml.parsers.SAXParser#parse parsing}
071: * @return the new script
072: */
073: protected Script getScript() {
074: return script;
075: }
076:
077: }
078:
079: /*
080: Revision history:
081: $Log: ScriptBuilder.java,v $
082: Revision 1.9 2006/01/18 14:40:05 billhorsman
083: Unbundled Jakarta's Commons Logging.
084:
085: Revision 1.8 2003/03/03 11:12:03 billhorsman
086: fixed licence
087:
088: Revision 1.7 2003/02/19 15:14:21 billhorsman
089: fixed copyright (copy and paste error,
090: not copyright change)
091:
092: Revision 1.6 2003/02/06 17:41:02 billhorsman
093: now uses imported logging
094:
095: Revision 1.5 2002/11/09 16:00:08 billhorsman
096: fix doc
097:
098: Revision 1.4 2002/11/09 14:45:07 billhorsman
099: now threaded and better exception handling
100:
101: Revision 1.3 2002/11/02 14:22:16 billhorsman
102: Documentation
103:
104: Revision 1.2 2002/11/02 13:57:34 billhorsman
105: checkstyle
106:
107: Revision 1.1 2002/11/02 11:29:53 billhorsman
108: new script runner for testing
109:
110: */
|