static <T> T createProxy(Class<T> cls, ClassLoader loader, InvocationHandler handler) { return cls.cast(ProxyHelper.getProxy(loader == null ? cls.getClassLoader() : loader, new Class[]{Client.class, InvocationHandlerAware.class, cls}, handler)); }
public static Object getProxy(ClassLoader loader, Class<?>[] interfaces, InvocationHandler handler) { return HELPER.getProxyInternal(loader, interfaces, handler); } }
protected Object getProxyInternal(ClassLoader loader, Class<?>[] interfaces, InvocationHandler handler) { ClassLoader combinedLoader = getClassLoaderForInterfaces(loader, interfaces); return Proxy.newProxyInstance(combinedLoader, interfaces, handler); }
if (canSeeAllInterfaces(loader, interfaces)) { LOG.log(Level.FINE, "current classloader " + loader + " can see all interface"); return loader; String sortedNameFromInterfaceArray = getSortedNameFromInterfaceArray(interfaces); ClassLoader cachedLoader = proxyClassLoaderCache.getProxyClassLoader(loader, interfaces); if (canSeeAllInterfaces(cachedLoader, interfaces)) { LOG.log(Level.FINE, "find required loader from ProxyClassLoader cache with key" + sortedNameFromInterfaceArray);
/** * Return a classloader that can see all the given interfaces If the given loader can see all interfaces * then it is used. If not then a combined classloader of all interface classloaders is returned. * * @param loader use supplied class loader * @param interfaces * @return classloader that sees all interfaces */ private ClassLoader getClassLoaderForInterfaces(ClassLoader loader, Class<?>[] interfaces) { if (canSeeAllInterfaces(loader, interfaces)) { return loader; } ProxyClassLoader combined = new ProxyClassLoader(loader, interfaces); for (Class<?> currentInterface : interfaces) { combined.addLoader(currentInterface.getClassLoader()); } return combined; }
if (canSeeAllInterfaces(loader, interfaces)) { LOG.log(Level.FINE, "current classloader " + loader + " can see all interface"); return loader; String sortedNameFromInterfaceArray = getSortedNameFromInterfaceArray(interfaces); ClassLoader cachedLoader = proxyClassLoaderCache.getProxyClassLoader(loader, interfaces); if (canSeeAllInterfaces(cachedLoader, interfaces)) { LOG.log(Level.FINE, "find required loader from ProxyClassLoader cache with key" + sortedNameFromInterfaceArray);
/** * Return a classloader that can see all the given interfaces If the given loader can see all interfaces * then it is used. If not then a combined classloader of all interface classloaders is returned. * * @param loader use supplied class loader * @param interfaces * @return classloader that sees all interfaces */ private ClassLoader getClassLoaderForInterfaces(ClassLoader loader, Class<?>[] interfaces) { if (canSeeAllInterfaces(loader, interfaces)) { return loader; } ProxyClassLoader combined = new ProxyClassLoader(loader, interfaces); for (Class<?> currentInterface : interfaces) { combined.addLoader(currentInterface.getClassLoader()); } return combined; }
static <T> T createProxy(Class<T> cls, ClassLoader loader, InvocationHandler handler) { return cls.cast(ProxyHelper.getProxy(loader == null ? cls.getClassLoader() : loader, new Class[]{Client.class, cls}, handler)); }
public static Object getProxy(ClassLoader loader, Class<?>[] interfaces, InvocationHandler handler) { return HELPER.getProxyInternal(loader, interfaces, handler); }
protected Object getProxyInternal(ClassLoader loader, Class<?>[] interfaces, InvocationHandler handler) { ClassLoader combinedLoader = getClassLoaderForInterfaces(loader, interfaces); return Proxy.newProxyInstance(combinedLoader, interfaces, handler); }
static <T> T createProxy(Class<T> cls, ClassLoader loader, InvocationHandler handler) { return cls.cast(ProxyHelper.getProxy(loader == null ? cls.getClassLoader() : loader, new Class[]{Client.class, InvocationHandlerAware.class, cls}, handler)); }
public static Object getProxy(ClassLoader loader, Class<?>[] interfaces, InvocationHandler handler) { return HELPER.getProxyInternal(loader, interfaces, handler); } }
protected Object getProxyInternal(ClassLoader loader, Class<?>[] interfaces, InvocationHandler handler) { ClassLoader combinedLoader = getClassLoaderForInterfaces(loader, interfaces); return Proxy.newProxyInstance(combinedLoader, interfaces, handler); }
private Book createCglibProxy(final Book book) { final InvocationHandler handler = new InvocationHandler() { public Object invoke(Object object, Method method, Object[] args) throws Throwable { return method.invoke(book, args); } }; return (Book)ProxyHelper.getProxy(this.getClass().getClassLoader(), new Class[]{Book.class}, handler); }
public static Object getProxy(ClassLoader loader, Class<?>[] interfaces, InvocationHandler handler) { return HELPER.getProxyInternal(loader, interfaces, handler); }
protected Object getProxyInternal(ClassLoader loader, Class<?>[] interfaces, InvocationHandler handler) { ClassLoader combinedLoader = getClassLoaderForInterfaces(loader, interfaces); return Proxy.newProxyInstance(combinedLoader, interfaces, handler); }
private static Object createEscapeHandler(Class<?> cls, String simpleClassName) { try { String postFix = getPostfix(cls); if (postFix == null) { LOG.log(Level.WARNING, "Failed to create" + simpleClassName + " for unknown jaxb class:" + cls); return null; } Class<?> handlerClass = ClassLoaderUtils.loadClass("com.sun.xml" + postFix + ".bind.marshaller." + simpleClassName, cls); Class<?> handlerInterface = ClassLoaderUtils .loadClass("com.sun.xml" + postFix + ".bind.marshaller.CharacterEscapeHandler", cls); Object targetHandler = ReflectionUtil.getDeclaredField(handlerClass, "theInstance").get(null); return ProxyHelper.getProxy(cls.getClassLoader(), new Class[] {handlerInterface}, new EscapeHandlerInvocationHandler(targetHandler)); } catch (Exception e) { if ("NoEscapeHandler".equals(simpleClassName)) { //this class doesn't exist in JAXB 2.2 so expected LOG.log(Level.FINER, "Failed to create " + simpleClassName); } else { LOG.log(Level.INFO, "Failed to create " + simpleClassName); } } return null; }
public static Object getProxy(ClassLoader loader, Class[] interfaces, InvocationHandler handler) { return HELPER.getProxyInternal(loader, interfaces, handler); } }
private static Object createEscapeHandler(Class<?> cls, String simpleClassName) { try { String postFix = getPostfix(cls); if (postFix == null) { LOG.log(Level.WARNING, "Failed to create" + simpleClassName + " for unknown jaxb class:" + cls); return null; } Class<?> handlerClass = ClassLoaderUtils.loadClass("com.sun.xml" + postFix + ".bind.marshaller." + simpleClassName, cls); Class<?> handlerInterface = ClassLoaderUtils .loadClass("com.sun.xml" + postFix + ".bind.marshaller.CharacterEscapeHandler", cls); Object targetHandler = ReflectionUtil.getDeclaredField(handlerClass, "theInstance").get(null); return ProxyHelper.getProxy(cls.getClassLoader(), new Class[] {handlerInterface}, new EscapeHandlerInvocationHandler(targetHandler)); } catch (Exception e) { if ("NoEscapeHandler".equals(simpleClassName)) { //this class doesn't exist in JAXB 2.2 so expected LOG.log(Level.FINER, "Failed to create " + simpleClassName); } else { LOG.log(Level.INFO, "Failed to create " + simpleClassName); } } return null; }
return enhancer.create(); } else { return super.getProxyInternal(loader, interfaces, h);