1 package org.pojomatic.internal; 2 3 import java.security.AccessController; 4 import java.security.PrivilegedAction; 5 6 public class ClassLoaderClassDefiner implements ClassDefiner { 7 8 private static final class DynamicClassLoader extends ClassLoader { 9 private DynamicClassLoader(ClassLoader parent) { 10 super(parent); 11 } 12 13 Class<?> loadClass(String name, byte[] classBytes) { 14 return defineClass(name, classBytes, 0, classBytes.length); 15 } 16 } 17 18 private DynamicClassLoader classLoader = AccessController.doPrivileged( 19 new PrivilegedAction<DynamicClassLoader>() { 20 @Override 21 public DynamicClassLoader run() { 22 return new DynamicClassLoader(PojomatorFactory.class.getClassLoader()); 23 } 24 }); 25 26 27 @Override 28 public Class<?> defineClass(String className, byte[] classBytes) { 29 return classLoader.loadClass(className, classBytes); 30 } 31 }