001: /*
002: * @(#)ClassLoader.java 1.2 06/11/07
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 components;
029:
030: import jcc.Util;
031: import jcc.Str2ID;
032: import consts.Const;
033: import util.*;
034:
035: import java.util.Enumeration;
036: import java.util.Hashtable;
037: import java.util.Set;
038: import java.util.Vector;
039:
040: /*
041: *
042: */
043:
044: public class ClassLoader {
045: String name;
046: ClassLoader parent;
047: Hashtable classes;
048: static int currentID;
049: int id;
050:
051: public ClassLoader(String n, ClassLoader p) {
052: id = currentID++;
053: name = n;
054: parent = p;
055: classes = new Hashtable();
056: }
057:
058: public ClassInfo lookupClass(String key) {
059: ClassInfo ci = null;
060: if (parent != null) {
061: ci = parent.lookupClass(key);
062: }
063: if (ci == null) {
064: ci = (ClassInfo) classes.get(key);
065: }
066: return ci;
067: }
068:
069: boolean enterClass(ClassInfo c) {
070: String className = c.className;
071: c.loader = this ;
072: // check to see if a class of this name is already there...
073: if (classes.containsKey(className)) {
074: System.err.println(Localizer.getString(
075: "classtable.class_table_already_contains",
076: className));
077: return false;
078: }
079: classes.put(className, c);
080: return true;
081: }
082:
083: public String getName() {
084: return name;
085: }
086:
087: public int getID() {
088: return id;
089: }
090:
091: public ClassLoader getParent() {
092: return parent;
093: }
094:
095: private ClassFileFinder searchPath;
096:
097: public void setSearchPath(ClassFileFinder sp) {
098: searchPath = sp;
099: }
100:
101: public ClassFileFinder getSearchPath() {
102: return searchPath;
103: }
104:
105: public String toString() {
106: return super .toString() + " name " + name;
107: }
108:
109: }
|