1 26 27 package net.sourceforge.groboutils.codecoverage.v2.datastore; 28 29 import java.io.File ; 30 import java.io.IOException ; 31 32 import net.sourceforge.groboutils.codecoverage.v2.IAnalysisModule; 33 34 35 43 public class DirMetaDataWriter implements IMetaDataWriter 44 { 45 private DirMetaDataIO store; 46 47 48 52 public DirMetaDataWriter( File basedir ) 53 throws IOException 54 { 55 if (basedir == null) 56 { 57 throw new IllegalArgumentException ( "No null args." ); 58 } 59 this.store = new DirMetaDataIO( basedir ); 60 } 61 62 63 67 public IClassMetaDataWriter getClassWriter( IAnalysisModule module ) 68 throws IOException 69 { 70 if (module == null) 71 { 72 throw new IllegalArgumentException ("no null args"); 73 } 74 checkClose(); 75 addModule( module ); 76 return new DirClassMetaDataWriter( module, this.store ); 77 } 78 79 80 83 public void close() 84 throws IOException 85 { 86 checkClose(); 87 this.store.close(); 88 this.store = null; 89 } 90 91 92 95 private void addModule( IAnalysisModule module ) 96 throws IOException 97 { 98 105 106 107 AnalysisModuleSet ams = this.store.getAnalysisModuleSet(); 108 if (ams.getAnalysisModuleIndex( module ) < 0) 109 { 110 ams.addAnalysisModule( module ); 112 this.store.putAnalysisModuleSet( ams ); 113 } 114 } 115 116 117 private void checkClose() 118 throws IOException 119 { 120 if (this.store == null) 121 { 122 throw new IOException ( "Writer has already been closed." ); 123 } 124 } 125 126 127 protected void finalize() throws Throwable 130 { 131 Exception ex = null; 132 if (this.store != null) 133 { 134 ex = new IllegalStateException ("Did not close writer."); 135 } 136 137 super.finalize(); 138 139 if (ex != null) 141 { 142 throw ex; 143 } 144 } 145 } 146 | Popular Tags |