001: /**
002: * Library name : Primrose - A Java Database Connection Pool.
003: * Published by Ben Keeping, http://primrose.org.uk .
004: * Copyright (C) 2004 Ben Keeping, primrose.org.uk
005: * Email: Use "Contact Us Form" on website
006: *
007: * This library is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU Lesser General Public
009: * License as published by the Free Software Foundation; either
010: * version 2.1 of the License, or (at your option) any later version.
011: *
012: * This library is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this library; if not, write to the Free Software
019: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020: */package uk.org.primrose.console;
021:
022: import java.io.*;
023:
024: public class GeneratePoolCode {
025:
026: public static void main(String args[]) throws Exception {
027: if (args.length != 3) {
028: System.out
029: .println("java GeneratePoolCode <config file> <out file> <class|interface>");
030:
031: } else {
032: GeneratePoolCode gpc = new GeneratePoolCode(args[0],
033: args[1], args[2]);
034: gpc.doit();
035: }
036:
037: }
038:
039: String configFileName;
040: String outFileName;
041: FileOutputStream outFile;
042: boolean genInterface;
043:
044: public GeneratePoolCode(String configFileName, String outFileName,
045: String classOrInterface) throws IOException {
046: this .configFileName = configFileName;
047: this .outFileName = outFileName;
048:
049: if (classOrInterface.equals("class")) {
050: genInterface = false;
051: } else {
052: genInterface = true;
053: }
054:
055: outFile = new FileOutputStream(outFileName);
056: }
057:
058: public void doit() throws IOException {
059:
060: BufferedReader br = new BufferedReader(new InputStreamReader(
061: new FileInputStream(configFileName)));
062: String line;
063: if (!genInterface) {
064: while ((line = br.readLine()) != null) {
065: String[] parts = line.split("=");
066: String name = parts[0];
067:
068: generateClassVars(name);
069: }
070: }
071: br.close();
072:
073: br = new BufferedReader(new InputStreamReader(
074: new FileInputStream(configFileName)));
075: while ((line = br.readLine()) != null) {
076: String[] parts = line.split("=");
077: String name = parts[0];
078:
079: generateGetSet(name);
080: }
081: br.close();
082:
083: outFile.close();
084: }
085:
086: public void generateClassVars(String name) throws IOException {
087:
088: outFile
089: .write(("\t// The '" + name + "' pool config property\n")
090: .getBytes());
091: outFile.write(("\tprotected String " + name + ";\n\n")
092: .getBytes());
093:
094: outFile.flush();
095: }
096:
097: public void generateGetSet(String name) throws IOException {
098: String camelName = (name.charAt(0) + "").toUpperCase()
099: + name.substring(1, name.length());
100:
101: outFile.write(("\t/**\n").getBytes());
102: outFile
103: .write(("\t*\tGet the '" + name + "' pool config property\n")
104: .getBytes());
105: outFile.write(("\t*/\n").getBytes());
106:
107: if (!genInterface) {
108: outFile
109: .write(("\tpublic String get" + camelName + "() {\n")
110: .getBytes());
111: outFile.write(("\t\treturn " + name + ";\n").getBytes());
112: outFile.write(("\t}\n\n").getBytes());
113: } else {
114: outFile
115: .write(("\tpublic String get" + camelName + "();\n\n")
116: .getBytes());
117:
118: }
119:
120: outFile.write(("\t/**\n").getBytes());
121: outFile
122: .write(("\t*\tSet the '" + name + "' pool config property\n")
123: .getBytes());
124: outFile.write(("\t*/\n").getBytes());
125:
126: if (!genInterface) {
127: outFile.write(("\tpublic void set" + camelName + "(String "
128: + name + ") {\n").getBytes());
129: outFile.write(("\t\tthis." + name + " = " + name + ";\n")
130: .getBytes());
131: outFile.write(("\t}\n\n\n").getBytes());
132: } else {
133: outFile.write(("\tpublic void set" + camelName + "(String "
134: + name + ");\n\n\n").getBytes());
135:
136: }
137:
138: outFile.flush();
139: }
140: }
|