/** Writes the class file to the classpath and returns a class object */ public Class<?> saveClass() { ClassFile classFile = ctClass.getClassFile(); try { if (!extraClassPath.exists()) { extraClassPath.mkdirs(); } FactoryHelper.writeFile(classFile, extraClassPath.getPath()); ClassLoader loader = getClass().getClassLoader(); Class<?> cls = FactoryHelper.toClass(classFile, loader); return cls; // load class } catch (Exception e) { throw new RuntimeException(e); } }
private void addUnwrapper(Bytecode code, Class type) { final int index = FactoryHelper.typeIndex( type ); final String wrapperType = FactoryHelper.wrapperTypes[index]; // checkcast code.addCheckcast( wrapperType ); // invokevirtual code.addInvokevirtual( wrapperType, FactoryHelper.unwarpMethods[index], FactoryHelper.unwrapDesc[index] ); }
byte[] b = toBytecode(cf); Method method; Object[] args; return toClass2(method, loader, args);
/** * Loads a class file by a given class loader. * This method uses a default protection domain for the class * but it may not work with a security manager or a sigend jar file. * * @see #toClass(ClassFile,ClassLoader,ProtectionDomain) */ public static Class toClass(ClassFile cf, ClassLoader loader) throws CannotCompileException { return toClass(cf, loader, null); }
/** * Writes a class file. */ public static void writeFile(ClassFile cf, String directoryName) throws CannotCompileException { try { writeFile0(cf, directoryName); } catch (IOException e) { throw new CannotCompileException(e); } }
/** * Loads a class file by a given lookup. * * @param lookup used to define the class. * @since 3.24 */ public static Class<?> toClass(ClassFile cf, java.lang.invoke.MethodHandles.Lookup lookup) throws CannotCompileException { try { byte[] b = toBytecode(cf); return DefineClassHelper.toClass(lookup, b); } catch (IOException e) { throw new CannotCompileException(e); } }
/** * Loads a class file by a given class loader. * This method uses a default protection domain for the class * but it may not work with a security manager or a signed jar file. * * @see #toClass(ClassFile,Class,ClassLoader,ProtectionDomain) * @deprecated */ public static Class<?> toClass(ClassFile cf, ClassLoader loader) throws CannotCompileException { return toClass(cf, null, loader, null); }
/** * Writes a class file. */ public static void writeFile(ClassFile cf, String directoryName) throws CannotCompileException { try { writeFile0(cf, directoryName); } catch (IOException e) { throw new CannotCompileException(e); } }
/** * Loads a class file by a given class loader. * * @param neighbor a class belonging to the same package that * the loaded class belongs to. * It can be null. * @param loader The class loader. It can be null if {@code neighbor} * is not null. * @param domain if it is null, a default domain is used. * @since 3.3 */ public static Class<?> toClass(ClassFile cf, Class<?> neighbor, ClassLoader loader, ProtectionDomain domain) throws CannotCompileException { try { byte[] b = toBytecode(cf); if (ProxyFactory.onlyPublicMethods) return DefineClassHelper.toPublicClass(cf.getName(), b); else return DefineClassHelper.toClass(cf.getName(), neighbor, loader, domain, b); } catch (IOException e) { throw new CannotCompileException(e); } }
private void createClass3(ClassLoader cl) { // we need a new class so we need a new class name allocateClassName(); try { ClassFile cf = make(); if (writeDirectory != null) FactoryHelper.writeFile(cf, writeDirectory); thisClass = FactoryHelper.toClass(cf, cl, getDomain()); setField(FILTER_SIGNATURE_FIELD, signature); // legacy behaviour : we only set the default interceptor static field if we are not using the cache if (!factoryUseCache) { setField(DEFAULT_INTERCEPTOR, handler); } } catch (CannotCompileException e) { throw new RuntimeException(e.getMessage(), e); } }
private static void addUnwrapper(Bytecode code, Class type) { if (type.isPrimitive()) { if (type == Void.TYPE) code.addOpcode(Opcode.POP); else { int index = FactoryHelper.typeIndex(type); String wrapper = FactoryHelper.wrapperTypes[index]; code.addCheckcast(wrapper); code.addInvokevirtual(wrapper, FactoryHelper.unwarpMethods[index], FactoryHelper.unwrapDesc[index]); } } else code.addCheckcast(type.getName()); }
/** * Loads a class file by a given class loader. * This method uses a default protection domain for the class * but it may not work with a security manager or a sigend jar file. * * @see #toClass(ClassFile,ClassLoader,ProtectionDomain) */ public static Class toClass(ClassFile cf, ClassLoader loader) throws CannotCompileException { return toClass(cf, loader, null); }
byte[] b = toBytecode(cf); Method method; Object[] args; return toClass2(method, loader, args);
/** * Writes a class file. */ public static void writeFile(ClassFile cf, String directoryName) throws CannotCompileException { try { writeFile0(cf, directoryName); } catch (IOException e) { throw new CannotCompileException(e); } }
BulkAccessor create() { final Method[] getters = new Method[getterNames.length]; final Method[] setters = new Method[setterNames.length]; findAccessors( targetBean, getterNames, setterNames, types, getters, setters ); final Class beanClass; try { final ClassFile classfile = make( getters, setters ); final ClassLoader loader = this.getClassLoader(); if ( writeDirectory != null ) { FactoryHelper.writeFile( classfile, writeDirectory ); } beanClass = FactoryHelper.toClass( classfile, null, loader, getDomain() ); return (BulkAccessor) this.newInstance( beanClass ); } catch ( Exception e ) { throw new BulkAccessorException( e.getMessage(), e ); } }
private static int makeWrapper(Bytecode code, Class type, int regno) { int index = FactoryHelper.typeIndex(type); String wrapper = FactoryHelper.wrapperTypes[index]; code.addNew(wrapper); code.addOpcode(Opcode.DUP); addLoad(code, regno, type); code.addInvokespecial(wrapper, "<init>", FactoryHelper.wrapperDesc[index]); return regno + FactoryHelper.dataSize[index]; }
/** * Loads a class file by a given class loader. * This method uses a default protection domain for the class * but it may not work with a security manager or a sigend jar file. * * @see #toClass(ClassFile,ClassLoader,ProtectionDomain) */ public static Class toClass(ClassFile cf, ClassLoader loader) throws CannotCompileException { return toClass(cf, loader, null); }
byte[] b = toBytecode(cf); Method method; Object[] args; return toClass2(method, loader, args);
/** * Writes a class file. */ public static void writeFile(ClassFile cf, String directoryName) throws CannotCompileException { try { writeFile0(cf, directoryName); } catch (IOException e) { throw new CannotCompileException(e); } }
private void createClass3(ClassLoader cl, Lookup lookup) { // we need a new class so we need a new class name allocateClassName(); try { ClassFile cf = make(); if (writeDirectory != null) FactoryHelper.writeFile(cf, writeDirectory); if (lookup == null) thisClass = FactoryHelper.toClass(cf, getClassInTheSamePackage(), cl, getDomain()); else thisClass = FactoryHelper.toClass(cf, lookup); setField(FILTER_SIGNATURE_FIELD, signature); // legacy behaviour : we only set the default interceptor static field if we are not using the cache if (!factoryUseCache) { setField(DEFAULT_INTERCEPTOR, handler); } } catch (CannotCompileException e) { throw new RuntimeException(e.getMessage(), e); } }