01: /*
02: * Copyright 2004,2004 The Apache Software Foundation.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16:
17: package org.apache.bsf.util.event.generator;
18:
19: import java.util.Hashtable;
20:
21: import org.apache.commons.logging.Log;
22: import org.apache.commons.logging.LogFactory;
23:
24: public class AdapterClassLoader extends ClassLoader {
25: private static Hashtable classCache = new Hashtable();
26: private Class c;
27:
28: private Log logger = LogFactory.getLog(this .getClass().getName());
29:
30: public AdapterClassLoader() {
31: super ();
32: }
33:
34: public synchronized Class defineClass(String name, byte[] b) {
35: if ((c = getLoadedClass(name)) == null) {
36: c = defineClass(name.replace('/', '.'), b, 0, b.length); // rgf, 2006-02-03
37: put(name, c);
38: } else {
39: logger.error("AdapterClassLoader: " + c
40: + " previously loaded. Can not redefine class.");
41: }
42:
43: return c;
44: }
45:
46: final protected Class findClass(String name) {
47: return get(name);
48: }
49:
50: final protected Class get(String name) {
51: return (Class) classCache.get(name);
52: }
53:
54: public synchronized Class getLoadedClass(String name) {
55: Class c = findLoadedClass(name);
56:
57: if (c == null) {
58: try {
59: c = findSystemClass(name);
60: } catch (ClassNotFoundException e) {
61: }
62: }
63:
64: if (c == null) {
65: c = findClass(name);
66: }
67:
68: return c;
69: }
70:
71: protected synchronized Class loadClass(String name, boolean resolve)
72: throws ClassNotFoundException {
73: Class c = getLoadedClass(name);
74:
75: if (c != null && resolve) {
76: resolveClass(c);
77: }
78:
79: return c;
80: }
81:
82: // Not in JDK 1.1, only in JDK 1.2.
83: // public AdapterClassLoader(ClassLoader loader)
84: // {
85: // super(loader);
86: // }
87:
88: final protected void put(String name, Class c) {
89: classCache.put(name, c);
90: }
91: }
|