/** * 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); }
/** * Generates a proxy class using the supplied filter. */ public Class createClass(MethodFilter filter) { computeSignature(filter); return createClass1(); }
/** * Generates a proxy class with a specific signature. * access is package local so ProxyObjectInputStream can use this * @param signature * @return */ Class createClass(byte[] signature) { installSignature(signature); return createClass1(); }
/** * Creates a proxy class and returns an instance of that class. * * @param paramTypes parameter types for a constructor. * @param args arguments passed to a constructor. * @param mh the method handler for the proxy class. * @since 3.4 */ public Object create(Class[] paramTypes, Object[] args, MethodHandler mh) throws NoSuchMethodException, IllegalArgumentException, InstantiationException, IllegalAccessException, InvocationTargetException { Object obj = create(paramTypes, args); ((Proxy)obj).setHandler(mh); return obj; }
/** * Converts a proxy object to an object that is writable to an * object stream. This method is called by <code>writeReplace()</code> * in a proxy class. * * @since 3.4 */ public static SerializedProxy makeSerializedProxy(Object proxy) throws java.io.InvalidClassException { Class clazz = proxy.getClass(); MethodHandler methodHandler = null; if (proxy instanceof ProxyObject) methodHandler = ((ProxyObject)proxy).getHandler(); else if (proxy instanceof Proxy) methodHandler = ProxyFactory.getHandler((Proxy)proxy); return new SerializedProxy(clazz, ProxyFactory.getFilterSignature(clazz), methodHandler); } }
private Class createClass1() { Class result = thisClass; if (result == null) { ClassLoader cl = getClassLoader(); synchronized (proxyCache) { if (factoryUseCache) createClass2(cl); else createClass3(cl); result = thisClass; // don't retain any unwanted references thisClass = null; } } return result; }
private static Method findMethod2(Class clazz, String name, String desc) { Method[] methods = SecurityActions.getDeclaredMethods(clazz); int n = methods.length; for (int i = 0; i < n; i++) if (methods[i].getName().equals(name) && makeDescriptor(methods[i]).equals(desc)) return methods[i]; return null; }
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]; }
/** * Finds a method with the given name and descriptor. * It searches only the class of self. * * @throws RuntimeException if the method is not found. */ public static Method findMethod(Class clazz, String name, String desc) { Method m = findMethod2(clazz, name, desc); if (m == null) error(clazz, name, desc); return m; }
/** * Finds two methods specified by the parameters and stores them * into the given array. * * <p>Added back for JBoss Seam. See JASSIST-206.</p> * * @throws RuntimeException if the methods are not found. * @see javassist.util.proxy.ProxyFactory * @deprecated replaced by {@link #find2Methods(Class, String, String, int, String, Method[])} */ public static void find2Methods(Object self, String superMethod, String thisMethod, int index, String desc, java.lang.reflect.Method[] methods) { methods[index + 1] = thisMethod == null ? null : findMethod(self, thisMethod, desc); methods[index] = findSuperMethod(self, superMethod, desc); }
/** * Finds two methods specified by the parameters and stores them * into the given array. * * @throws RuntimeException if the methods are not found. * @see javassist.util.proxy.ProxyFactory */ public static void find2Methods(Class clazz, String superMethod, String thisMethod, int index, String desc, java.lang.reflect.Method[] methods) { methods[index + 1] = thisMethod == null ? null : findMethod(clazz, thisMethod, desc); methods[index] = findSuperClassMethod(clazz, superMethod, desc); }
protected ClassLoader getClassLoader() { return classLoaderProvider.get(this); }
private static int addLoadParameters(Bytecode code, Class[] params, int offset) { int stacksize = 0; int n = params.length; for (int i = 0; i < n; ++i) stacksize += addLoad(code, stacksize + offset, params[i]); return stacksize; }
public ClassLoader get(ProxyFactory pf) { return pf.getClassLoader0(); } };
private void allocateClassName() { classname = makeProxyName(basename); }
static byte[] getFilterSignature(Class clazz) { return (byte[])getField(clazz, FILTER_SIGNATURE_FIELD); }
private static synchronized Class toClass2(Method method, ClassLoader loader, Object[] args) throws Exception { SecurityActions.setAccessible(method, true); Class clazz = (Class)method.invoke(loader, args); SecurityActions.setAccessible(method, false); return clazz; }
/** * 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 static String makeProxyName(String classname) { synchronized (nameGenerator) { return nameGenerator.get(classname); } }
/** * Generates a proxy class using the current filter. */ public Class createClass() { if (signature == null) { computeSignature(methodFilter); } return createClass1(); }