org.jboss.weld.util.bytecode
Class ClassFileUtils

java.lang.Object
  extended by org.jboss.weld.util.bytecode.ClassFileUtils

public class ClassFileUtils
extends Object

Utility class for loading a ClassFile into a classloader. This borrows heavily from javassist

Author:
Stuart Douglas

Constructor Summary
ClassFileUtils()
           
 
Method Summary
static byte[] toBytecode(javassist.bytecode.ClassFile file)
           
static Class<?> toClass(javassist.bytecode.ClassFile ct, ClassLoader loader, ProtectionDomain domain)
          Converts the class to a java.lang.Class object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ClassFileUtils

public ClassFileUtils()
Method Detail

toClass

public static Class<?> toClass(javassist.bytecode.ClassFile ct,
                               ClassLoader loader,
                               ProtectionDomain domain)
                        throws javassist.CannotCompileException
Converts the class to a java.lang.Class object. Once this method is called, further modifications are not allowed any more.

The class file represented by the given CtClass is loaded by the given class loader to construct a java.lang.Class object. Since a private method on the class loader is invoked through the reflection API, the caller must have permissions to do that.

An easy way to obtain ProtectionDomain object is to call getProtectionDomain() in java.lang.Class. It returns the domain that the class belongs to.

This method is provided for convenience. If you need more complex functionality, you should write your own class loader.

Parameters:
loader - the class loader used to load this class. For example, the loader returned by getClassLoader() can be used for this parameter.
domain - the protection domain for the class. If it is null, the default domain created by java.lang.ClassLoader is used.
Throws:
javassist.CannotCompileException

toBytecode

public static byte[] toBytecode(javassist.bytecode.ClassFile file)


Copyright © 2013 Seam Framework. All Rights Reserved.