01: package org.mandarax.zkb.framework;
02:
03: /*
04: * Copyright (C) 1999-2004 Jens Dietrich (mailto:mandarax@jbdietrich.com)
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License as published by the Free Software Foundation; either
09: * version 2 of the License, or (at your option) any later version.
10: *
11: * This library is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * Lesser General Public License for more details.
15: *
16: * You should have received a copy of the GNU Lesser General Public
17: * License along with this library; if not, write to the Free Software
18: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19: */
20:
21: import java.io.FileOutputStream;
22: import java.io.IOException;
23: import java.io.PrintStream;
24: import java.util.List;
25:
26: /**
27: * Utility class that generates the DTD for an instance of GenericDriver.
28: * @author <A href="http://www-ist.massey.ac.nz/JBDietrich" target="_top">Jens Dietrich</A>
29: * @version 3.4 <7 March 05>
30: * @version 3.4 <7 March 05>
31: * @since 2.2
32: */
33: public class DTDGenerator {
34: /**
35: * Generate the DTD for a driver.
36: * @param driver a driver
37: * @param out a print stream
38: */
39: public static void generateDTD(GenericDriver driver, PrintStream out)
40: throws IOException {
41: List adapters = driver.getAdapters();
42: StringBuffer buf = new StringBuffer();
43: for (int i = 0; i < adapters.size(); i++) {
44: ((Adapter) adapters.get(i)).printDTD(buf);
45: }
46: out.println(buf.toString());
47: }
48:
49: /**
50: * Generate the DTD for a driver.
51: * @param driver a driver
52: */
53: public static void generateDTD(GenericDriver driver)
54: throws IOException {
55: PrintStream out = new PrintStream(new FileOutputStream(
56: getFile4DTD(driver)));
57: generateDTD(driver, out);
58: out.close();
59: }
60:
61: /**
62: * Run the program for the class ZKBDriver_1_0, output to console.
63: */
64: public static void main(String[] args) throws Exception {
65: GenericDriver driver = new ZKBDriver_1_0();
66: generateDTD(driver);
67: System.out.println("DTD written to " + getFile4DTD(driver));
68:
69: driver = new ZKBDriver_1_1();
70: generateDTD(driver);
71: System.out.println("DTD written to " + getFile4DTD(driver));
72:
73: driver = new ZKBDriver_2_0();
74: generateDTD(driver);
75: System.out.println("DTD written to " + getFile4DTD(driver));
76:
77: System.exit(0);
78: }
79:
80: /**
81: * Get a local dtd file fr a driver.
82: * @param driver the driver
83: * @return a driver name
84: */
85: private static String getFile4DTD(GenericDriver driver) {
86: return "dtd/" + driver.getName() + ".dtd";
87: }
88:
89: }
|