/** * Create a composite interface Class for the given interfaces, * implementing the given interfaces in one single Class. * <p>This implementation builds a JDK proxy class for the given interfaces. * @param interfaces the interfaces to merge * @param classLoader the ClassLoader to create the composite Class in * @return the merged interface as Class * @throws IllegalArgumentException if the specified interfaces expose * conflicting method signatures (or a similar constraint is violated) * @see java.lang.reflect.Proxy#getProxyClass */ @SuppressWarnings("deprecation") public static Class<?> createCompositeInterface(Class<?>[] interfaces, @Nullable ClassLoader classLoader) { Assert.notEmpty(interfaces, "Interfaces must not be empty"); return Proxy.getProxyClass(classLoader, interfaces); }
@Override protected Class<?> resolveProxyClass(String[] interfaces) throws IOException, ClassNotFoundException { List<Class<?>> loadedClasses = new ArrayList<Class<?>>(interfaces.length); for (String name : interfaces) { Class<?> clazz = Class.forName(name, false, classLoader); loadedClasses.add(clazz); } return Proxy.getProxyClass(classLoader, loadedClasses.toArray(new Class[loadedClasses.size()])); }
@Override protected Class<?> resolveProxyClass(String[] interfaces) throws IOException, ClassNotFoundException { List<Class<?>> loadedClasses = new ArrayList<Class<?>>(interfaces.length); for (String name : interfaces) { Class<?> clazz = Class.forName(name, false, classLoader); loadedClasses.add(clazz); } return Proxy.getProxyClass(classLoader, loadedClasses.toArray(new Class[loadedClasses.size()])); }
@Override protected Class<?> resolveProxyClass(String[] interfaces) throws ClassNotFoundException { Class<?>[] interfaceClasses = new Class<?>[interfaces.length]; for (int i = 0; i < interfaces.length; i++) { interfaceClasses[i] = Class.forName(interfaces[i], false, classLoader); } return Proxy.getProxyClass(classLoader, interfaceClasses); }
@Override protected Class<?> resolveProxyClass(String[] interfaces) throws ClassNotFoundException { Class<?>[] interfaceClasses = new Class<?>[interfaces.length]; for (int i = 0; i < interfaces.length; i++) { interfaceClasses[i] = Class.forName(interfaces[i], false, classLoader); } return Proxy.getProxyClass(classLoader, interfaceClasses); }
/** * Create a composite interface Class for the given interfaces, * implementing the given interfaces in one single Class. * <p>This implementation builds a JDK proxy class for the given interfaces. * @param interfaces the interfaces to merge * @param classLoader the ClassLoader to create the composite Class in * @return the merged interface as Class * @throws IllegalArgumentException if the specified interfaces expose * conflicting method signatures (or a similar constraint is violated) * @see java.lang.reflect.Proxy#getProxyClass */ @SuppressWarnings("deprecation") public static Class<?> createCompositeInterface(Class<?>[] interfaces, @Nullable ClassLoader classLoader) { Assert.notEmpty(interfaces, "Interfaces must not be empty"); return Proxy.getProxyClass(classLoader, interfaces); }
@SuppressWarnings( "unchecked" ) ProxyFactory( Class<T> type ) throws LinkageError { this.type = type; try { this.constructor = (Constructor<? extends T>) Proxy .getProxyClass( ConsistencyReporter.class.getClassLoader(), type ) .getConstructor( InvocationHandler.class ); instances.put( type, this ); } catch ( NoSuchMethodException e ) { throw new LinkageError( "Cannot access Proxy constructor for " + type.getName(), e ); } }
private static Constructor<?> getProxyConstructor(Class<? extends Object> objectClass, Class<?>[] interfacesArray) { final ClassLoader classLoader = objectClass.getClassLoader(); try { final Constructor<?> constructor = Proxy.getProxyClass(classLoader, interfacesArray) .getConstructor(new Class[] { InvocationHandler.class }); // issue 475: workaround for a j.l.r.Proxy change in Java 8 - proxy class for non-public interface is non-public now. // Ref: https://netbeans.org/bugzilla/show_bug.cgi?id=229191 // and http://hg.netbeans.org/jet-main/rev/3238e03c676f constructor.setAccessible(true); return constructor; } catch (final NoSuchMethodException e) { throw new IllegalStateException(e); } }
private Class<Proxy> getProxyClassForInterface( final Class<?> interfaceType ) { assert interfaceType.isInterface(); Class<Proxy> proxyReturnClass = interfacesToProxyClassesMap.get( interfaceType ); if ( null == proxyReturnClass ) { // Suppressed because we know getProxyClass returns class extending Proxy. @SuppressWarnings("unchecked") Class<Proxy> newProxyReturnClass = (Class<Proxy>) Proxy.getProxyClass( interfaceType.getClassLoader(), new Class[] { interfaceType }); interfacesToProxyClassesMap.put( interfaceType, newProxyReturnClass ); proxyReturnClass = newProxyReturnClass; } return proxyReturnClass; }
/** * Create a proxy class that implements the specified interfaces using * the specified ClassLoader or the super ClassLoader. * * @param interfaces the interfaces to implement * @return a proxy class implementing the interfaces * @throws IOException in case of an I/O error * @throws ClassNotFoundException if the Class cannot be found * @see java.io.ObjectInputStream#resolveProxyClass(java.lang.String[]) * @since 2.1 */ @Override protected Class<?> resolveProxyClass(final String[] interfaces) throws IOException, ClassNotFoundException { final Class<?>[] interfaceClasses = new Class[interfaces.length]; for (int i = 0; i < interfaces.length; i++) { interfaceClasses[i] = Class.forName(interfaces[i], false, classLoader); } try { return Proxy.getProxyClass(classLoader, interfaceClasses); } catch (final IllegalArgumentException e) { return super.resolveProxyClass(interfaces); } }
/** {@inheritDoc} */ public Class<?> cloneProxy(final Class<?> proxyClass) throws IOException, ClassNotFoundException { final Class<?>[] origInterfaces = proxyClass.getInterfaces(); final Class<?>[] interfaces = new Class[origInterfaces.length]; for (int i = 0, origInterfacesLength = origInterfaces.length; i < origInterfacesLength; i++) { interfaces[i] = clone(origInterfaces[i]); } return Proxy.getProxyClass(destClassLoader, interfaces); } }
public Class<?> cloneProxy(final Class<?> proxyClass) throws IOException, ClassNotFoundException { final Class<?>[] origInterfaces = proxyClass.getInterfaces(); final Class<?>[] interfaces = new Class[origInterfaces.length]; for (int i = 0, origInterfacesLength = origInterfaces.length; i < origInterfacesLength; i++) { interfaces[i] = clone(origInterfaces[i]); } return Proxy.getProxyClass(destClassLoader, interfaces); } }
return Proxy.getProxyClass( hasNonPublicInterface ? nonPublicLoader : classLoader, classObjs); } catch (IllegalArgumentException e) {
/** * See {@link Proxy#getProxyClass(ClassLoader, Class...)} */ Class<?> getProxyClass(final Class<?>... classObjs) { IllegalArgumentException ex = null; for (ClassLoader classLoader : this.getClassLoaders()) { try { return Proxy.getProxyClass(classLoader, classObjs); } catch (SecurityException sex) { // Continue to next classloader } catch (IllegalArgumentException iaex) { ex = iaex; // Continue to next classloader } } if (ex != null) { throw ex; } return null; }
public Class<?> resolveProxyClass(final Unmarshaller unmarshaller, final String[] interfaces) throws IOException, ClassNotFoundException { final int length = interfaces.length; final Class<?>[] classes = new Class<?>[length]; for(int i = 0; i < length; ++i) { classes[i] = this.loadClass(interfaces[i]); } final ClassLoader classLoader; if (length == 1) { classLoader = doPrivileged((PrivilegedAction<ClassLoader>) classes[0]::getClassLoader); } else { classLoader = getClassLoader(); } return Proxy.getProxyClass(classLoader, classes); }
@Override protected Class<?> resolveProxyClass(String[] interfaces) throws IOException, ClassNotFoundException { Class<?>[] interfaceClasses = new Class<?>[interfaces.length]; for (int i = 0; i < interfaces.length; i++) { interfaceClasses[i] = Class.forName(interfaces[i], false, classLoader); } return Proxy.getProxyClass(classLoader, interfaceClasses); }
@Override protected Class<?> resolveProxyClass(String[] interfaces) throws IOException, ClassNotFoundException { Class<?>[] interfaceClasses = new Class<?>[interfaces.length]; for (int i = 0; i < interfaces.length; i++) { interfaceClasses[i] = Class.forName(interfaces[i], false, classLoader); } return Proxy.getProxyClass(classLoader, interfaceClasses); }
public Class<?> resolveProxyClass(final Unmarshaller unmarshaller, final String[] interfaces) throws IOException, ClassNotFoundException { final int length = interfaces.length; final Class<?>[] classes = new Class<?>[length]; for (int i = 0; i < length; ++ i) { classes[i] = this.loadClass(interfaces[i]); } final ClassLoader classLoader; if (length == 1) { classLoader = doPrivileged((PrivilegedAction<ClassLoader>) classes[0]::getClassLoader); } else { classLoader = getClassLoader(); } return Proxy.getProxyClass(classLoader, classes); } }
/** * {@inheritDoc} The base implementation uses the class loader returned from {@code getClassLoader()} and loads * each interface by name, returning a proxy class from that class loader. */ public Class<?> resolveProxyClass(final Unmarshaller unmarshaller, final String[] interfaces) throws IOException, ClassNotFoundException { final ClassLoader classLoader = getClassLoader(); final int length = interfaces.length; Class<?>[] classes = new Class<?>[length]; for (int i = 0; i < length; i ++) { classes[i] = loadClass(interfaces[i]); } return Proxy.getProxyClass(classLoader, classes); }
public static Class<?> createCompositeInterface(Class<?>[] interfaces, ClassLoader classLoader) { Assert.notEmpty(interfaces, "Interfaces must not be empty"); Assert.notNull(classLoader, "ClassLoader must not be null"); return Proxy.getProxyClass(classLoader, interfaces); }