KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > myoodb > core > ClassLoader


1 ///////////////////////////////////////////////////////////////////////////////
2
//
3
// Copyright (C) 2003-@year@ by Thomas M. Hazel, MyOODB (www.myoodb.org)
4
//
5
// All Rights Reserved
6
//
7
// This program is free software; you can redistribute it and/or modify
8
// it under the terms of the GNU General Public License and GNU Library
9
// 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 import java.io.*;
27 import java.util.*;
28
29 public final class ClassLoader extends java.lang.ClassLoader JavaDoc
30 {
31     private HashMap m_classTable;
32
33     public ClassLoader()
34     {
35         flushCache();
36     }
37
38     protected void flushCache()
39     {
40         m_classTable = new HashMap(100);
41     }
42
43     protected Class JavaDoc loadClass(String JavaDoc name, boolean resolve) throws ClassNotFoundException JavaDoc
44     {
45         if (name.startsWith("java"))
46         {
47             return getSystemClassLoader().loadClass(name);
48         }
49         else
50         {
51             Class JavaDoc classType = (Class JavaDoc) m_classTable.get(name);
52
53             if (classType == null)
54             {
55                 classType = primitiveType(name);
56                 if (classType == null)
57                 {
58                     classType = Thread.currentThread().getContextClassLoader().loadClass(name);
59                 }
60
61                 m_classTable.put(name, classType);
62             }
63
64             return classType;
65         }
66     }
67
68     protected static Class JavaDoc primitiveType(String JavaDoc name)
69     {
70         if (name.equals("int"))
71         {
72             return Integer.TYPE;
73         }
74         else if (name.equals("char"))
75         {
76             return Character.TYPE;
77         }
78         else if (name.equals("byte"))
79         {
80             return Byte.TYPE;
81         }
82         else if (name.equals("double"))
83         {
84             return Double.TYPE;
85         }
86         else if (name.equals("float"))
87         {
88             return Float.TYPE;
89         }
90         else if (name.equals("long"))
91         {
92             return Long.TYPE;
93         }
94         else if (name.equals("short"))
95         {
96             return Short.TYPE;
97         }
98         else if (name.equals("boolean"))
99         {
100             return Boolean.TYPE;
101         }
102         else
103         {
104             return null;
105         }
106     }
107
108     public Class JavaDoc loadClass(String JavaDoc name) throws ClassNotFoundException JavaDoc
109     {
110         return loadClass(name, false);
111     }
112 }
113
Popular Tags