1 package org.myoodb.core; 25 26 import java.io.*; 27 import java.util.*; 28 29 public final class ClassLoader extends java.lang.ClassLoader 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 loadClass(String name, boolean resolve) throws ClassNotFoundException 44 { 45 if (name.startsWith("java")) 46 { 47 return getSystemClassLoader().loadClass(name); 48 } 49 else 50 { 51 Class classType = (Class ) 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 primitiveType(String 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 loadClass(String name) throws ClassNotFoundException 109 { 110 return loadClass(name, false); 111 } 112 } 113 | Popular Tags |