Search in sources :

Example 1 with ClassEnhancerImpl

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();
}
Also used : PrivilegedAction(java.security.PrivilegedAction) ClassLoaderResolver(org.datanucleus.ClassLoaderResolver) InterfaceMetaData(org.datanucleus.metadata.InterfaceMetaData) ClassEnhancerImpl(org.datanucleus.enhancer.ClassEnhancerImpl) AbstractClassMetaData(org.datanucleus.metadata.AbstractClassMetaData) ClassMetaData(org.datanucleus.metadata.ClassMetaData) ClassLoaderResolverImpl(org.datanucleus.ClassLoaderResolverImpl)

Aggregations

PrivilegedAction (java.security.PrivilegedAction)1 ClassLoaderResolver (org.datanucleus.ClassLoaderResolver)1 ClassLoaderResolverImpl (org.datanucleus.ClassLoaderResolverImpl)1 ClassEnhancerImpl (org.datanucleus.enhancer.ClassEnhancerImpl)1 AbstractClassMetaData (org.datanucleus.metadata.AbstractClassMetaData)1 ClassMetaData (org.datanucleus.metadata.ClassMetaData)1 InterfaceMetaData (org.datanucleus.metadata.InterfaceMetaData)1