import java.util.*; import java.io.*; public class TA extends RC implements Serializable { Key TTid; protected String Fname; protected String AltFname; protected String Ftype; protected String IsKey; protected String Descr; protected TAtable Table; protected Database Schema; public TT TTid_pp; public RC TTid_fpp; public RC TTid_bpp; public void setTTid(Key value) { TTid = value; } public Key getTTid() { return TTid; } public void setFname(String value) { Fname = value; } public String getFname() { return Fname; } public void setAltFname(String value) { AltFname = value; } public String getAltFname() { return AltFname; } public void setFtype(String value) { Ftype = value; } public String getFtype() { return Ftype; } public void setIsKey(String value) { IsKey = value; } public String getIsKey() { return IsKey; } public void setDescr(String value) { Descr = value; } public String getDescr() { return Descr; } TA(String rowbuffer, Database mySchema) { String buffer; StringTokenizer tokens = new StringTokenizer( rowbuffer ); buffer = tokens.nextToken(); pkid = new Key(buffer, mySchema); buffer = tokens.nextToken(); TTid = new Key(buffer, mySchema); buffer = tokens.nextToken(); Fname = buffer; buffer = tokens.nextToken(); AltFname = buffer; buffer = tokens.nextToken(); Ftype = buffer; buffer = tokens.nextToken(); IsKey = buffer; // We allow spaces in the last one, so // this has to be a bit different buffer = tokens.nextToken("\r\n"); Descr = buffer.trim(); Schema = mySchema; Table = mySchema.TAtab; } public void addRow() { Table.insertRow(this); linkRow(); } public void deleteRow() { Table.removeRow(this); unlinkRow(); } public void linkRow() { TT TTtemp; TA TAtemp; // This loop basically implements link_parent_bp_m for( TTtemp = Schema.TTtab.getFirstRow(); TTtemp != null; TTtemp = Schema.TTtab.getNextRow(TTtemp) ) { if( TTid.compare(TTtemp.getPkid()) == 0 ) { TTid_pp = TTtemp; TAtemp = TTtemp.TAid_bcp; TTtemp.TAid_bcp = this; TTid_fpp = TTtemp; if( TTtemp.TAid_fcp == null ) { TTtemp.TAid_fcp = this; TTid_bpp = TTtemp; } else { TTid_bpp = TAtemp; TAtemp.TTid_fpp = this; } } // End if == }// End for } public void unlinkRow() { TT TTtemp = TTid_pp; TA TAtemp; if( TTtemp != null ) { if( TTtemp.TAid_fcp == this && TTid_fpp == TTtemp ) { TTtemp.TAid_fcp = null; TTtemp.TAid_bcp = null; } else if ( TTtemp.TAid_fcp == this ) { // First child case TTtemp.TAid_fcp = (TA)TTid_fpp; TAtemp = (TA)TTid_fpp; TAtemp.TTid_bpp = TTtemp; } else if ( TTid_fpp == TTtemp ) { // Last child case TTtemp.TAid_bcp = (TA)TTid_bpp; TAtemp = (TA)TTid_bpp; TAtemp.TTid_fpp = TTtemp; } else { TAtemp = (TA)TTid_bpp; TAtemp.TTid_fpp = (TA)TTid_fpp; TAtemp = (TA)TTid_fpp; TAtemp.TTid_bpp = (TA)TTid_bpp; } } } public TAtable getTable() { return Table; } public void setTable(TAtable value) { Table = value; } public Database getSchema() { return Schema; } public void setSchema(Database value) { Schema = value; } public TA() { } public void dumpRow(BufferedWriter output) throws IOException { output.write(this.toString()); output.newLine(); output.flush(); } public String toString() { return pkid + " " + TTid + " " + Fname + " " + AltFname + " " + Ftype + " " + IsKey + " " + Descr; } public static void main(String[] args) { String line = "SV010001 PJ010001 test_de_co.sch CHGEN v9.0 CHGEN"; TA theTable = new TA(); // tt theTable = new TT(line); } }