import java.io.*; import java.util.*; public class CodeGenerator implements Serializable { protected Vector fileList; protected PrintWriter file; protected Database theSchema; public CodeGenerator(Database mySchema) { fileList = new Vector(1); theSchema = mySchema; } public Database getTheSchema() { return theSchema; } public void setTheSchema(Database newSchema) { theSchema = newSchema; } public void RegisterFile(String filename) { System.out.println(filename + "..."); fileList.addElement(filename); } protected void OpenFile(String filename) { try { file = new PrintWriter( new FileWriter(filename) ); fileList.addElement(filename); } catch(IOException e) { System.err.println("GENJAVA-F-BADOUTPUT: " + filename + " - " + e.getMessage()); System.exit(-1); } } protected void GenerateRowHeader(TT TTcurr) throws IOException { int startpos = 0; int endpos = 0; // Remove the C-style comment from the description String description = TTcurr.getDescr(); endpos = description.length() - 1; while( description.charAt(startpos) != '/' && description.charAt(startpos + 1) != '*' ) { startpos++; } startpos += 2; while( description.charAt(endpos) != '/' && description.charAt(endpos - 1) != '*' ) { endpos--; } endpos -= 2; description = description.substring(startpos, endpos - startpos).trim(); file.println("import java.util.*;"); file.println("import java.text.DecimalFormat;"); file.println("import java.io.*;"); file.println(); file.println("/**"); file.println(" * " + description ); file.println(" * @author Genjava v1.0"); file.println(" */"); file.println(); file.println("public class " + TTcurr.getTTabb() + " extends RC implements Serializable"); file.println("{"); } public void GenerateRows() { RowGenerator rg = new RowGenerator(this); rg.Generate(); } public void GenerateTables() { TableGenerator tg = new TableGenerator(this); tg.Generate(); } public void GenerateKey() { KeyGenerator kg = new KeyGenerator(this); kg.Generate(); } public void GenerateTableSeqListType() { TableSeqListTypeGenerator tsg = new TableSeqListTypeGenerator(this); tsg.Generate(); } public void GenerateDatabase() { DatabaseGenerator dg = new DatabaseGenerator(this); dg.Generate(); } public void GenerateDocfiles() { Runtime rt = Runtime.getRuntime(); String[] callAndArgs = new String[fileList.size() + 5]; callAndArgs[0] = "javadoc"; callAndArgs[1] = "-d"; callAndArgs[2] = Genjava.directory + Genjava.filesep + "docs"; callAndArgs[3] = "-sourcepath"; callAndArgs[4] = Genjava.directory; for( int i = 0; i < fileList.size(); i++ ) { callAndArgs[i + 5] = (String)fileList.elementAt( i ); } try { Process child = rt.exec(callAndArgs); BufferedReader childOutput = new BufferedReader ( new InputStreamReader( child.getInputStream() ) ); BufferedReader childError = new BufferedReader ( new InputStreamReader( child.getErrorStream() ) ); try { boolean childFinished = false; int read = 0; while( childFinished == false ) { while ( childError.ready() ) { System.err.println( childError.readLine() ); } while ( childOutput.ready() ) { System.out.println( childOutput.readLine() ); } try { child.exitValue(); childFinished = true; System.out.println("javadoc process completed with exit code " + child.exitValue()); childOutput.close(); childError.close(); } catch( Exception excc ) { // NOP } } } catch( IOException e ) { System.err.println("IOException reading child output - " + e); } } catch(IOException e) { System.err.println("IOException - " + e); } } }