KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * @(#)AnalysisModuleIO.java
3  *
4  * Copyright (C) 2002-2003 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 import java.io.Reader JavaDoc;
31 import java.io.Writer JavaDoc;
32
33 import net.sourceforge.groboutils.codecoverage.v2.IAnalysisModule;
34 import net.sourceforge.groboutils.codecoverage.v2.IMethodCode;
35
36 /**
37  * Knows how to read and write an AnalysisModule object.
38  *
39  * @author Matt Albrecht <a HREF="mailto:groboclown@users.sourceforge.net">groboclown@users.sourceforge.net</a>
40  * @version $Date: 2004/04/15 05:48:26 $
41  * @since December 15, 2002
42  */

43 class AnalysisModuleIO
44 {
45     public AnalysisModuleIO()
46     {
47         // do nothing
48
}
49     
50     
51     static class StaleAnalysisModule implements IAnalysisModule
52     {
53         private String JavaDoc name;
54         private String JavaDoc unit;
55         private String JavaDoc mime;
56         
57         public StaleAnalysisModule( String JavaDoc n, String JavaDoc u, String JavaDoc m )
58         {
59             this.name = n;
60             this.unit = u;
61             this.mime = m;
62         }
63         
64         public String JavaDoc getMeasureName() { return this.name; }
65         public String JavaDoc getMeasureUnit() { return this.unit; }
66         public String JavaDoc getMimeEncoding() { return this.mime; }
67         public void analyze( IMethodCode method )
68         {
69             throw new IllegalStateException JavaDoc(
70                 "this is a stale module for measure '"+this.name+"'" );
71         }
72     }
73     
74     public void writeAnalysisModule( IAnalysisModule ams, Writer JavaDoc out )
75             throws IOException JavaDoc
76     {
77         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
78         
79         sb.append( ams.getMeasureName().length() ).
80             append( ':' ).
81             append( ams.getMeasureName() ).
82             append( ',' ).
83             append( ams.getMeasureUnit().length() ).
84             append( ':' ).
85             append( ams.getMeasureUnit() ).
86             append( ',' ).
87             append( ams.getMimeEncoding().length() ).
88             append( ':' ).
89             append( ams.getMimeEncoding() );
90         
91         out.write( sb.toString() );
92     }
93     
94     
95     /**
96      * Does not read in the actual module, but a datastore that
97      * resembles the original.
98      */

99     public IAnalysisModule readAnalysisModule( Reader JavaDoc in )
100             throws IOException JavaDoc
101     {
102         int count = ReadUtil.toInt(
103             ReadUtil.readTo( in, ':' ) );
104         String JavaDoc measureName = ReadUtil.readCount( in, count );
105         ReadUtil.readTo( in, ',' );
106         
107         count = ReadUtil.toInt(
108             ReadUtil.readTo( in, ':' ) );
109         String JavaDoc measureUnit = ReadUtil.readCount( in, count );
110         ReadUtil.readTo( in, ',' );
111         
112         count = ReadUtil.toInt(
113             ReadUtil.readTo( in, ':' ) );
114         String JavaDoc mimeEncoding = ReadUtil.readCount( in, count );
115         
116         return new StaleAnalysisModule( measureName, measureUnit,
117             mimeEncoding );
118     }
119 }
120
121
Popular Tags