/* Generated By:JavaCC: Do not edit this line. DBPCD.java */ package org.biolegato.database ; import java.awt.image.BufferedImage ; import java.io.File ; import java.io.Reader ; import java.io.FileReader ; import java.io.FileInputStream ; import java.io.IOException ; import java.io.InputStreamReader ; import java.io.BufferedReader ; import java.sql.Connection ; import java.sql.DriverManager ; import java.util.Set ; import java.util.Map ; import java.util.List ; import java.util.HashSet ; import java.util.HashMap ; import java.util.ArrayList ; import java.util.Collection ; import java.util.Collections ; import java.util.LinkedList ; import java.util.LinkedHashMap ; import javax.swing.Action ; import javax.swing.BoxLayout ; import javax.swing.JButton ; import javax.swing.JFrame ; import javax.swing.JMenu ; import javax.swing.JList ; import javax.swing.JPanel ; import javax.swing.JSlider ; import javax.swing.JTabbedPane ; import javax.swing.JTextField ; import javax.swing.JMenuItem ; import javax.swing.ImageIcon ; import javax.imageio.ImageIO ; import org.biopcd.sql.* ; import org.biopcd.widgets.* ; import org.biolegato.database.fields.*; /** * A class used to parse PCD schema files into BioLegato. */ public class DBPCD implements DBPCDConstants { /** * The main database to connect to for the SQL queries within PCD file */ private JDBCDBConnection mainConnection = null; /** * Whether to operate in debug mode */ public static boolean debug = false; public static void main (String[] args) { try { File path = new File(args[0]); DBPCD parser = new DBPCD(new FileReader(path)); DBSchema schema = parser.parseSchema(path.getParentFile(), false); schema.pcdOut(0, System.out); } catch (Throwable th) { th.printStackTrace(System.err); } } /* PRODUCTIONS */ /** * Parses a PCD database schema. ** * @param parent the parent path of the PCD database file - this is used for DB referencing * @param norecurse if true, recursion through reference fields and the like will be skipped (this prevents infinite recursion when parsing reference fields) * @return the parsed schema object */ final public DBSchema parseSchema(File parent, boolean norecurse) throws ParseException { // the name of the primary key for the main table KeyableField key; // the name of the main table in the database that the schema is derived from String table; // the column to be used for displaying a human readable description of each entry stored in the database String name; // the current field being parsed DBField field = null; // the schema object to create Map fields = new LinkedHashMap(); assertIndent(0); jj_consume_token(T_SCHEMA); jj_consume_token(WSP); table = Text(); nl(); assertIndent(1); jj_consume_token(T_NAMECOL); jj_consume_token(WSP); name = Text(); nl(); assertIndent(1); jj_consume_token(T_KEY); jj_consume_token(WSP); key = parseKeyableField(); label_1: while (true) { if (testIndent(1)) { ; } else { break label_1; } field = parseField(table, key, parent, norecurse); if (field != null) { fields.put(field.getName(), field); } } {if (true) return new DBSchema(table, key, fields.get(name), fields.values());} throw new Error("Missing return statement in function"); } /** * Parses a single PCD database field. ** * @param table the name of the table that the field belongs to * @param key the name of the primary key withing table that the field belongs to * @param parent the parent path of the PCD database file - this is used for DB referencing * @param norecurse if true, recursion through reference fields and the like will be skipped (this prevents infinite recursion when parsing reference fields) * @return the parsed field object */ final public DBField parseField(String table, KeyableField key, File parent, boolean norecurse) throws ParseException { // the name of the current field in the database String fieldName; // the human readable version of the current field in the database String fieldLabel; // the object representing the current database field DBField field = null; /////// // For reference objects /////// // the table to reference String refTable; // the primary key of the table to reference String refKey; // the column in the reference table to display String refName; /////// // For command objects /////// // the label to display on the command button String commandLabel; // the command for the button to execute String commandExec; switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case T_INT: case T_TEXT: field = parseKeyableField(); break; case T_DEC: jj_consume_token(T_DEC); jj_consume_token(WSP); fieldName = Text(); nl(); fieldLabel = fieldName; if (testIndent(2)) { jj_consume_token(T_LABEL); jj_consume_token(WSP); fieldLabel = Text(); nl(); } else { ; } field = new DecimalField(fieldName, fieldLabel); break; case T_REF: jj_consume_token(T_REF); jj_consume_token(WSP); fieldName = Text(); nl(); fieldLabel = fieldName; assertIndent(2); switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case T_LABEL: jj_consume_token(T_LABEL); jj_consume_token(WSP); fieldLabel = Text(); nl(); assertIndent(2); break; default: jj_la1[0] = jj_gen; ; } jj_consume_token(T_TABLE); jj_consume_token(WSP); refTable = Text(); nl(); try { if (!norecurse) { DBPCD parser = new DBPCD(new FileReader(parent + File.separator + refTable + ".schema")); DBSchema schema = parser.parseSchema(parent, true); field = new ReferenceField(fieldName, fieldLabel, table, key, refTable, schema.getKey(), schema.getNameCol()); } } catch (Exception ex) { ex.printStackTrace(System.err); } break; case T_BOOL: jj_consume_token(T_BOOL); jj_consume_token(WSP); fieldName = Text(); nl(); fieldLabel = fieldName; if (testIndent(2)) { jj_consume_token(T_LABEL); jj_consume_token(WSP); fieldLabel = Text(); nl(); } else { ; } field = new BooleanField(fieldName, fieldLabel); break; case T_BTN: jj_consume_token(T_BTN); jj_consume_token(WSP); commandLabel = Text(); nl(); if (testIndent(2)) { } else { jj_consume_token(-1); throw new ParseException(); } jj_consume_token(T_EXEC); jj_consume_token(WSP); commandExec = Text(); nl(); field = new DBCommand(commandLabel, commandExec); break; default: jj_la1[1] = jj_gen; jj_consume_token(-1); throw new ParseException(); } {if (true) return field;} throw new Error("Missing return statement in function"); } /** * Parses a single Keyable (i.e. may be used as a database key) PCD database field. ** * @return the parsed field object */ final public KeyableField parseKeyableField() throws ParseException { // the name of the current field in the database String fieldName; // the human readable version of the current field in the database String fieldLabel; // the object representing the current database field KeyableField field = null; // the minimum value for the field (if it is a number field) int fieldMin = 0; // the maximum value for the field (if it is a number field) int fieldMax = 5000000; switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case T_INT: jj_consume_token(T_INT); jj_consume_token(WSP); fieldName = Text(); nl(); fieldLabel = fieldName; if (testIndent(2)) { jj_consume_token(T_LABEL); jj_consume_token(WSP); fieldLabel = Text(); nl(); } else { ; } if (testIndent(2)) { jj_consume_token(T_MIN); jj_consume_token(WSP); fieldMin = Number(); nl(); } else { ; } if (testIndent(2)) { jj_consume_token(T_MAX); jj_consume_token(WSP); fieldMax = Number(); nl(); } else { ; } field = new NumberField(fieldName, fieldLabel, fieldMin, fieldMax); break; case T_TEXT: jj_consume_token(T_TEXT); jj_consume_token(WSP); fieldName = Text(); nl(); fieldLabel = fieldName; if (testIndent(2)) { jj_consume_token(T_LABEL); jj_consume_token(WSP); fieldLabel = Text(); nl(); } else { ; } field = new DBTextField(fieldName, fieldLabel); break; default: jj_la1[2] = jj_gen; jj_consume_token(-1); throw new ParseException(); } {if (true) return field;} throw new Error("Missing return statement in function"); } ////////////////////////// // SHARED PCD CODE // ////////////////////////// /** * Parses an identifier token from a PCD file into a Java String ** * @return the coresponding Java String object */ final public String Ident() throws ParseException { /* The token to parse into a String value */ Token t = null; /* Match a text token */ t = jj_consume_token(ID); {if (true) return t.image;} throw new Error("Missing return statement in function"); } /** * Parses a text token from a PCD file into a Java String ** * @return the coresponding Java String object */ final public String Text() throws ParseException { /* The token to parse into a String value */ Token t = null; /* Match a text token */ t = jj_consume_token(TEXT); {if (true) return t.image.substring(1, t.image.length() - 1).replaceAll("\u005c"\u005c"", "\u005c"");} throw new Error("Missing return statement in function"); } /** * Parses a decimal number from a PCD file into a Java double ** * @return the coresponding Java double value */ final public double Decimal() throws ParseException { /* The double value parsed by the function */ double value = 0d; /* The token to parse into a double value */ Token t = null; switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case DECIMAL: t = jj_consume_token(DECIMAL); try { value = Double.parseDouble(t.image); } catch (NumberFormatException nfe) { /* NOTE: this statement should never be reached because the * token manager will only pass proper decimal numbers * to this code; however, Java requires a try-catch * clause in order to parse Strings into doubles */ {if (true) throw new ParseException("Invalid decimal number on line: " + t.endLine);} } break; case NUMBER: value = Number(); break; default: jj_la1[3] = jj_gen; jj_consume_token(-1); throw new ParseException(); } {if (true) return value;} throw new Error("Missing return statement in function"); } /** * Parses a non-decimal number from a PCD file into a Java integer ** * @return the coresponding Java int value */ final public int Number() throws ParseException { /* The integer value parsed by the function */ int value = 0; /* The token to parse into an integer value */ Token t = null; /* Match the number token to parse */ t = jj_consume_token(NUMBER); try { value = Integer.parseInt(t.image); } catch (NumberFormatException nfe) { /* NOTE: this statement should never be reached because the * token manager will only pass proper numbers to this * code; however, Java requires a try-catch clause in * order to parse Strings into integers */ {if (true) throw new ParseException("Invalid number on line: " + t.endLine);} } {if (true) return value;} throw new Error("Missing return statement in function"); } /** * Parses a boolean token into a java boolean ** * @return the value of the boolean */ final public boolean Bool() throws ParseException { switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case T_TRUE: jj_consume_token(T_TRUE); {if (true) return true;} break; case T_FALSE: jj_consume_token(T_FALSE); {if (true) return false;} break; default: jj_la1[4] = jj_gen; jj_consume_token(-1); throw new ParseException(); } throw new Error("Missing return statement in function"); } /** * Asserts indentation level (calls token_source.testIndent) ** * @param scope the number of indents required */ final public void assertIndent(int scope) throws ParseException { if (!testIndent(scope)) { {if (true) throw new ParseException("Indentation error on line: " + getToken(1).beginLine + " with an indentation of " + (token_source.getIndent() * token_source.INDENT_SIZE) + " spaces (expected " + (scope * token_source.INDENT_SIZE) + " spaces)");} } } /** * Tests indentation (NOTE: this calls the token manager) ** * @param scope the number of indents required */ final public boolean testIndent(int scope) throws ParseException { getToken(1); {if (true) return (token_source.getIndent() == scope && getToken(1).kind != EOF);} throw new Error("Missing return statement in function"); } /** * Matches new line characters including preceding whitespace */ final public void nl() throws ParseException { switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case WSP: jj_consume_token(WSP); break; default: jj_la1[5] = jj_gen; ; } switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case NL: jj_consume_token(NL); break; case 0: jj_consume_token(0); break; default: jj_la1[6] = jj_gen; jj_consume_token(-1); throw new ParseException(); } } /** Generated Token Manager. */ public DBPCDTokenManager token_source; SimpleCharStream jj_input_stream; /** Current token. */ public Token token; /** Next token. */ public Token jj_nt; private int jj_ntk; private int jj_gen; final private int[] jj_la1 = new int[7]; static private int[] jj_la1_0; static private int[] jj_la1_1; static { jj_la1_init_0(); jj_la1_init_1(); } private static void jj_la1_init_0() { jj_la1_0 = new int[] {0x1000,0x1f8,0x108,0x180000,0x6,0x1000000,0x400001,}; } private static void jj_la1_init_1() { jj_la1_1 = new int[] {0x0,0x0,0x0,0x0,0x0,0x0,0x0,}; } /** Constructor with InputStream. */ public DBPCD(java.io.InputStream stream) { this(stream, null); } /** Constructor with InputStream and supplied encoding */ public DBPCD(java.io.InputStream stream, String encoding) { try { jj_input_stream = new SimpleCharStream(stream, encoding, 1, 1); } catch(java.io.UnsupportedEncodingException e) { throw new RuntimeException(e); } token_source = new DBPCDTokenManager(jj_input_stream); token = new Token(); jj_ntk = -1; jj_gen = 0; for (int i = 0; i < 7; i++) jj_la1[i] = -1; } /** Reinitialise. */ public void ReInit(java.io.InputStream stream) { ReInit(stream, null); } /** Reinitialise. */ public void ReInit(java.io.InputStream stream, String encoding) { try { jj_input_stream.ReInit(stream, encoding, 1, 1); } catch(java.io.UnsupportedEncodingException e) { throw new RuntimeException(e); } token_source.ReInit(jj_input_stream); token = new Token(); jj_ntk = -1; jj_gen = 0; for (int i = 0; i < 7; i++) jj_la1[i] = -1; } /** Constructor. */ public DBPCD(java.io.Reader stream) { jj_input_stream = new SimpleCharStream(stream, 1, 1); token_source = new DBPCDTokenManager(jj_input_stream); token = new Token(); jj_ntk = -1; jj_gen = 0; for (int i = 0; i < 7; i++) jj_la1[i] = -1; } /** Reinitialise. */ public void ReInit(java.io.Reader stream) { jj_input_stream.ReInit(stream, 1, 1); token_source.ReInit(jj_input_stream); token = new Token(); jj_ntk = -1; jj_gen = 0; for (int i = 0; i < 7; i++) jj_la1[i] = -1; } /** Constructor with generated Token Manager. */ public DBPCD(DBPCDTokenManager tm) { token_source = tm; token = new Token(); jj_ntk = -1; jj_gen = 0; for (int i = 0; i < 7; i++) jj_la1[i] = -1; } /** Reinitialise. */ public void ReInit(DBPCDTokenManager tm) { token_source = tm; token = new Token(); jj_ntk = -1; jj_gen = 0; for (int i = 0; i < 7; i++) jj_la1[i] = -1; } private Token jj_consume_token(int kind) throws ParseException { Token oldToken; if ((oldToken = token).next != null) token = token.next; else token = token.next = token_source.getNextToken(); jj_ntk = -1; if (token.kind == kind) { jj_gen++; return token; } token = oldToken; jj_kind = kind; throw generateParseException(); } /** Get the next Token. */ final public Token getNextToken() { if (token.next != null) token = token.next; else token = token.next = token_source.getNextToken(); jj_ntk = -1; jj_gen++; return token; } /** Get the specific Token. */ final public Token getToken(int index) { Token t = token; for (int i = 0; i < index; i++) { if (t.next != null) t = t.next; else t = t.next = token_source.getNextToken(); } return t; } private int jj_ntk() { if ((jj_nt=token.next) == null) return (jj_ntk = (token.next=token_source.getNextToken()).kind); else return (jj_ntk = jj_nt.kind); } private java.util.List jj_expentries = new java.util.ArrayList(); private int[] jj_expentry; private int jj_kind = -1; /** Generate ParseException. */ public ParseException generateParseException() { jj_expentries.clear(); boolean[] la1tokens = new boolean[37]; if (jj_kind >= 0) { la1tokens[jj_kind] = true; jj_kind = -1; } for (int i = 0; i < 7; i++) { if (jj_la1[i] == jj_gen) { for (int j = 0; j < 32; j++) { if ((jj_la1_0[i] & (1<