src/share/classes/sun/misc/Launcher.java

Print this page




 278             return AccessController.doPrivileged(
 279                 new PrivilegedAction<AppClassLoader>() {
 280                     public AppClassLoader run() {
 281                     URL[] urls =
 282                         (s == null) ? new URL[0] : pathToURLs(path);
 283                     return new AppClassLoader(urls, extcl);
 284                 }
 285             });
 286         }
 287 
 288         /*
 289          * Creates a new AppClassLoader
 290          */
 291         AppClassLoader(URL[] urls, ClassLoader parent) {
 292             super(urls, parent, factory);
 293         }
 294 
 295         /**
 296          * Override loadClass so we can checkPackageAccess.
 297          */
 298         public Class loadClass(String name, boolean resolve)
 299             throws ClassNotFoundException
 300         {
 301             int i = name.lastIndexOf('.');
 302             if (i != -1) {
 303                 SecurityManager sm = System.getSecurityManager();
 304                 if (sm != null) {
 305                     sm.checkPackageAccess(name.substring(0, i));
 306                 }
 307             }
 308             return (super.loadClass(name, resolve));
 309         }
 310 
 311         /**
 312          * allow any classes loaded from classpath to exit the VM.
 313          */
 314         protected PermissionCollection getPermissions(CodeSource codesource)
 315         {
 316             PermissionCollection perms = super.getPermissions(codesource);
 317             perms.add(new RuntimePermission("exitVM"));
 318             return perms;


 456             file = file.getCanonicalFile();
 457         } catch (IOException e) {}
 458 
 459         try {
 460             return ParseUtil.fileToEncodedURL(file);
 461         } catch (MalformedURLException e) {
 462             // Should never happen since we specify the protocol...
 463             throw new InternalError(e);
 464         }
 465     }
 466 
 467     /*
 468      * The stream handler factory for loading system protocol handlers.
 469      */
 470     private static class Factory implements URLStreamHandlerFactory {
 471         private static String PREFIX = "sun.net.www.protocol";
 472 
 473         public URLStreamHandler createURLStreamHandler(String protocol) {
 474             String name = PREFIX + "." + protocol + ".Handler";
 475             try {
 476                 Class c = Class.forName(name);
 477                 return (URLStreamHandler)c.newInstance();
 478             } catch (ReflectiveOperationException e) {
 479                 throw new InternalError("could not load " + protocol +
 480                                         "system protocol handler", e);
 481             }
 482         }
 483     }
 484 }
 485 
 486 class PathPermissions extends PermissionCollection {
 487     // use serialVersionUID from JDK 1.2.2 for interoperability
 488     private static final long serialVersionUID = 8133287259134945693L;
 489 
 490     private File path[];
 491     private Permissions perms;
 492 
 493     URL codeBase;
 494 
 495     PathPermissions(File path[])
 496     {




 278             return AccessController.doPrivileged(
 279                 new PrivilegedAction<AppClassLoader>() {
 280                     public AppClassLoader run() {
 281                     URL[] urls =
 282                         (s == null) ? new URL[0] : pathToURLs(path);
 283                     return new AppClassLoader(urls, extcl);
 284                 }
 285             });
 286         }
 287 
 288         /*
 289          * Creates a new AppClassLoader
 290          */
 291         AppClassLoader(URL[] urls, ClassLoader parent) {
 292             super(urls, parent, factory);
 293         }
 294 
 295         /**
 296          * Override loadClass so we can checkPackageAccess.
 297          */
 298         public Class<?> loadClass(String name, boolean resolve)
 299             throws ClassNotFoundException
 300         {
 301             int i = name.lastIndexOf('.');
 302             if (i != -1) {
 303                 SecurityManager sm = System.getSecurityManager();
 304                 if (sm != null) {
 305                     sm.checkPackageAccess(name.substring(0, i));
 306                 }
 307             }
 308             return (super.loadClass(name, resolve));
 309         }
 310 
 311         /**
 312          * allow any classes loaded from classpath to exit the VM.
 313          */
 314         protected PermissionCollection getPermissions(CodeSource codesource)
 315         {
 316             PermissionCollection perms = super.getPermissions(codesource);
 317             perms.add(new RuntimePermission("exitVM"));
 318             return perms;


 456             file = file.getCanonicalFile();
 457         } catch (IOException e) {}
 458 
 459         try {
 460             return ParseUtil.fileToEncodedURL(file);
 461         } catch (MalformedURLException e) {
 462             // Should never happen since we specify the protocol...
 463             throw new InternalError(e);
 464         }
 465     }
 466 
 467     /*
 468      * The stream handler factory for loading system protocol handlers.
 469      */
 470     private static class Factory implements URLStreamHandlerFactory {
 471         private static String PREFIX = "sun.net.www.protocol";
 472 
 473         public URLStreamHandler createURLStreamHandler(String protocol) {
 474             String name = PREFIX + "." + protocol + ".Handler";
 475             try {
 476                 Class<?> c = Class.forName(name);
 477                 return (URLStreamHandler)c.newInstance();
 478             } catch (ReflectiveOperationException e) {
 479                 throw new InternalError("could not load " + protocol +
 480                                         "system protocol handler", e);
 481             }
 482         }
 483     }
 484 }
 485 
 486 class PathPermissions extends PermissionCollection {
 487     // use serialVersionUID from JDK 1.2.2 for interoperability
 488     private static final long serialVersionUID = 8133287259134945693L;
 489 
 490     private File path[];
 491     private Permissions perms;
 492 
 493     URL codeBase;
 494 
 495     PathPermissions(File path[])
 496     {