KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > edu > umd > cs > findbugs > ba > RepositoryClassParser


1 /*
2  * Bytecode Analysis Framework
3  * Copyright (C) 2003,2004 University of Maryland
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  */

19
20 package edu.umd.cs.findbugs.ba;
21
22 import java.io.IOException JavaDoc;
23 import java.io.InputStream JavaDoc;
24
25 import org.apache.bcel.Repository;
26 import org.apache.bcel.classfile.ClassParser;
27 import org.apache.bcel.classfile.JavaClass;
28
29 /**
30  * A special version of ClassParser that automatically enters
31  * parsed classes into the Repository. This allows us to
32  * use the Repository to inspect the class hierarchy, based on
33  * the current class path.
34  */

35 public class RepositoryClassParser {
36     private ClassParser classParser;
37
38     /**
39      * Constructor.
40      *
41      * @param inputStream the input stream from which to read the class file
42      * @param fileName filename of the class file
43      */

44     public RepositoryClassParser(InputStream JavaDoc inputStream, String JavaDoc fileName) {
45         classParser = new ClassParser(inputStream, fileName);
46     }
47
48     /**
49      * Constructor.
50      *
51      * @param fileName name of the class file
52      * @throws IOException if the file cannot be read
53      */

54     public RepositoryClassParser(String JavaDoc fileName) throws IOException JavaDoc {
55         classParser = new ClassParser(fileName);
56     }
57
58     /**
59      * Constructor.
60      *
61      * @param zipFile name of a zip file containing the class
62      * @param fileName name of the zip entry within the class
63      * @throws IOException if the zip entry cannot be read
64      */

65     public RepositoryClassParser(String JavaDoc zipFile, String JavaDoc fileName) throws IOException JavaDoc {
66         classParser = new ClassParser(zipFile, fileName);
67     }
68
69     /**
70      * Parse the class file into a JavaClass object.
71      * If succesful, the new JavaClass is entered into the Repository.
72      *
73      * @return the parsed JavaClass
74      * @throws IOException if the class cannot be parsed
75      */

76     public JavaClass parse() throws IOException JavaDoc {
77         JavaClass jclass = classParser.parse();
78         Repository.addClass(jclass);
79         return jclass;
80     }
81 }
82
83 // vim:ts=4
84
Popular Tags