001: /*
002: * @(#)ClassDictionary.java 1.14 06/10/10
003: *
004: * Copyright 1990-2006 Sun Microsystems, Inc. All Rights Reserved.
005: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License version
009: * 2 only, as published by the Free Software Foundation.
010: *
011: * This program is distributed in the hope that it will be useful, but
012: * WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * General Public License version 2 for more details (a copy is
015: * included at /legal/license.txt).
016: *
017: * You should have received a copy of the GNU General Public License
018: * version 2 along with this work; if not, write to the Free Software
019: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA
021: *
022: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023: * Clara, CA 95054 or visit www.sun.com if you need additional
024: * information or have any questions.
025: *
026: */
027:
028: package dependenceAnalyzer;
029:
030: import util.*;
031: import java.io.FilenameFilter;
032: import java.util.*;
033: import java.io.InputStream;
034: import components.ClassInfo;
035:
036: /*
037: * A ClassDictionary is used by the dependence analyser
038: * to encapsulate all class name lookup operations. Thus
039: * it contains both a hash table and a ClassFileFinder,
040: * to lookup, respectively, classes we've already read, and
041: * those not yet read. We have also bundled in a FilenameFilter,
042: * to know when a class should be excluded rather than found
043: * and read in.
044: *
045: * Note that this is not a public class: it is only for use
046: * within the dependenceAnalyzer package.
047: */
048:
049: class ClassDictionary {
050: /*
051: * public interfaces.
052: */
053:
054: public ClassDictionary(ClassFileFinder find, FilenameFilter filt) {
055: finder = find;
056: filter = filt;
057: cdict = new Hashtable();
058: }
059:
060: public ClassEntry lookup(String cname) {
061: return (ClassEntry) (cdict.get(cname));
062: }
063:
064: public ClassEntry lookupAdd(String cname) {
065: ClassEntry ce = (ClassEntry) (cdict.get(cname));
066: if (ce == null) {
067: ce = new ClassEntry(cname);
068: if (filter.accept(null, cname)) {
069: ce.flags |= ClassEntry.EXCLUDED;
070: }
071: cdict.put(cname, ce);
072: }
073: return ce;
074: }
075:
076: public Enumeration elements() {
077: return cdict.elements();
078: }
079:
080: /*
081: * and as a public service to ClassEntry...
082: */
083: ClassInfo findClassInfo(String cname) {
084: InputStream fin = finder.findClassFile(cname);
085: if (fin == null)
086: return null;
087: ClassFile f = new ClassFile(cname, fin, false);
088: if (!f.readClassFile()) {
089: f.dump(System.err);
090: return null;
091: }
092: return f.clas;
093: }
094:
095: /*
096: * private state parts.
097: */
098: private ClassFileFinder finder;
099: private FilenameFilter filter;
100: private Hashtable cdict;
101: }
|