use of org.datanucleus.enhancer.ClassEnhancerImpl in project datanucleus-core by datanucleus.
the class ImplementationGenerator method enhance.
/**
* Enhance the implementation of the class/interface.
* @param clr ClassLoader resolver
*/
public void enhance(final ClassLoaderResolver clr) {
// define the generated class in the classloader so we populate the metadata
final EnhancerClassLoader loader = new EnhancerClassLoader();
loader.defineClass(fullClassName, getBytes(), clr);
// Create MetaData for implementation of interface
final ClassLoaderResolver genclr = new ClassLoaderResolverImpl(loader);
final ClassMetaData implementationCmd;
if (inputCmd instanceof InterfaceMetaData) {
implementationCmd = new ClassMetaData((InterfaceMetaData) inputCmd, className, true);
} else {
implementationCmd = new ClassMetaData((ClassMetaData) inputCmd, className);
}
// Do as PrivilegedAction since populate()/initialise() use reflection to get additional fields
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
implementationCmd.populate(genclr, null, metaDataMgr);
implementationCmd.initialise(genclr);
return null;
}
});
// enhance the class and update the byte definition
ClassEnhancer gen = new ClassEnhancerImpl(implementationCmd, genclr, metaDataMgr, JDOEnhancementNamer.getInstance(), getBytes());
gen.enhance();
bytes = gen.getClassBytes();
}
Aggregations