Browse Source

put back callback to ClassPool.writeAsClass. This callback to ClassPool instance

is required to be able to override how dynamic class creation works


git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@91 30ef5769-5b8d-40dd-aea6-55b5d6557bb3
tags/rel_3_17_1_ga
patriot1burke 20 years ago
parent
commit
3fb5f5033c
2 changed files with 25 additions and 16 deletions
  1. 24
    15
      src/main/javassist/ClassPool.java
  2. 1
    1
      src/main/javassist/CtClass.java

+ 24
- 15
src/main/javassist/ClassPool.java View File

@@ -260,21 +260,30 @@ public class ClassPool {
return classLoader.loadClass(name);
}

static Class loadClass(String classname, byte[] classfile)
throws NotFoundException, IOException, CannotCompileException
{
if (classLoader == null)
classLoader = new SimpleLoader();

try {
return classLoader.loadClass(classname, classfile);
}
catch (ClassFormatError e) {
throw new CannotCompileException(e, classname);
}
}

/**
/**
* Callback to write the class and create a Class object
* ClassPool can be extended to override this behavior
* @param classname
* @param classfile
* @return
* @throws NotFoundException
* @throws IOException
* @throws CannotCompileException
*/
public Class writeAsClass(String classname, byte[] classfile)
throws CannotCompileException
{
try {
if (classLoader == null)
classLoader = new SimpleLoader();
return classLoader.loadClass(classname, classfile);
}
catch (ClassFormatError e) {
throw new CannotCompileException(e, classname);
}
}

/**
* Reads a class file and constructs a <code>CtClass</code>
* object with a new name.
* This method is useful if you want to generate a new class as a copy

+ 1
- 1
src/main/javassist/CtClass.java View File

@@ -849,7 +849,7 @@ public abstract class CtClass {
public Class toClass()
throws NotFoundException, IOException, CannotCompileException
{
return ClassPool.loadClass(getName(), toBytecode());
return getClassPool().writeAsClass(getName(), toBytecode());
}

/**

Loading…
Cancel
Save