1*b1cdbd2cSJim Jagielski /************************************************************** 2*b1cdbd2cSJim Jagielski * 3*b1cdbd2cSJim Jagielski * Licensed to the Apache Software Foundation (ASF) under one 4*b1cdbd2cSJim Jagielski * or more contributor license agreements. See the NOTICE file 5*b1cdbd2cSJim Jagielski * distributed with this work for additional information 6*b1cdbd2cSJim Jagielski * regarding copyright ownership. The ASF licenses this file 7*b1cdbd2cSJim Jagielski * to you under the Apache License, Version 2.0 (the 8*b1cdbd2cSJim Jagielski * "License"); you may not use this file except in compliance 9*b1cdbd2cSJim Jagielski * with the License. You may obtain a copy of the License at 10*b1cdbd2cSJim Jagielski * 11*b1cdbd2cSJim Jagielski * http://www.apache.org/licenses/LICENSE-2.0 12*b1cdbd2cSJim Jagielski * 13*b1cdbd2cSJim Jagielski * Unless required by applicable law or agreed to in writing, 14*b1cdbd2cSJim Jagielski * software distributed under the License is distributed on an 15*b1cdbd2cSJim Jagielski * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*b1cdbd2cSJim Jagielski * KIND, either express or implied. See the License for the 17*b1cdbd2cSJim Jagielski * specific language governing permissions and limitations 18*b1cdbd2cSJim Jagielski * under the License. 19*b1cdbd2cSJim Jagielski * 20*b1cdbd2cSJim Jagielski *************************************************************/ 21*b1cdbd2cSJim Jagielski 22*b1cdbd2cSJim Jagielski 23*b1cdbd2cSJim Jagielski 24*b1cdbd2cSJim Jagielski import java.io.*; 25*b1cdbd2cSJim Jagielski import java.util.*; 26*b1cdbd2cSJim Jagielski 27*b1cdbd2cSJim Jagielski public class pdbcomparison 28*b1cdbd2cSJim Jagielski { 29*b1cdbd2cSJim Jagielski 30*b1cdbd2cSJim Jagielski private String LOGTAG ="LOGFILE"; 31*b1cdbd2cSJim Jagielski private String OUTTAG ="OUTFILE"; 32*b1cdbd2cSJim Jagielski private String LISTTAG ="LISTFILE"; 33*b1cdbd2cSJim Jagielski private String PDBTAG1 ="PDBNAME1"; 34*b1cdbd2cSJim Jagielski private String PDBTAG2 ="PDBNAME2"; 35*b1cdbd2cSJim Jagielski 36*b1cdbd2cSJim Jagielski private String OUTFILE="pdbcomparison.out"; 37*b1cdbd2cSJim Jagielski private String LOGFILE="pdbcomparison.log"; 38*b1cdbd2cSJim Jagielski 39*b1cdbd2cSJim Jagielski private String pdbarr1[]; 40*b1cdbd2cSJim Jagielski private String pdbarr2[]; 41*b1cdbd2cSJim Jagielski 42*b1cdbd2cSJim Jagielski 43*b1cdbd2cSJim Jagielski /** 44*b1cdbd2cSJim Jagielski * Default Constructor 45*b1cdbd2cSJim Jagielski * 46*b1cdbd2cSJim Jagielski * @param 47*b1cdbd2cSJim Jagielski * @return 48*b1cdbd2cSJim Jagielski * 49*b1cdbd2cSJim Jagielski */ pdbcomparison()50*b1cdbd2cSJim Jagielski public void pdbcomparison() 51*b1cdbd2cSJim Jagielski { 52*b1cdbd2cSJim Jagielski } 53*b1cdbd2cSJim Jagielski 54*b1cdbd2cSJim Jagielski /** 55*b1cdbd2cSJim Jagielski * Prints the command line arguments for this class 56*b1cdbd2cSJim Jagielski * 57*b1cdbd2cSJim Jagielski * @param 58*b1cdbd2cSJim Jagielski * 59*b1cdbd2cSJim Jagielski * @return void 60*b1cdbd2cSJim Jagielski * 61*b1cdbd2cSJim Jagielski */ usage()62*b1cdbd2cSJim Jagielski public void usage() 63*b1cdbd2cSJim Jagielski { 64*b1cdbd2cSJim Jagielski String str = new String(); 65*b1cdbd2cSJim Jagielski str += "********************************************************\n"; 66*b1cdbd2cSJim Jagielski str += " java pdbcomparison.java <propFile> \n"; 67*b1cdbd2cSJim Jagielski str += " where propFile is name of Property File...\n"; 68*b1cdbd2cSJim Jagielski str += "********************************************************\n"; 69*b1cdbd2cSJim Jagielski 70*b1cdbd2cSJim Jagielski System.out.println(str); 71*b1cdbd2cSJim Jagielski 72*b1cdbd2cSJim Jagielski } 73*b1cdbd2cSJim Jagielski 74*b1cdbd2cSJim Jagielski /** 75*b1cdbd2cSJim Jagielski * This method, read the Property file and validates the 76*b1cdbd2cSJim Jagielski * entries in that file, and accordingly sets the log file 77*b1cdbd2cSJim Jagielski * output file and updates the array pdbarr1 and pdbarr2 with 78*b1cdbd2cSJim Jagielski * list of pdb's to be compared. 79*b1cdbd2cSJim Jagielski * 80*b1cdbd2cSJim Jagielski * @param propFile Property filename which list the log/outputfile/list/pdb 81*b1cdbd2cSJim Jagielski * names 82*b1cdbd2cSJim Jagielski * @return 83*b1cdbd2cSJim Jagielski * 84*b1cdbd2cSJim Jagielski */ parsePropertyFile(String propFile)85*b1cdbd2cSJim Jagielski public void parsePropertyFile(String propFile) 86*b1cdbd2cSJim Jagielski { 87*b1cdbd2cSJim Jagielski Properties defaultProps = new Properties(); 88*b1cdbd2cSJim Jagielski 89*b1cdbd2cSJim Jagielski try { 90*b1cdbd2cSJim Jagielski FileInputStream in = new FileInputStream(propFile); 91*b1cdbd2cSJim Jagielski defaultProps.load(in); 92*b1cdbd2cSJim Jagielski in.close(); 93*b1cdbd2cSJim Jagielski } catch (IOException e) { 94*b1cdbd2cSJim Jagielski System.out.println("Could not open Property File " + propFile); 95*b1cdbd2cSJim Jagielski return; 96*b1cdbd2cSJim Jagielski } 97*b1cdbd2cSJim Jagielski 98*b1cdbd2cSJim Jagielski 99*b1cdbd2cSJim Jagielski String logFile = defaultProps.getProperty(this.LOGTAG); 100*b1cdbd2cSJim Jagielski String outFile = defaultProps.getProperty(this.OUTTAG); 101*b1cdbd2cSJim Jagielski String listFile = defaultProps.getProperty(this.LISTTAG); 102*b1cdbd2cSJim Jagielski String pdbname1 = defaultProps.getProperty(this.PDBTAG1); 103*b1cdbd2cSJim Jagielski String pdbname2 = defaultProps.getProperty(this.PDBTAG2); 104*b1cdbd2cSJim Jagielski 105*b1cdbd2cSJim Jagielski // validate all command line arguments 106*b1cdbd2cSJim Jagielski if ((listFile == null) && ((pdbname1 == null) || (pdbname2 == null))) 107*b1cdbd2cSJim Jagielski { 108*b1cdbd2cSJim Jagielski System.out.println("Missing listFile or missing pdb filenames in Property file " + propFile); 109*b1cdbd2cSJim Jagielski return; 110*b1cdbd2cSJim Jagielski } 111*b1cdbd2cSJim Jagielski 112*b1cdbd2cSJim Jagielski if (logFile == null || logFile.length() == 0) 113*b1cdbd2cSJim Jagielski logFile = this.LOGFILE; 114*b1cdbd2cSJim Jagielski 115*b1cdbd2cSJim Jagielski if (outFile == null || outFile.length() == 0) 116*b1cdbd2cSJim Jagielski outFile = this.LOGFILE; 117*b1cdbd2cSJim Jagielski 118*b1cdbd2cSJim Jagielski 119*b1cdbd2cSJim Jagielski // validate log and output files 120*b1cdbd2cSJim Jagielski if (! validateAndCreateFile(logFile)) return; 121*b1cdbd2cSJim Jagielski if (! validateAndCreateFile(outFile)) return; 122*b1cdbd2cSJim Jagielski LOGFILE = logFile; 123*b1cdbd2cSJim Jagielski OUTFILE = outFile; 124*b1cdbd2cSJim Jagielski 125*b1cdbd2cSJim Jagielski System.out.println("Output is written to log file... " + LOGFILE); 126*b1cdbd2cSJim Jagielski if (listFile != null) 127*b1cdbd2cSJim Jagielski { 128*b1cdbd2cSJim Jagielski if (! checkFile(listFile)) return; 129*b1cdbd2cSJim Jagielski populatePDBArray(listFile); 130*b1cdbd2cSJim Jagielski } else { 131*b1cdbd2cSJim Jagielski if (! checkFile(pdbname1)) return; 132*b1cdbd2cSJim Jagielski if (! checkFile(pdbname2)) return; 133*b1cdbd2cSJim Jagielski populatePDBArray(pdbname1, pdbname2); 134*b1cdbd2cSJim Jagielski } 135*b1cdbd2cSJim Jagielski } 136*b1cdbd2cSJim Jagielski 137*b1cdbd2cSJim Jagielski /** 138*b1cdbd2cSJim Jagielski * This method validates if the file passed exists. 139*b1cdbd2cSJim Jagielski * If it does , then it is moved to <filename>.bak and then creates a newFile. 140*b1cdbd2cSJim Jagielski * Also validates permissions to create. 141*b1cdbd2cSJim Jagielski * 142*b1cdbd2cSJim Jagielski * @param filename name of file to be created 143*b1cdbd2cSJim Jagielski * @return true, if file could be created 144*b1cdbd2cSJim Jagielski * false, if could not. 145*b1cdbd2cSJim Jagielski * 146*b1cdbd2cSJim Jagielski */ validateAndCreateFile(String filename)147*b1cdbd2cSJim Jagielski private boolean validateAndCreateFile (String filename) 148*b1cdbd2cSJim Jagielski { 149*b1cdbd2cSJim Jagielski if (filename == null) return false; 150*b1cdbd2cSJim Jagielski 151*b1cdbd2cSJim Jagielski File f = null; 152*b1cdbd2cSJim Jagielski try { 153*b1cdbd2cSJim Jagielski f = new File(filename); 154*b1cdbd2cSJim Jagielski } catch (NullPointerException e) { 155*b1cdbd2cSJim Jagielski System.out.println("Could not create a File object for file " + filename); 156*b1cdbd2cSJim Jagielski return false; 157*b1cdbd2cSJim Jagielski } 158*b1cdbd2cSJim Jagielski 159*b1cdbd2cSJim Jagielski if (f.exists()) 160*b1cdbd2cSJim Jagielski { 161*b1cdbd2cSJim Jagielski String newFile = filename + ".bak"; 162*b1cdbd2cSJim Jagielski File newF=null; 163*b1cdbd2cSJim Jagielski try { 164*b1cdbd2cSJim Jagielski newF = new File(newFile); 165*b1cdbd2cSJim Jagielski } catch (Exception ex) { 166*b1cdbd2cSJim Jagielski System.out.println("Could not get File Object instance for " + newFile); 167*b1cdbd2cSJim Jagielski return false; 168*b1cdbd2cSJim Jagielski } 169*b1cdbd2cSJim Jagielski 170*b1cdbd2cSJim Jagielski if (newF.exists()) 171*b1cdbd2cSJim Jagielski { 172*b1cdbd2cSJim Jagielski try { 173*b1cdbd2cSJim Jagielski newF.delete(); 174*b1cdbd2cSJim Jagielski } catch ( SecurityException se) { 175*b1cdbd2cSJim Jagielski System.out.println("Could not get delete " + newFile); 176*b1cdbd2cSJim Jagielski return false; 177*b1cdbd2cSJim Jagielski } 178*b1cdbd2cSJim Jagielski } 179*b1cdbd2cSJim Jagielski 180*b1cdbd2cSJim Jagielski try { 181*b1cdbd2cSJim Jagielski if (! f.renameTo(newF)) 182*b1cdbd2cSJim Jagielski { 183*b1cdbd2cSJim Jagielski System.out.println("Could not rename " + filename + " to " + newFile ); 184*b1cdbd2cSJim Jagielski return false; 185*b1cdbd2cSJim Jagielski } 186*b1cdbd2cSJim Jagielski } catch (SecurityException s) { 187*b1cdbd2cSJim Jagielski System.out.println("SecurityException: " + s.toString()); 188*b1cdbd2cSJim Jagielski return false; 189*b1cdbd2cSJim Jagielski } catch (NullPointerException n) { 190*b1cdbd2cSJim Jagielski System.out.println("NullPointerException: " + n.toString()); 191*b1cdbd2cSJim Jagielski return false; 192*b1cdbd2cSJim Jagielski } 193*b1cdbd2cSJim Jagielski } else { 194*b1cdbd2cSJim Jagielski try { 195*b1cdbd2cSJim Jagielski if (! f.createNewFile()) 196*b1cdbd2cSJim Jagielski { 197*b1cdbd2cSJim Jagielski System.out.println("Could not create " + filename + " Check permissions.."); 198*b1cdbd2cSJim Jagielski return false; 199*b1cdbd2cSJim Jagielski } 200*b1cdbd2cSJim Jagielski } catch (IOException e) { 201*b1cdbd2cSJim Jagielski System.out.println("IOException: " + e.toString()); 202*b1cdbd2cSJim Jagielski return false; 203*b1cdbd2cSJim Jagielski } catch (SecurityException s) { 204*b1cdbd2cSJim Jagielski System.out.println("SecuriityException: " + s.toString() ); 205*b1cdbd2cSJim Jagielski return false; 206*b1cdbd2cSJim Jagielski } 207*b1cdbd2cSJim Jagielski 208*b1cdbd2cSJim Jagielski } 209*b1cdbd2cSJim Jagielski 210*b1cdbd2cSJim Jagielski return true; 211*b1cdbd2cSJim Jagielski 212*b1cdbd2cSJim Jagielski } 213*b1cdbd2cSJim Jagielski 214*b1cdbd2cSJim Jagielski /** 215*b1cdbd2cSJim Jagielski * This method validates if the file exists and is readable 216*b1cdbd2cSJim Jagielski * 217*b1cdbd2cSJim Jagielski * @param filename name of file to be created 218*b1cdbd2cSJim Jagielski * @return true, if file exists and is readable 219*b1cdbd2cSJim Jagielski * false, if not. 220*b1cdbd2cSJim Jagielski * 221*b1cdbd2cSJim Jagielski */ checkFile(String filename)222*b1cdbd2cSJim Jagielski private boolean checkFile(String filename) 223*b1cdbd2cSJim Jagielski { 224*b1cdbd2cSJim Jagielski if (filename == null) return false; 225*b1cdbd2cSJim Jagielski 226*b1cdbd2cSJim Jagielski File f = null; 227*b1cdbd2cSJim Jagielski try { 228*b1cdbd2cSJim Jagielski f = new File(filename); 229*b1cdbd2cSJim Jagielski } catch (NullPointerException e) { 230*b1cdbd2cSJim Jagielski System.out.println("Could not create a File object for file " + filename); 231*b1cdbd2cSJim Jagielski return false; 232*b1cdbd2cSJim Jagielski } 233*b1cdbd2cSJim Jagielski 234*b1cdbd2cSJim Jagielski if (! f.exists()) 235*b1cdbd2cSJim Jagielski { 236*b1cdbd2cSJim Jagielski System.out.println("File " + filename + " does not exist... "); 237*b1cdbd2cSJim Jagielski return false; 238*b1cdbd2cSJim Jagielski } 239*b1cdbd2cSJim Jagielski 240*b1cdbd2cSJim Jagielski if (! f.canRead()) 241*b1cdbd2cSJim Jagielski { 242*b1cdbd2cSJim Jagielski System.out.println("Cannot read file " + filename); 243*b1cdbd2cSJim Jagielski return false; 244*b1cdbd2cSJim Jagielski } 245*b1cdbd2cSJim Jagielski 246*b1cdbd2cSJim Jagielski return true; 247*b1cdbd2cSJim Jagielski 248*b1cdbd2cSJim Jagielski } 249*b1cdbd2cSJim Jagielski 250*b1cdbd2cSJim Jagielski /** 251*b1cdbd2cSJim Jagielski * This method populates the pdb arrays with the names of the pdbs to 252*b1cdbd2cSJim Jagielski * compare. Ths listFile lists a series of entries, wherein each 253*b1cdbd2cSJim Jagielski * line indicates the PDB names to be compared. 254*b1cdbd2cSJim Jagielski * <pdbname1>=<pdbname2> 255*b1cdbd2cSJim Jagielski * 256*b1cdbd2cSJim Jagielski * @param listFile name of the listfile 257*b1cdbd2cSJim Jagielski * @return 258*b1cdbd2cSJim Jagielski * 259*b1cdbd2cSJim Jagielski */ populatePDBArray(String listFile)260*b1cdbd2cSJim Jagielski private void populatePDBArray(String listFile) 261*b1cdbd2cSJim Jagielski { 262*b1cdbd2cSJim Jagielski // open ListFile and populate the PDB list to be compared 263*b1cdbd2cSJim Jagielski if (listFile != null) 264*b1cdbd2cSJim Jagielski { 265*b1cdbd2cSJim Jagielski Properties listProps = new Properties(); 266*b1cdbd2cSJim Jagielski try { 267*b1cdbd2cSJim Jagielski FileInputStream in = new FileInputStream(listFile); 268*b1cdbd2cSJim Jagielski listProps.load(in); 269*b1cdbd2cSJim Jagielski in.close(); 270*b1cdbd2cSJim Jagielski } catch (IOException ex) { 271*b1cdbd2cSJim Jagielski System.out.println("Could not open List File " + listFile); 272*b1cdbd2cSJim Jagielski return; 273*b1cdbd2cSJim Jagielski } 274*b1cdbd2cSJim Jagielski 275*b1cdbd2cSJim Jagielski pdbarr1 = new String[listProps.size()]; 276*b1cdbd2cSJim Jagielski pdbarr2 = new String[listProps.size()]; 277*b1cdbd2cSJim Jagielski Enumeration e = listProps.keys(); 278*b1cdbd2cSJim Jagielski int j=0; 279*b1cdbd2cSJim Jagielski while (e.hasMoreElements()) 280*b1cdbd2cSJim Jagielski { 281*b1cdbd2cSJim Jagielski pdbarr1[j] = (String)e.nextElement(); 282*b1cdbd2cSJim Jagielski pdbarr2[j] = listProps.getProperty(pdbarr1[j]); 283*b1cdbd2cSJim Jagielski j++; 284*b1cdbd2cSJim Jagielski } 285*b1cdbd2cSJim Jagielski 286*b1cdbd2cSJim Jagielski } 287*b1cdbd2cSJim Jagielski } 288*b1cdbd2cSJim Jagielski 289*b1cdbd2cSJim Jagielski /** 290*b1cdbd2cSJim Jagielski * This method populates the pdb arrays with the names of the pdbs to 291*b1cdbd2cSJim Jagielski * compare. 292*b1cdbd2cSJim Jagielski * 293*b1cdbd2cSJim Jagielski * @param pdbname1 Name of 2nd PDB file to be compared 294*b1cdbd2cSJim Jagielski * @param pdbname2 Name of 2nd PDB file to be compared 295*b1cdbd2cSJim Jagielski * @return 296*b1cdbd2cSJim Jagielski * 297*b1cdbd2cSJim Jagielski */ populatePDBArray(String pdbname1, String pdbname2)298*b1cdbd2cSJim Jagielski private void populatePDBArray(String pdbname1, String pdbname2) 299*b1cdbd2cSJim Jagielski { 300*b1cdbd2cSJim Jagielski if (pdbname1 == null) return; 301*b1cdbd2cSJim Jagielski if (pdbname2 == null) return; 302*b1cdbd2cSJim Jagielski 303*b1cdbd2cSJim Jagielski if ((pdbname1 != null) && (pdbname2 != null)) 304*b1cdbd2cSJim Jagielski { 305*b1cdbd2cSJim Jagielski pdbarr1 = new String[1]; 306*b1cdbd2cSJim Jagielski pdbarr2 = new String[1]; 307*b1cdbd2cSJim Jagielski 308*b1cdbd2cSJim Jagielski pdbarr1[0] = pdbname1; 309*b1cdbd2cSJim Jagielski pdbarr2[0] = pdbname2; 310*b1cdbd2cSJim Jagielski } 311*b1cdbd2cSJim Jagielski } 312*b1cdbd2cSJim Jagielski 313*b1cdbd2cSJim Jagielski /** 314*b1cdbd2cSJim Jagielski * This method populates the pdb arrays with the names of the pdbs to 315*b1cdbd2cSJim Jagielski * compare. 316*b1cdbd2cSJim Jagielski * 317*b1cdbd2cSJim Jagielski * @param arrayno Array number which corresponds to the pdb array 318*b1cdbd2cSJim Jagielski * containing list of pdbs 319*b1cdbd2cSJim Jagielski * If 1 then send pdbarr1, if 2 send pdbarr2 else null 320*b1cdbd2cSJim Jagielski * 321*b1cdbd2cSJim Jagielski * @return PDB string array containing list of PDB's 322*b1cdbd2cSJim Jagielski * 323*b1cdbd2cSJim Jagielski */ getPDBArray(int arrayno)324*b1cdbd2cSJim Jagielski private String[] getPDBArray(int arrayno) 325*b1cdbd2cSJim Jagielski { 326*b1cdbd2cSJim Jagielski if (arrayno == 1) return pdbarr1; 327*b1cdbd2cSJim Jagielski if (arrayno == 2) return pdbarr2; 328*b1cdbd2cSJim Jagielski 329*b1cdbd2cSJim Jagielski return null; 330*b1cdbd2cSJim Jagielski } 331*b1cdbd2cSJim Jagielski 332*b1cdbd2cSJim Jagielski /** 333*b1cdbd2cSJim Jagielski * This method comares 2 PDB's and returns true if comparison is equal. 334*b1cdbd2cSJim Jagielski * It uses the PDB Decoder class to decode to a PDB structure and then 335*b1cdbd2cSJim Jagielski * does record comparison 336*b1cdbd2cSJim Jagielski * 337*b1cdbd2cSJim Jagielski * @param pdbname1 Name of one PDB file to be compared 338*b1cdbd2cSJim Jagielski * @param pdbname2 Name of other PDB file to be compared 339*b1cdbd2cSJim Jagielski * 340*b1cdbd2cSJim Jagielski * @return returns true if both PDB's are equal else returns false 341*b1cdbd2cSJim Jagielski * 342*b1cdbd2cSJim Jagielski */ comparePDB(String pdbname1, String pdbname2)343*b1cdbd2cSJim Jagielski private boolean comparePDB(String pdbname1, String pdbname2) 344*b1cdbd2cSJim Jagielski { 345*b1cdbd2cSJim Jagielski PalmDB pdb1=null, pdb2=null; 346*b1cdbd2cSJim Jagielski PDBDecoder decoder = new PDBDecoder(); 347*b1cdbd2cSJim Jagielski try { 348*b1cdbd2cSJim Jagielski pdb1 = decoder.parse(pdbname1); 349*b1cdbd2cSJim Jagielski } catch (Exception e) { 350*b1cdbd2cSJim Jagielski System.out.println("Could not parse PDB " + pdbname1); 351*b1cdbd2cSJim Jagielski return false; 352*b1cdbd2cSJim Jagielski } 353*b1cdbd2cSJim Jagielski 354*b1cdbd2cSJim Jagielski try { 355*b1cdbd2cSJim Jagielski pdb2 = decoder.parse(pdbname2); 356*b1cdbd2cSJim Jagielski } catch (Exception e) { 357*b1cdbd2cSJim Jagielski System.out.println("Could not parse PDB " + pdbname2); 358*b1cdbd2cSJim Jagielski return false; 359*b1cdbd2cSJim Jagielski } 360*b1cdbd2cSJim Jagielski 361*b1cdbd2cSJim Jagielski if (pdb1.equals(pdb2)) { 362*b1cdbd2cSJim Jagielski writeToLog("PDB " + pdbname1 + " and PDB " + pdbname2 + " are equal"); 363*b1cdbd2cSJim Jagielski 364*b1cdbd2cSJim Jagielski return true; 365*b1cdbd2cSJim Jagielski } else { 366*b1cdbd2cSJim Jagielski writeToLog("PDB " + pdbname1 + " and PDB " + pdbname2 + " are not equal"); 367*b1cdbd2cSJim Jagielski return false; 368*b1cdbd2cSJim Jagielski } 369*b1cdbd2cSJim Jagielski } 370*b1cdbd2cSJim Jagielski 371*b1cdbd2cSJim Jagielski 372*b1cdbd2cSJim Jagielski 373*b1cdbd2cSJim Jagielski /** 374*b1cdbd2cSJim Jagielski * Write message to LOGFILE 375*b1cdbd2cSJim Jagielski * 376*b1cdbd2cSJim Jagielski * @param msg Message to be written to log file 377*b1cdbd2cSJim Jagielski * @return 378*b1cdbd2cSJim Jagielski * 379*b1cdbd2cSJim Jagielski */ writeToLog(String msg)380*b1cdbd2cSJim Jagielski private void writeToLog(String msg) 381*b1cdbd2cSJim Jagielski { 382*b1cdbd2cSJim Jagielski if (msg == null) return; 383*b1cdbd2cSJim Jagielski 384*b1cdbd2cSJim Jagielski // Get Output Stream from Log file 385*b1cdbd2cSJim Jagielski RandomAccessFile raf=null; 386*b1cdbd2cSJim Jagielski try { 387*b1cdbd2cSJim Jagielski raf = new RandomAccessFile(LOGFILE, "rw"); 388*b1cdbd2cSJim Jagielski } catch (Exception e) { 389*b1cdbd2cSJim Jagielski System.out.println ("Could not open file " + LOGFILE); 390*b1cdbd2cSJim Jagielski return; 391*b1cdbd2cSJim Jagielski } 392*b1cdbd2cSJim Jagielski 393*b1cdbd2cSJim Jagielski try { 394*b1cdbd2cSJim Jagielski long len = raf.length(); 395*b1cdbd2cSJim Jagielski raf.seek(len); 396*b1cdbd2cSJim Jagielski raf.write(msg.getBytes()); 397*b1cdbd2cSJim Jagielski raf.write("\n".getBytes()); 398*b1cdbd2cSJim Jagielski } catch (IOException e) { 399*b1cdbd2cSJim Jagielski System.out.println("ERROR: Could not write to File " + LOGFILE); 400*b1cdbd2cSJim Jagielski return; 401*b1cdbd2cSJim Jagielski } 402*b1cdbd2cSJim Jagielski } 403*b1cdbd2cSJim Jagielski 404*b1cdbd2cSJim Jagielski /** 405*b1cdbd2cSJim Jagielski * Write status of comparison to OUTFILE 406*b1cdbd2cSJim Jagielski * 407*b1cdbd2cSJim Jagielski * @param status Indicates whether comparsion of PDB's PASSED or FAILED 408*b1cdbd2cSJim Jagielski * @param pdbname1 file name of pdb which was compared. 409*b1cdbd2cSJim Jagielski * @param pdbname2 file name of pdb which was compared. 410*b1cdbd2cSJim Jagielski * 411*b1cdbd2cSJim Jagielski * @return 412*b1cdbd2cSJim Jagielski * 413*b1cdbd2cSJim Jagielski */ writeToOutputFile(String status, String pdbname1, String pdbname2)414*b1cdbd2cSJim Jagielski private void writeToOutputFile(String status, String pdbname1, String pdbname2) 415*b1cdbd2cSJim Jagielski { 416*b1cdbd2cSJim Jagielski if (status == null) return; 417*b1cdbd2cSJim Jagielski if (pdbname1 == null) return; 418*b1cdbd2cSJim Jagielski if (pdbname2 == null) return; 419*b1cdbd2cSJim Jagielski 420*b1cdbd2cSJim Jagielski String msg = pdbname1 + "=" + pdbname2 + ":" + status; 421*b1cdbd2cSJim Jagielski 422*b1cdbd2cSJim Jagielski // Get Output Stream from Log file 423*b1cdbd2cSJim Jagielski RandomAccessFile raf=null; 424*b1cdbd2cSJim Jagielski try { 425*b1cdbd2cSJim Jagielski raf = new RandomAccessFile(OUTFILE, "rw"); 426*b1cdbd2cSJim Jagielski } catch (Exception e) { 427*b1cdbd2cSJim Jagielski System.out.println ("Could not open file " + OUTFILE); 428*b1cdbd2cSJim Jagielski return; 429*b1cdbd2cSJim Jagielski } 430*b1cdbd2cSJim Jagielski 431*b1cdbd2cSJim Jagielski try { 432*b1cdbd2cSJim Jagielski long len = raf.length(); 433*b1cdbd2cSJim Jagielski raf.seek(len); 434*b1cdbd2cSJim Jagielski 435*b1cdbd2cSJim Jagielski raf.write(msg.getBytes()); 436*b1cdbd2cSJim Jagielski raf.write("\n".getBytes()); 437*b1cdbd2cSJim Jagielski } catch (IOException e) { 438*b1cdbd2cSJim Jagielski System.out.println("ERROR: Could not write to File " + OUTFILE); 439*b1cdbd2cSJim Jagielski return; 440*b1cdbd2cSJim Jagielski } 441*b1cdbd2cSJim Jagielski 442*b1cdbd2cSJim Jagielski try { 443*b1cdbd2cSJim Jagielski raf.close(); 444*b1cdbd2cSJim Jagielski } catch (Exception e) { 445*b1cdbd2cSJim Jagielski System.out.println("ERROR: Could not close File " + OUTFILE); 446*b1cdbd2cSJim Jagielski return; 447*b1cdbd2cSJim Jagielski } 448*b1cdbd2cSJim Jagielski 449*b1cdbd2cSJim Jagielski } 450*b1cdbd2cSJim Jagielski 451*b1cdbd2cSJim Jagielski 452*b1cdbd2cSJim Jagielski 453*b1cdbd2cSJim Jagielski /** 454*b1cdbd2cSJim Jagielski * Main starting block of execution 455*b1cdbd2cSJim Jagielski * 456*b1cdbd2cSJim Jagielski * @param command line args captured in an array of Strings 457*b1cdbd2cSJim Jagielski * @return 458*b1cdbd2cSJim Jagielski * 459*b1cdbd2cSJim Jagielski */ main(String args[])460*b1cdbd2cSJim Jagielski public static void main(String args[]) 461*b1cdbd2cSJim Jagielski { 462*b1cdbd2cSJim Jagielski 463*b1cdbd2cSJim Jagielski Date startTime = new Date(); 464*b1cdbd2cSJim Jagielski pdbcomparison pdbcmp = new pdbcomparison(); 465*b1cdbd2cSJim Jagielski int nargs = args.length; 466*b1cdbd2cSJim Jagielski int status=0; 467*b1cdbd2cSJim Jagielski 468*b1cdbd2cSJim Jagielski if (nargs != 1) 469*b1cdbd2cSJim Jagielski { 470*b1cdbd2cSJim Jagielski System.out.println("Incorrect no. of arguments passed..."); 471*b1cdbd2cSJim Jagielski pdbcmp.usage(); 472*b1cdbd2cSJim Jagielski System.exit(-1); 473*b1cdbd2cSJim Jagielski 474*b1cdbd2cSJim Jagielski } 475*b1cdbd2cSJim Jagielski 476*b1cdbd2cSJim Jagielski String propFile = args[0]; 477*b1cdbd2cSJim Jagielski 478*b1cdbd2cSJim Jagielski File f=null; 479*b1cdbd2cSJim Jagielski try { 480*b1cdbd2cSJim Jagielski f = new File(propFile); 481*b1cdbd2cSJim Jagielski } catch (Exception e) { 482*b1cdbd2cSJim Jagielski System.out.println("Exception: Could not open file " + propFile); 483*b1cdbd2cSJim Jagielski System.exit(-1); 484*b1cdbd2cSJim Jagielski } 485*b1cdbd2cSJim Jagielski 486*b1cdbd2cSJim Jagielski if (! f.canRead()) { 487*b1cdbd2cSJim Jagielski System.out.println("Exception: " + propFile + " is not a file "); 488*b1cdbd2cSJim Jagielski System.exit(-1); 489*b1cdbd2cSJim Jagielski } 490*b1cdbd2cSJim Jagielski 491*b1cdbd2cSJim Jagielski if (! f.canRead()) { 492*b1cdbd2cSJim Jagielski System.out.println("Exception: Cannot open file for reading. Please check permissions "); 493*b1cdbd2cSJim Jagielski System.exit(-1); 494*b1cdbd2cSJim Jagielski } 495*b1cdbd2cSJim Jagielski 496*b1cdbd2cSJim Jagielski // parse Property file 497*b1cdbd2cSJim Jagielski pdbcmp.parsePropertyFile(propFile); 498*b1cdbd2cSJim Jagielski 499*b1cdbd2cSJim Jagielski String pdbarr1[] = pdbcmp.getPDBArray(1); 500*b1cdbd2cSJim Jagielski String pdbarr2[] = pdbcmp.getPDBArray(2); 501*b1cdbd2cSJim Jagielski if ( (pdbarr1 == null) || 502*b1cdbd2cSJim Jagielski (pdbarr2 == null) || 503*b1cdbd2cSJim Jagielski (pdbarr1.length == 0) || 504*b1cdbd2cSJim Jagielski (pdbarr1.length == 0)) 505*b1cdbd2cSJim Jagielski { 506*b1cdbd2cSJim Jagielski System.out.println("pdbArray is empty. No PDBS to compare... \n"); 507*b1cdbd2cSJim Jagielski System.exit(-1); 508*b1cdbd2cSJim Jagielski } 509*b1cdbd2cSJim Jagielski 510*b1cdbd2cSJim Jagielski 511*b1cdbd2cSJim Jagielski pdbcmp.writeToLog("************** Start *****************"); 512*b1cdbd2cSJim Jagielski pdbcmp.writeToLog("PDB Comparison: start time " + startTime); 513*b1cdbd2cSJim Jagielski for (int i=0; i<pdbarr1.length; i++) 514*b1cdbd2cSJim Jagielski { 515*b1cdbd2cSJim Jagielski Date pdb_startTime = new Date(); 516*b1cdbd2cSJim Jagielski pdbcmp.writeToLog("\n"); 517*b1cdbd2cSJim Jagielski pdbcmp.writeToLog("start time " + pdb_startTime); 518*b1cdbd2cSJim Jagielski boolean val = pdbcmp.comparePDB(pdbarr1[i], pdbarr2[i]); 519*b1cdbd2cSJim Jagielski Date pdb_endTime = new Date(); 520*b1cdbd2cSJim Jagielski pdbcmp.writeToLog("end time " + pdb_endTime); 521*b1cdbd2cSJim Jagielski 522*b1cdbd2cSJim Jagielski if (val) { 523*b1cdbd2cSJim Jagielski pdbcmp.writeToOutputFile("PASSED", pdbarr1[i], pdbarr2[i]); 524*b1cdbd2cSJim Jagielski status=0; 525*b1cdbd2cSJim Jagielski } else { 526*b1cdbd2cSJim Jagielski pdbcmp.writeToOutputFile("FAILED", pdbarr1[i], pdbarr2[i]); 527*b1cdbd2cSJim Jagielski status=-1; 528*b1cdbd2cSJim Jagielski } 529*b1cdbd2cSJim Jagielski } 530*b1cdbd2cSJim Jagielski 531*b1cdbd2cSJim Jagielski Date endTime = new Date(); 532*b1cdbd2cSJim Jagielski pdbcmp.writeToLog("PDB Comparison: end time " + endTime); 533*b1cdbd2cSJim Jagielski pdbcmp.writeToLog("************** End *****************n"); 534*b1cdbd2cSJim Jagielski pdbcmp.writeToLog("\n"); 535*b1cdbd2cSJim Jagielski 536*b1cdbd2cSJim Jagielski System.exit(status); 537*b1cdbd2cSJim Jagielski } 538*b1cdbd2cSJim Jagielski } 539