KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > logicalcobwebs > dbscript > ScriptBuilder


1 /*
2  * This software is released under a licence similar to the Apache Software Licence.
3  * See org.logicalcobwebs.proxool.package.html for details.
4  * The latest version is available at http://proxool.sourceforge.net
5  */

6 package org.logicalcobwebs.dbscript;
7
8 import org.apache.commons.logging.Log;
9 import org.apache.commons.logging.LogFactory;
10 import org.xml.sax.Attributes JavaDoc;
11 import org.xml.sax.SAXException JavaDoc;
12 import org.xml.sax.helpers.DefaultHandler JavaDoc;
13
14 /**
15  * Parser to get {@link org.logicalcobwebs.dbscript.Script} from XML source
16  *
17  * @version $Revision: 1.9 $, $Date: 2006/01/18 14:40:05 $
18  * @author Bill Horsman (bill@logicalcobwebs.co.uk)
19  * @author $Author: billhorsman $ (current maintainer)
20  * @since Proxool 0.5
21  */

22 class ScriptBuilder extends DefaultHandler JavaDoc {
23
24     private static final Log LOG = LogFactory.getLog(ScriptBuilder.class);
25
26     private Script script = null;
27
28     /**
29      * @see DefaultHandler#startElement
30      */

31     public void startElement(String JavaDoc uri, String JavaDoc localName,
32                              String JavaDoc qName, Attributes JavaDoc attributes)
33             throws SAXException JavaDoc {
34
35         if (qName.equals("script")) {
36             script = new Script();
37             script.setName(attributes.getValue("name"));
38             script.setDriver(attributes.getValue("driver"));
39             script.setUrl(attributes.getValue("url"));
40
41         } else if (qName.equals("info")) {
42             String JavaDoc name = attributes.getValue("name");
43             String JavaDoc value = attributes.getValue("value");
44             script.addProperty(name, value);
45
46         } else if (qName.equals("command")) {
47             Command command = new Command();
48             command.setName(attributes.getValue("name"));
49             command.setSql(attributes.getValue("sql"));
50             if (attributes.getValue("load") != null) {
51                 int load = Integer.parseInt(attributes.getValue("load"));
52                 command.setLoad(load);
53             }
54             if (attributes.getValue("loops") != null) {
55                 int loops = Integer.parseInt(attributes.getValue("loops"));
56                 command.setLoops(loops);
57             }
58             if (attributes.getValue("exception") != null) {
59                 String JavaDoc exception = attributes.getValue("exception");
60                 command.setException(exception);
61             }
62             script.addCommand(command);
63         }
64
65     }
66
67     /**
68      * Get the script we just built. Call *after* {@link javax.xml.parsers.SAXParser#parse parsing}
69      * @return the new script
70      */

71     protected Script getScript() {
72         return script;
73     }
74
75 }
76
77 /*
78  Revision history:
79  $Log: ScriptBuilder.java,v $
80  Revision 1.9 2006/01/18 14:40:05 billhorsman
81  Unbundled Jakarta's Commons Logging.
82
83  Revision 1.8 2003/03/03 11:12:03 billhorsman
84  fixed licence
85
86  Revision 1.7 2003/02/19 15:14:21 billhorsman
87  fixed copyright (copy and paste error,
88  not copyright change)
89
90  Revision 1.6 2003/02/06 17:41:02 billhorsman
91  now uses imported logging
92
93  Revision 1.5 2002/11/09 16:00:08 billhorsman
94  fix doc
95
96  Revision 1.4 2002/11/09 14:45:07 billhorsman
97  now threaded and better exception handling
98
99  Revision 1.3 2002/11/02 14:22:16 billhorsman
100  Documentation
101
102  Revision 1.2 2002/11/02 13:57:34 billhorsman
103  checkstyle
104
105  Revision 1.1 2002/11/02 11:29:53 billhorsman
106  new script runner for testing
107
108 */

109
Popular Tags