1 7 8 package javax.management.remote.rmi; 9 10 import java.io.ByteArrayOutputStream ; 11 import java.io.DataOutputStream ; 12 import java.security.ProtectionDomain ; 13 14 61 62 class NoCallStackClassLoader extends ClassLoader { 63 64 public NoCallStackClassLoader(String className, 65 byte[] byteCode, 66 String [] referencedClassNames, 67 ClassLoader referencedClassLoader, 68 ProtectionDomain protectionDomain) { 69 this(new String [] {className}, new byte[][] {byteCode}, 70 referencedClassNames, referencedClassLoader, protectionDomain); 71 } 72 73 public NoCallStackClassLoader(String [] classNames, 74 byte[][] byteCodes, 75 String [] referencedClassNames, 76 ClassLoader referencedClassLoader, 77 ProtectionDomain protectionDomain) { 78 super(null); 79 80 81 if (classNames == null || classNames.length == 0 82 || byteCodes == null || classNames.length != byteCodes.length 83 || referencedClassNames == null || protectionDomain == null) 84 throw new IllegalArgumentException (); 85 for (int i = 0; i < classNames.length; i++) { 86 if (classNames[i] == null || byteCodes[i] == null) 87 throw new IllegalArgumentException (); 88 } 89 for (int i = 0; i < referencedClassNames.length; i++) { 90 if (referencedClassNames[i] == null) 91 throw new IllegalArgumentException (); 92 } 93 94 this.classNames = classNames; 95 this.byteCodes = byteCodes; 96 this.referencedClassNames = referencedClassNames; 97 this.referencedClassLoader = referencedClassLoader; 98 this.protectionDomain = protectionDomain; 99 } 100 101 105 protected Class findClass(String name) throws ClassNotFoundException { 106 for (int i = 0; i < classNames.length; i++) { 107 if (name.equals(classNames[i])) { 108 return defineClass(classNames[i], byteCodes[i], 0, 109 byteCodes[i].length, protectionDomain); 110 } 111 } 112 113 117 if (referencedClassLoader != null) { 118 for (int i = 0; i < referencedClassNames.length; i++) { 119 if (name.equals(referencedClassNames[i])) 120 return referencedClassLoader.loadClass(name); 121 } 122 } 123 124 throw new ClassNotFoundException (name); 125 } 126 127 private final String [] classNames; 128 private final byte[][] byteCodes; 129 private final String [] referencedClassNames; 130 private final ClassLoader referencedClassLoader; 131 private final ProtectionDomain protectionDomain; 132 133 157 public static byte[] stringToBytes(String s) { 158 final int slen = s.length(); 159 byte[] bytes = new byte[slen]; 160 for (int i = 0; i < slen; i++) 161 bytes[i] = (byte) s.charAt(i); 162 return bytes; 163 } 164 } 165 166 212 | Popular Tags |