Package com.sun.ejb.codegen
Class ClassGenerator
- java.lang.Object
-
- com.sun.ejb.codegen.ClassGenerator
-
public final class ClassGenerator extends Object
This class serves to generate classes, because ...MethodHandles.Lookupclass restricts the generated class to use an already existing class as a source of the package andProtectionDomain.Proxy.newProxyInstance(ClassLoader, Class[], java.lang.reflect.InvocationHandler)has another requirements, ie. all referred classes must be loadable by used classloader.- Author:
- David Matejcek
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classClassGenerator.ClassDefinitionExceptionThe class wasn't generated.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Class<?>defineClass(Class<?> anchorClass, String className, byte[] classData)Calls theMethodHandles.Lookup's defineClass method to create a new classstatic Class<?>defineClass(ClassLoader loader, Class<?> anchorClass, String targetPackageName, String className, byte[] classData)Decides which method is suitable to define the new class and then uses it.static Class<?>defineClass(ClassLoader loader, String className, byte[] classData)Calls theClassLoader's protected defineClass method to create a new classstatic Class<?>defineClass(ClassLoader loader, String className, byte[] classData, int offset, int length)Calls theClassLoader's protected defineClass method to create a new classstatic Class<?>defineClass(ClassLoader loader, String className, byte[] classData, int offset, int length, ProtectionDomain protectionDomain)Calls theClassLoader's protected defineClass method to create a new classstatic Class<?>defineClass(ClassLoader loader, String className, byte[] classData, ProtectionDomain protectionDomain)Calls theClassLoader's protected defineClass method to create a new class
-
-
-
Method Detail
-
defineClass
public static Class<?> defineClass(ClassLoader loader, Class<?> anchorClass, String targetPackageName, String className, byte[] classData)
Decides which method is suitable to define the new class and then uses it.- Parameters:
loader- the classloader instance used to generate the classanchorClass- the class used as an "orientation" class. See theMethodHandles.Lookupclass for more info.targetPackageName- the name is used in decision logic; if the anchor class is from a different package, theMethodHandles.Lookup's method is not usable.className- expected binary name or nullclassData- the valid bytes that make up the class data.- Returns:
- the new generated class
- Throws:
ClassGenerator.ClassDefinitionException- invalid data, missing dependency, or another error related to the class generation
-
defineClass
public static Class<?> defineClass(Class<?> anchorClass, String className, byte[] classData)
Calls theMethodHandles.Lookup's defineClass method to create a new class- Parameters:
anchorClass- the class used as an "orientation" class. See theMethodHandles.Lookupclass for more info.className- expected binary name or nullclassData- the valid bytes that make up the class data.- Returns:
- the new generated class
- Throws:
ClassGenerator.ClassDefinitionException- invalid data, missing dependency, or another error related to the class generation
-
defineClass
public static Class<?> defineClass(ClassLoader loader, String className, byte[] classData) throws ClassGenerator.ClassDefinitionException
Calls theClassLoader's protected defineClass method to create a new class- Parameters:
loader- the classloader instance used to generate the classclassName- expected binary name or nullclassData- the valid bytes that make up the class data.- Returns:
- the new generated class
- Throws:
ClassGenerator.ClassDefinitionException- invalid data, missing dependency, or another error related to the class generation
-
defineClass
public static Class<?> defineClass(ClassLoader loader, String className, byte[] classData, int offset, int length) throws ClassGenerator.ClassDefinitionException
Calls theClassLoader's protected defineClass method to create a new class- Parameters:
loader- the classloader instance used to generate the classclassName- expected binary name or nullclassData- the valid bytes that make up the class data.offset- The start offset inbof the class datalength- The length of the class data- Returns:
- the new generated class
- Throws:
ClassGenerator.ClassDefinitionException- invalid data, missing dependency, or another error related to the class generation
-
defineClass
public static Class<?> defineClass(ClassLoader loader, String className, byte[] classData, ProtectionDomain protectionDomain) throws ClassGenerator.ClassDefinitionException
Calls theClassLoader's protected defineClass method to create a new class- Parameters:
loader- the classloader instance used to generate the classclassName- expected binary name or nullclassData- the valid bytes that make up the class data.protectionDomain- TheProtectionDomainof the class- Returns:
- the new generated class
- Throws:
ClassGenerator.ClassDefinitionException- invalid data, missing dependency, or another error related to the class generation
-
defineClass
public static Class<?> defineClass(ClassLoader loader, String className, byte[] classData, int offset, int length, ProtectionDomain protectionDomain) throws ClassGenerator.ClassDefinitionException
Calls theClassLoader's protected defineClass method to create a new class- Parameters:
loader- the classloader instance used to generate the classclassName- expected binary name or nullclassData- the valid bytes that make up the class data.offset- The start offset inbof the class datalength- The length of the class dataprotectionDomain- TheProtectionDomainof the class- Returns:
- the new generated class
- Throws:
ClassGenerator.ClassDefinitionException- invalid data, missing dependency, or another error related to the class generation
-
-