1 26 27 package net.sourceforge.groboutils.codecoverage.v2.datastore; 28 29 import java.io.IOException ; 30 31 import net.sourceforge.groboutils.codecoverage.v2.IAnalysisModule; 32 33 34 41 public class DirClassMetaDataWriter implements IClassMetaDataWriter 42 { 43 private DirMetaDataIO store; 44 private IAnalysisModule am; 45 private AnalysisModuleSet ams; 46 47 DirClassMetaDataWriter( IAnalysisModule module, DirMetaDataIO data ) 48 throws IOException 49 { 50 if (data == null || module == null) 51 { 52 throw new IllegalArgumentException ("no null args"); 53 } 54 this.store = data; 55 this.am = module; 56 this.ams = data.getAnalysisModuleSet(); 57 } 58 59 60 65 public void writeClassRecord( ClassRecord cr ) 66 throws IOException 67 { 68 if (cr == null) 69 { 70 throw new IllegalArgumentException ("no null args"); 71 } 72 checkClose(); 73 74 cr = getAMClassRecord( cr ); 76 77 this.store.putClassRecord( this.am, cr ); 78 } 79 80 81 85 public void close() 86 throws IOException 87 { 88 checkClose(); 89 this.store = null; 91 } 92 93 94 97 private ClassRecord getAMClassRecord( ClassRecord cr ) 98 throws IOException 99 { 100 ClassRecord c2 = new ClassRecord( cr.getClassName(), cr.getClassCRC(), 101 cr.getSourceFileName(), cr.getMethods(), this.ams ); 102 103 MarkRecord mr[] = cr.getMarksForAnalysisModule( this.am ); 105 for (int i = 0; i < mr.length; ++i) 106 { 107 c2.addMark( mr[i] ); 109 } 110 111 return c2; 112 } 113 114 115 private void checkClose() 116 throws IOException 117 { 118 if (this.store == null) 119 { 120 throw new IOException ( "Writer has already been closed." ); 121 } 122 } 123 124 125 protected void finalize() throws Throwable 126 { 127 super.finalize(); 128 129 if (this.store != null) 131 { 132 throw new IllegalStateException ("Did not close writer."); 133 } 134 } 135 } 136 137 | Popular Tags |