001: /*
002: * @(#)DirMetaDataReader.java
003: *
004: * Copyright (C) 2002-2003 Matt Albrecht
005: * groboclown@users.sourceforge.net
006: * http://groboutils.sourceforge.net
007: *
008: * Permission is hereby granted, free of charge, to any person obtaining a
009: * copy of this software and associated documentation files (the "Software"),
010: * to deal in the Software without restriction, including without limitation
011: * the rights to use, copy, modify, merge, publish, distribute, sublicense,
012: * and/or sell copies of the Software, and to permit persons to whom the
013: * Software is furnished to do so, subject to the following conditions:
014: *
015: * The above copyright notice and this permission notice shall be included in
016: * all copies or substantial portions of the Software.
017: *
018: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
019: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
020: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
021: * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
022: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
023: * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
024: * DEALINGS IN THE SOFTWARE.
025: */
026:
027: package net.sourceforge.groboutils.codecoverage.v2.datastore;
028:
029: import java.io.File;
030: import java.io.IOException;
031:
032: import net.sourceforge.groboutils.codecoverage.v2.IAnalysisModule;
033:
034: /**
035: * Knows how to read the meta-data in a repository.
036: *
037: * @author Matt Albrecht <a href="mailto:groboclown@users.sourceforge.net">groboclown@users.sourceforge.net</a>
038: * @version $Date: 2004/04/15 05:48:26 $
039: * @since December 15, 2002
040: */
041: public class DirMetaDataReader implements IMetaDataReader {
042: private DirMetaDataIO store;
043:
044: /**
045: * Creates a meta-data writer for a specific directory. This directory
046: * should be dedicated to just this writer.
047: */
048: public DirMetaDataReader(File basedir) throws IOException {
049: if (basedir == null) {
050: throw new IllegalArgumentException("No null args.");
051: }
052: this .store = new DirMetaDataIO(basedir);
053: }
054:
055: /**
056: * Returns a mark meta-data reader for a specific class signature.
057: */
058: public IClassMetaDataReader getClassReader(IAnalysisModule module)
059: throws IOException {
060: if (module == null) {
061: throw new IllegalArgumentException("no null args");
062: }
063: checkClose();
064:
065: // check if the module exists?
066:
067: return new DirClassMetaDataReader(module, this .store);
068: }
069:
070: /**
071: * Returns the list of all known modules at the time of recording.
072: */
073: public AnalysisModuleSet getAnalysisModuleSet() throws IOException {
074: checkClose();
075:
076: return this .store.getAnalysisModuleSet();
077: }
078:
079: /**
080: * Closes this reader to prevent further access.
081: */
082: public void close() throws IOException {
083: checkClose();
084: this .store.close();
085: this .store = null;
086: }
087:
088: private void checkClose() throws IOException {
089: if (this .store == null) {
090: throw new IOException("Writer has already been closed.");
091: }
092: }
093:
094: protected void finalize() throws Throwable {
095: Exception ex = null;
096: if (this .store != null) {
097: ex = new IllegalStateException("Did not close writer.");
098: }
099:
100: super .finalize();
101:
102: // class-based post condition
103: if (ex != null) {
104: throw ex;
105: }
106: }
107: }
|