1 21 22 package org.apache.derby.impl.services.reflect; 23 import org.apache.derby.iapi.util.ByteArray; 24 25 28 29 public final class ReflectClassesJava2 extends DatabaseClasses 30 implements java.security.PrivilegedAction 31 { 32 33 private java.util.HashMap preCompiled; 34 35 private int action = -1; 36 37 synchronized LoadedGeneratedClass loadGeneratedClassFromData(String fullyQualifiedName, ByteArray classDump) { 38 39 if (classDump == null || classDump.getArray() == null) { 40 41 if (preCompiled == null) 42 preCompiled = new java.util.HashMap (); 43 else 44 { 45 ReflectGeneratedClass gc = (ReflectGeneratedClass) preCompiled.get(fullyQualifiedName); 46 if (gc != null) 47 return gc; 48 } 49 50 try { 52 Class jvmClass = Class.forName(fullyQualifiedName); 53 ReflectGeneratedClass gc = new ReflectGeneratedClass(this, jvmClass, null); 54 preCompiled.put(fullyQualifiedName, gc); 55 return gc; 56 } catch (ClassNotFoundException cnfe) { 57 throw new NoClassDefFoundError (cnfe.toString()); 58 } 59 } 60 61 action = 1; 62 return ((ReflectLoaderJava2) java.security.AccessController.doPrivileged(this)).loadGeneratedClass(fullyQualifiedName, classDump); 63 } 64 65 public final Object run() { 66 67 try { 68 switch (action) { 70 case 1: 71 return new ReflectLoaderJava2(getClass().getClassLoader(), this); 72 case 2: 73 return Thread.currentThread().getContextClassLoader(); 74 default: 75 return null; 76 } 77 } finally { 78 action = -1; 79 } 80 81 } 82 83 Class loadClassNotInDatabaseJar(String name) throws ClassNotFoundException { 84 85 Class foundClass = null; 86 87 try { 98 ClassLoader cl; 99 synchronized(this) { 100 action = 2; 101 cl = ((ClassLoader ) 102 java.security.AccessController.doPrivileged(this)); 103 } 104 105 foundClass = (cl != null) ? cl.loadClass(name) 106 :Class.forName(name); 107 } catch (ClassNotFoundException cnfe) { 108 foundClass = Class.forName(name); 109 } 110 return foundClass; 111 } 112 } 113 | Popular Tags |