1 4 package com.tc.object.loaders; 5 6 7 import com.tc.asm.ClassAdapter; 8 import com.tc.asm.ClassVisitor; 9 import com.tc.asm.MethodVisitor; 10 import com.tc.asm.Opcodes; 11 import com.tc.object.bytecode.ByteCodeUtil; 12 13 16 public class StandardClassLoaderAdapter extends ClassAdapter implements Opcodes { 17 18 private final String loaderName; 19 20 public StandardClassLoaderAdapter(ClassVisitor cv, String loaderName) { 21 super(cv); 22 this.loaderName = loaderName; 23 } 24 25 public void visit(int version, int access, String name, String signature, String superName, String [] interfaces) { 26 interfaces = ByteCodeUtil.addInterfaces(interfaces, new String [] { NamedClassLoader.CLASS }); 27 super.visit(version, access, name, signature, superName, interfaces); 28 } 29 30 public void visitEnd() { 31 addNamedClassLoaderMethods(); 32 super.visitEnd(); 33 } 34 35 private void addNamedClassLoaderMethods() { 36 MethodVisitor mv = super.visitMethod(ACC_PUBLIC | ACC_FINAL | ACC_SYNTHETIC, "__tc_getClassLoaderName", 37 "()Ljava/lang/String;", null, null); 38 mv.visitCode(); 39 mv.visitLdcInsn(loaderName); 40 mv.visitInsn(ARETURN); 41 mv.visitMaxs(0, 0); 42 mv.visitEnd(); 43 44 mv = super.visitMethod(ACC_PUBLIC | ACC_FINAL | ACC_SYNTHETIC, "__tc_setClassLoaderName", "(Ljava/lang/String;)V", 45 null, null); 46 mv.visitCode(); 47 mv.visitTypeInsn(NEW, "java/lang/AssertionError"); 48 mv.visitInsn(DUP); 49 mv.visitMethodInsn(INVOKESPECIAL, "java/lang/AssertionError", "<init>", "()V"); 50 mv.visitInsn(ATHROW); 51 mv.visitMaxs(0, 0); 52 mv.visitEnd(); 53 } 54 55 } 56 | Popular Tags |