Update of /cvsroot/genex/genex-server/Java In directory sc8-pr-cvs1:/tmp/cvs-serv9305/Java Added Files: ApiGenerator.java GenexApiGenerator.java GenexApiWriter.java GenexContentHandler.java GenexElement.java GenexJava.java build.xml Log Message: Initial commit --- NEW FILE: ApiGenerator.java --- /* * C O P Y R I G H T N O T I C E * * * * @author Hyojoo Kang * * @version draft * * @date 2003.01.13 * * * *************************************************************************** */ package org.bio.genex; import java.io.*; import org.xml.sax.*; import org.xml.sax.helpers.*; /** * Entry Point Class * */ public class ApiGenerator { private final String API_DIRECTORY = "Class"; private GenexJava genexJava; private String apiFileName; private GenexApiWriter genexWriter; /** * CTor */ public ApiGenerator(File xmlFile) { // Perpare the new api file String xmlFileName = xmlFile.getName(); String className = new String(xmlFileName.substring(0, xmlFileName.lastIndexOf("."))); // if it does not exist, make it File classDir = new File(API_DIRECTORY); if ( !classDir.isDirectory() ) classDir.mkdir(); apiFileName = API_DIRECTORY + "/" + className + ".java"; System.out.println("new filename: "+apiFileName+" xml:"+xmlFile.getPath()); try { // Create the parser. XMLReader parser = XMLReaderFactory.createXMLReader( "org.apache.xerces.parsers.SAXParser"); // Create the content handler. GenexContentHandler cHandler = new GenexContentHandler(className); // Set the content handler. parser.setContentHandler(cHandler); // Parse the file. parser.parse(xmlFile.getPath()); // Here is the Genex object genexJava = cHandler.getGenexJava(); try { FileOutputStream fout = new FileOutputStream(apiFileName); // Here is the ApiWriter genexWriter = new GenexApiWriter( fout, genexJava); } catch (FileNotFoundException e) { System.err.println(e); } if ( genexJava == null ) { System.err.println("Error: No GenexJava returned"); } } catch (IOException exception) { exception.printStackTrace(); } catch (SAXException exception) { exception.printStackTrace(); } } /** * WriteClass methodGe * */ public void writeClass() { genexWriter.writeClass(); genexWriter.close(); } } --- NEW FILE: GenexApiGenerator.java --- /* * C O P Y R I G H T N O T I C E * * * * @author Hyojoo Kang * * @version draft * * @date 2003.01.13 * * * *************************************************************************** */ package org.bio.genex; import java.io.*; /** * Entry Point Class * */ public class GenexApiGenerator { /** * ENTRY POINT */ public static void main(String[] args) { if ( args.length == 0 ) { System.out.println("Usage: GenexApiGenerator xmlDir"); return; } System.out.println(args[0]+"|"+args.length); // XML Directory File xmlDir = new File(args[0]); if ( xmlDir.isDirectory() ) { File xmlFiles[] = xmlDir.listFiles(); System.out.println("xml files: "+xmlFiles[0].getName()); for (int i=0; i< xmlFiles.length ; i++) { if ( xmlFiles[i].isFile()) { ApiGenerator apiGen = new ApiGenerator(xmlFiles[i]); apiGen.writeClass(); } else { System.err.println(xmlFiles[i].getName()+" is not a file"); } } } else { System.err.println("'"+args[0]+"' is not a Directory"); } } } --- NEW FILE: GenexApiWriter.java --- /* * C O P Y R I G H T N O T I C E * * * * @author Hyojoo Kang * * @version draft * * @date 2003.01.13 * * * *************************************************************************** */ package org.bio.genex; import java.io.*; /** * GenexApiWriter class */ public class GenexApiWriter extends PrintWriter{ private static final String pkgName = "org.bio.genex"; private GenexJava genexJava; /** * Ctor */ public GenexApiWriter( FileOutputStream fout, GenexJava gj ) { super(fout); genexJava = gj; } /** * Accessors */ public void writeClass() { //-- Basics writeHeader(); writeAttributes(); writeCtor(); //-- APIs writeFetch(); writeInsertFoo(); println("}"); } private void writeHeader() { println("/****************************************************"); println(" *"); println(" *"); println(" * "+ genexJava.getClassName() ); println(" *"); println(" *"); println(" ****************************************************/\n\n"); println("package "+ pkgName + "." + genexJava.getClassName() +";\n"); println("import java.sql.*;"); println("\n\n\npublic class "+ genexJava.getClassName() + " {\n\n"); } private void writeAttributes(){ println(" private String dbUrl = \"jdbc:postgresql:genex\";"); println(" private String dbDriverClassName =\"org.postgresql.Driver\";"); println(" private String dbUsername = \"genex\";"); println(" private String dbPassword = \"genex\";\n"); } private void writeCtor() { println(" /**\n * Constructor\n */"); println(" public Citation() {\n"); println(" }\n"); } private void writeFetch() { println(" /**\n * Fetch\n */"); // println(" public } private void writeInsertFoo() { println(" /**\n * writeInsert\n */"); println(" public void writeInsertFoo() {\n"); println(" Connection conn=null;"); println(" try {"); println(" "); println(" conn = DriverManager.getConnection(dbUrl, dbUsername, dbPassword );"); println(" PreparedStatement ps;"); println(" } catch ( SQLException e) {"); println(" "); println(" System.err.println(e);"); println(" } finally {"); println(" "); println(" if ( conn != null ) {"); println(" try { conn.close(); } catch (Exception e){}"); println(" }\n }\n"); println(" }\n"); } } /* public void writeInsertFoo() { Connection conn=null; try { Class.forName( dbDriverClassName ); conn = DriverManager.getConnection(dbUrl, dbUsername, dbPassword ); PreparedStatement ps = conn.prepareStatement( "insert into citation values " + "(1,2,'titlefoo', 'auth', 'pub', 'publisye', 'edi', 1980, 2, 3, 23, null);"); int cnt = ps.executeUpdate(); System.out.println("Prepared and inserted"); Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery("SELECT * FROM citation;"); while( rs.next() ) { String text = rs.getString("title"); System.out.println("The titiel is :"+text); } conn.close(); } catch ( SQLException e) { System.err.println(e); } catch ( ClassNotFoundException e ) { System.err.println(e); } finally { if ( conn != null ) { try { conn.close(); } catch (Exception e){} } } } */ --- NEW FILE: GenexContentHandler.java --- /* * C O P Y R I G H T N O T I C E * * * * @author Hyojoo Kang * * @version draft * * @date 2003.01.13 * * * *************************************************************************** */ package org.bio.genex; import org.xml.sax.*; import org.xml.sax.helpers.*; /** * <b>Description:</b> * Content handler for GeneX object. * */ public class GenexContentHandler extends DefaultHandler { protected GenexJava genexJava; /** * Ctor */ public GenexContentHandler(String className){ super(); genexJava = new GenexJava(className); } /** * Accessor to genexJava; * */ public GenexJava getGenexJava() { return genexJava; } public void startElement( String uri, String localName, String qName, Attributes attributes) throws SAXException { /* System.out.print( "|"+uri + "|"+localName+"|"+qName+"|"+attributes.getLength()); for(int i=0; i<attributes.getLength(); i++) { String urif = attributes.getURI(i); String localNamef = attributes.getLocalName(i); String value = attributes.getValue(i); System.out.print(" "+urif+"*"+localNamef+"*"+value+"*"); } System.out.println(); */ genexJava.addElement(uri, localName, qName, attributes); } public void endElement( String uri, String localName, String qName) throws SAXException { ;// do nothing for now } // implements ContentHandler } --- NEW FILE: GenexElement.java --- /* * C O P Y R I G H T N O T I C E * * * * @author Hyojoo Kang * * @version draft * * @date 2003.01.13 * * * *************************************************************************** */ package org.bio.genex; import org.xml.sax.*; /** * Genex Element class */ public class GenexElement { private String uri; private String localName; private String qName; private Attributes attr ; /** * Ctor */ public GenexElement(String uri, String localName, String qName, Attributes attr) { this.uri = uri; this.localName = localName; this.qName = qName; this.attr = attr; } /** * Accessors */ public String getLocalName() { return localName; } public String getQName() { return qName; } public Attributes getAttributes() { return attr; } } --- NEW FILE: GenexJava.java --- /* * C O P Y R I G H T N O T I C E * * * * @author Hyojoo Kang * * @version draft * * @date 2003.01.13 * * * *************************************************************************** */ package org.bio.genex; import java.util.ArrayList; import java.io.*; import org.xml.sax.*; /** * <b>Description:</b> * GeneX Java object. * */ public class GenexJava { private static final int INIT_CAPACITY = 20; // Genex Xml Elements private GenexElement xTable; private GenexElement xPrimeKey; private ArrayList xColumns; private GenexElement xUniqueCols; private GenexElement xFKey; private String className; /** * Ctor */ public GenexJava(String className) { xColumns = new ArrayList(INIT_CAPACITY); this.className = className; } public void addElement(String uri, String localName, String qName, Attributes attr) { GenexElement genexE = new GenexElement(uri, localName, qName, attr); if ("table".equals(localName) ) { xTable = genexE; } else if ("primary_key".equals(localName) ) { xPrimeKey = genexE; } else if ("column".equals(localName) ) { xColumns.add(genexE); } else if ("unique".equals(localName) ) { xUniqueCols = genexE; } else if ("foreign_key".equals(localName) ) { xFKey = genexE; } else { System.err.println("Don't know what '"+localName+"' is."); } } /** * Accessors */ public String getClassName() { return className; } public GenexElement getTable() { return xTable; } public ArrayList getColumns() { return xColumns; } } --- NEW FILE: build.xml --- <?xml version="1.0"?> <project default="Genex" basedir="."> <!-- For people who use Jikes --> <property name="build.compiler" value="jikes"/> <property name="build.compiler.pedantic" value="true"/> <property name="build.compiler.emacs" value="true"/> <property name="build.compiler.fulldepend" value="true"/> <property name="src" value="."/> <property name="classes" value="."/> <property name="doc" value="doc"/> <property name="sourcefiles" value="**/*.java"/> <property name="classfiles" value="**/*.class"/> <!-- =================================================================== --> <!-- Help on usage --> <!-- =================================================================== --> <target name="usage"> <echo message=""/> <echo message=""/> <echo message=" Java Genex build file"/> <echo message="-------------------------------------------------------------"/> <echo message=""/> <echo message=""/> <echo message=" See the comments inside the build.xml file for more details."/> <echo message="-------------------------------------------------------------"/> <echo message=""/> <echo message=""/> </target> <!-- =================================================================== --> <!-- Build targets --> <!-- =================================================================== --> <!-- ZIP up results --> <target name="Genex" depends="build"> </target> <!-- Compile source --> <target name="build" depends="prepare"> <javac srcdir="${basedir}" destdir="${basedir}"/> </target> <!-- Create the doc directory --> <target name="prepare"> <mkdir dir="${doc}"/> <!-- javadoc destdir="${doc}" sourcepath="${src}" packagenames="QtDimensionGui"/ --> </target> <!-- Clean any existing files --> <target name="clean"> <delete> <fileset dir="${classes}" includes="${classfiles}"/> </delete> <delete dir="${doc}"/> </target> </project> |