src/share/classes/java/lang/reflect/Proxy.java

Print this page




 333      *
 334      * @param   loader the class loader to define the proxy class
 335      * @param   interfaces the list of interfaces for the proxy class
 336      *          to implement
 337      * @return  a proxy class that is defined in the specified class loader
 338      *          and that implements the specified interfaces
 339      * @throws  IllegalArgumentException if any of the restrictions on the
 340      *          parameters that may be passed to {@code getProxyClass}
 341      *          are violated
 342      * @throws  NullPointerException if the {@code interfaces} array
 343      *          argument or any of its elements are {@code null}
 344      */
 345     public static Class<?> getProxyClass(ClassLoader loader,
 346                                          Class<?>... interfaces)
 347         throws IllegalArgumentException
 348     {
 349         if (interfaces.length > 65535) {
 350             throw new IllegalArgumentException("interface limit exceeded");
 351         }
 352 
 353         Class proxyClass = null;
 354 
 355         /* collect interface names to use as key for proxy class cache */
 356         String[] interfaceNames = new String[interfaces.length];
 357 
 358         // for detecting duplicates
 359         Set<Class<?>> interfaceSet = new HashSet<Class<?>>();
 360 
 361         for (int i = 0; i < interfaces.length; i++) {
 362             /*
 363              * Verify that the class loader resolves the name of this
 364              * interface to the same Class object.
 365              */
 366             String interfaceName = interfaces[i].getName();
 367             Class interfaceClass = null;
 368             try {
 369                 interfaceClass = Class.forName(interfaceName, false, loader);
 370             } catch (ClassNotFoundException e) {
 371             }
 372             if (interfaceClass != interfaces[i]) {
 373                 throw new IllegalArgumentException(
 374                     interfaces[i] + " is not visible from class loader");
 375             }
 376 
 377             /*
 378              * Verify that the Class object actually represents an
 379              * interface.
 380              */
 381             if (!interfaceClass.isInterface()) {
 382                 throw new IllegalArgumentException(
 383                     interfaceClass.getName() + " is not an interface");
 384             }
 385 
 386             /*
 387              * Verify that this interface is not a duplicate.




 333      *
 334      * @param   loader the class loader to define the proxy class
 335      * @param   interfaces the list of interfaces for the proxy class
 336      *          to implement
 337      * @return  a proxy class that is defined in the specified class loader
 338      *          and that implements the specified interfaces
 339      * @throws  IllegalArgumentException if any of the restrictions on the
 340      *          parameters that may be passed to {@code getProxyClass}
 341      *          are violated
 342      * @throws  NullPointerException if the {@code interfaces} array
 343      *          argument or any of its elements are {@code null}
 344      */
 345     public static Class<?> getProxyClass(ClassLoader loader,
 346                                          Class<?>... interfaces)
 347         throws IllegalArgumentException
 348     {
 349         if (interfaces.length > 65535) {
 350             throw new IllegalArgumentException("interface limit exceeded");
 351         }
 352 
 353         Class<?> proxyClass = null;
 354 
 355         /* collect interface names to use as key for proxy class cache */
 356         String[] interfaceNames = new String[interfaces.length];
 357 
 358         // for detecting duplicates
 359         Set<Class<?>> interfaceSet = new HashSet<Class<?>>();
 360 
 361         for (int i = 0; i < interfaces.length; i++) {
 362             /*
 363              * Verify that the class loader resolves the name of this
 364              * interface to the same Class object.
 365              */
 366             String interfaceName = interfaces[i].getName();
 367             Class<?> interfaceClass = null;
 368             try {
 369                 interfaceClass = Class.forName(interfaceName, false, loader);
 370             } catch (ClassNotFoundException e) {
 371             }
 372             if (interfaceClass != interfaces[i]) {
 373                 throw new IllegalArgumentException(
 374                     interfaces[i] + " is not visible from class loader");
 375             }
 376 
 377             /*
 378              * Verify that the Class object actually represents an
 379              * interface.
 380              */
 381             if (!interfaceClass.isInterface()) {
 382                 throw new IllegalArgumentException(
 383                     interfaceClass.getName() + " is not an interface");
 384             }
 385 
 386             /*
 387              * Verify that this interface is not a duplicate.