KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > groboutils > codecoverage > v2 > datastore > DirClassMetaDataWriter


1 /*
2  * @(#)DirClassMetaDataWriter.java
3  *
4  * Copyright (C) 2002-2004 Matt Albrecht
5  * groboclown@users.sourceforge.net
6  * http://groboutils.sourceforge.net
7  *
8  * Permission is hereby granted, free of charge, to any person obtaining a
9  * copy of this software and associated documentation files (the "Software"),
10  * to deal in the Software without restriction, including without limitation
11  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12  * and/or sell copies of the Software, and to permit persons to whom the
13  * Software is furnished to do so, subject to the following conditions:
14  *
15  * The above copyright notice and this permission notice shall be included in
16  * all copies or substantial portions of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24  * DEALINGS IN THE SOFTWARE.
25  */

26
27 package net.sourceforge.groboutils.codecoverage.v2.datastore;
28
29 import java.io.IOException JavaDoc;
30
31 import net.sourceforge.groboutils.codecoverage.v2.IAnalysisModule;
32
33
34 /**
35  * Knows how to store the meta-data in a repository.
36  *
37  * @author Matt Albrecht <a HREF="mailto:groboclown@users.sourceforge.net">groboclown@users.sourceforge.net</a>
38  * @version $Date: 2004/04/15 05:48:26 $
39  * @since December 16, 2002
40  */

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 JavaDoc
49     {
50         if (data == null || module == null)
51         {
52             throw new IllegalArgumentException JavaDoc("no null args");
53         }
54         this.store = data;
55         this.am = module;
56         this.ams = data.getAnalysisModuleSet();
57     }
58     
59     
60     /**
61      * Writes the given class record and its associated marks for this
62      * Analysis Module to the repository. It will overwrite any existing
63      * data.
64      */

65     public void writeClassRecord( ClassRecord cr )
66             throws IOException JavaDoc
67     {
68         if (cr == null)
69         {
70             throw new IllegalArgumentException JavaDoc("no null args");
71         }
72         checkClose();
73         
74         // create the record for this particular module
75
cr = getAMClassRecord( cr );
76         
77         this.store.putClassRecord( this.am, cr );
78     }
79     
80     
81     /**
82      * Closes off the writer's connection to the store. Mark writers may
83      * still have open connections that are still able to be used.
84      */

85     public void close()
86             throws IOException JavaDoc
87     {
88         checkClose();
89         // do not close the store!!!
90
this.store = null;
91     }
92     
93     
94     /**
95      * Creates a class record for this specific module.
96      */

97     private ClassRecord getAMClassRecord( ClassRecord cr )
98             throws IOException JavaDoc
99     {
100         ClassRecord c2 = new ClassRecord( cr.getClassName(), cr.getClassCRC(),
101             cr.getSourceFileName(), cr.getMethods(), this.ams );
102         
103         // get only the marks for this analysis module
104
MarkRecord mr[] = cr.getMarksForAnalysisModule( this.am );
105         for (int i = 0; i < mr.length; ++i)
106         {
107             // this guarantees a unique addition of marks
108
c2.addMark( mr[i] );
109         }
110             
111         return c2;
112     }
113     
114     
115     private void checkClose()
116             throws IOException JavaDoc
117     {
118         if (this.store == null)
119         {
120             throw new IOException JavaDoc( "Writer has already been closed." );
121         }
122     }
123     
124     
125     protected void finalize() throws Throwable JavaDoc
126     {
127         super.finalize();
128         
129         // class-based post condition
130
if (this.store != null)
131         {
132             throw new IllegalStateException JavaDoc("Did not close writer.");
133         }
134     }
135 }
136
137
Popular Tags