01: ///////////////////////////////////////////////////////////////////////////////
02: //
03: // Copyright (C) 2003-@year@ by Thomas M. Hazel, MyOODB (www.myoodb.org)
04: //
05: // All Rights Reserved
06: //
07: // This program is free software; you can redistribute it and/or modify
08: // it under the terms of the GNU General Public License and GNU Library
09: // General Public License as published by the Free Software Foundation;
10: // either version 2, or (at your option) any later version.
11: //
12: // This program is distributed in the hope that it will be useful,
13: // but WITHOUT ANY WARRANTY; without even the implied warranty of
14: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15: // GNU General Public License and GNU Library General Public License
16: // for more details.
17: //
18: // You should have received a copy of the GNU General Public License
19: // and GNU Library General Public License along with this program; if
20: // not, write to the Free Software Foundation, 675 Mass Ave, Cambridge,
21: // MA 02139, USA.
22: //
23: ///////////////////////////////////////////////////////////////////////////////
24: package org.myoodb.core;
25:
26: // TODO: had problems with java 1.6, for now do not extend java.lang.ClassLoader
27: public final class ClassLoader {
28: private java.util.concurrent.ConcurrentHashMap m_classTable;
29:
30: protected static Class primitiveType(String name) {
31: if (name.equals("int")) {
32: return Integer.TYPE;
33: } else if (name.equals("char")) {
34: return Character.TYPE;
35: } else if (name.equals("byte")) {
36: return Byte.TYPE;
37: } else if (name.equals("double")) {
38: return Double.TYPE;
39: } else if (name.equals("float")) {
40: return Float.TYPE;
41: } else if (name.equals("long")) {
42: return Long.TYPE;
43: } else if (name.equals("short")) {
44: return Short.TYPE;
45: } else if (name.equals("boolean")) {
46: return Boolean.TYPE;
47: } else {
48: return null;
49: }
50: }
51:
52: public ClassLoader() {
53: m_classTable = new java.util.concurrent.ConcurrentHashMap();
54: }
55:
56: public Class loadClass(String name) throws ClassNotFoundException {
57: Class classType = (Class) m_classTable.get(name);
58: if (classType == null) {
59: classType = primitiveType(name);
60: if (classType == null) {
61: classType = Class.forName(name);
62: }
63:
64: m_classTable.put(name, classType);
65: }
66:
67: return classType;
68: }
69: }
|