01: /*
02: * Bytecode Analysis Framework
03: * Copyright (C) 2003,2004 University of Maryland
04: *
05: * This library is free software; you can redistribute it and/or
06: * modify it under the terms of the GNU Lesser General Public
07: * License as published by the Free Software Foundation; either
08: * version 2.1 of the License, or (at your option) any later version.
09: *
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;
23: import java.io.InputStream;
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 inputStream,
45: String fileName) {
46: classParser = new ClassParser(inputStream, fileName);
47: }
48:
49: /**
50: * Constructor.
51: *
52: * @param fileName name of the class file
53: * @throws IOException if the file cannot be read
54: */
55: public RepositoryClassParser(String fileName) throws IOException {
56: classParser = new ClassParser(fileName);
57: }
58:
59: /**
60: * Constructor.
61: *
62: * @param zipFile name of a zip file containing the class
63: * @param fileName name of the zip entry within the class
64: * @throws IOException if the zip entry cannot be read
65: */
66: public RepositoryClassParser(String zipFile, String fileName)
67: throws IOException {
68: classParser = new ClassParser(zipFile, fileName);
69: }
70:
71: /**
72: * Parse the class file into a JavaClass object.
73: * If succesful, the new JavaClass is entered into the Repository.
74: *
75: * @return the parsed JavaClass
76: * @throws IOException if the class cannot be parsed
77: */
78: public JavaClass parse() throws IOException {
79: JavaClass jclass = classParser.parse();
80: Repository.addClass(jclass);
81: return jclass;
82: }
83: }
84:
85: // vim:ts=4
|