Package com.sun.ejb.codegen
Class ClassGenerator
java.lang.Object
com.sun.ejb.codegen.ClassGenerator
This class serves to generate classes, because ...
MethodHandles.Lookup class restricts the generated class to use
an already existing class as a source of the package and ProtectionDomain.
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 ClassesModifier and TypeClassDescriptionstatic classThe class wasn't generated. -
Method Summary
Modifier and TypeMethodDescriptionstatic Class<?> defineClass(Class<?> anchorClass, String className, byte[] classData) Calls theMethodHandles.Lookup's defineClass method to create a new class.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.static Class<?> defineClass(ClassLoader loader, String className, byte[] classData) Calls theClassLoader's protected defineClass method to create a new class.static Class<?> defineClass(ClassLoader loader, String className, byte[] classData, int offset, int length) Calls theClassLoader's protected defineClass method to create a new class.static Class<?> defineClass(ClassLoader loader, String className, byte[] classData, int offset, int length, ProtectionDomain protectionDomain) Calls theClassLoader's protected defineClass method to create a new class.static Class<?> defineClass(ClassLoader loader, String className, byte[] classData, ProtectionDomain protectionDomain) Calls theClassLoader's protected defineClass method to create a new class.
-
Method Details
-
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
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
-