337 * This includes the original list of URLs specified to the constructor,
338 * along with any URLs subsequently appended by the addURL() method.
339 * @return the search path of URLs for loading classes and resources.
340 */
341 public URL[] getURLs() {
342 return ucp.getURLs();
343 }
344
345 /**
346 * Finds and loads the class with the specified name from the URL search
347 * path. Any URLs referring to JAR files are loaded and opened as needed
348 * until the class is found.
349 *
350 * @param name the name of the class
351 * @return the resulting class
352 * @exception ClassNotFoundException if the class could not be found,
353 * or if the loader is closed.
354 * @exception NullPointerException if {@code name} is {@code null}.
355 */
356 protected Class<?> findClass(final String name)
357 throws ClassNotFoundException
358 {
359 try {
360 return AccessController.doPrivileged(
361 new PrivilegedExceptionAction<Class<?>>() {
362 public Class<?> run() throws ClassNotFoundException {
363 String path = name.replace('.', '/').concat(".class");
364 Resource res = ucp.getResource(path, false);
365 if (res != null) {
366 try {
367 return defineClass(name, res);
368 } catch (IOException e) {
369 throw new ClassNotFoundException(name, e);
370 }
371 } else {
372 throw new ClassNotFoundException(name);
373 }
374 }
375 }, acc);
376 } catch (java.security.PrivilegedActionException pae) {
377 throw (ClassNotFoundException) pae.getException();
378 }
379 }
380
381 /*
382 * Retrieve the package using the specified package name.
383 * If non-null, verify the package using the specified code
384 * source and manifest.
385 */
386 private Package getAndVerifyPackage(String pkgname,
387 Manifest man, URL url) {
388 Package pkg = getPackage(pkgname);
389 if (pkg != null) {
390 // Package found, so check package sealing.
391 if (pkg.isSealed()) {
392 // Verify that code source URL is the same.
393 if (!pkg.isSealed(url)) {
394 throw new SecurityException(
395 "sealing violation: package " + pkgname + " is sealed");
396 }
397 } else {
398 // Make sure we are not attempting to seal the package
|
337 * This includes the original list of URLs specified to the constructor,
338 * along with any URLs subsequently appended by the addURL() method.
339 * @return the search path of URLs for loading classes and resources.
340 */
341 public URL[] getURLs() {
342 return ucp.getURLs();
343 }
344
345 /**
346 * Finds and loads the class with the specified name from the URL search
347 * path. Any URLs referring to JAR files are loaded and opened as needed
348 * until the class is found.
349 *
350 * @param name the name of the class
351 * @return the resulting class
352 * @exception ClassNotFoundException if the class could not be found,
353 * or if the loader is closed.
354 * @exception NullPointerException if {@code name} is {@code null}.
355 */
356 protected Class<?> findClass(final String name)
357 throws ClassNotFoundException {
358 final Class<?> result;
359 try {
360 result = AccessController.doPrivileged(
361 new PrivilegedExceptionAction<Class<?>>() {
362 public Class<?> run() throws ClassNotFoundException {
363 String path = name.replace('.', '/').concat(".class");
364 Resource res = ucp.getResource(path, false);
365 if (res != null) {
366 try {
367 return defineClass(name, res);
368 } catch (IOException e) {
369 throw new ClassNotFoundException(name, e);
370 }
371 } else {
372 return null;
373 }
374 }
375 }, acc);
376 } catch (java.security.PrivilegedActionException pae) {
377 throw (ClassNotFoundException) pae.getException();
378 }
379 if (result == null) {
380 throw new ClassNotFoundException(name);
381 }
382 return result;
383 }
384
385 /*
386 * Retrieve the package using the specified package name.
387 * If non-null, verify the package using the specified code
388 * source and manifest.
389 */
390 private Package getAndVerifyPackage(String pkgname,
391 Manifest man, URL url) {
392 Package pkg = getPackage(pkgname);
393 if (pkg != null) {
394 // Package found, so check package sealing.
395 if (pkg.isSealed()) {
396 // Verify that code source URL is the same.
397 if (!pkg.isSealed(url)) {
398 throw new SecurityException(
399 "sealing violation: package " + pkgname + " is sealed");
400 }
401 } else {
402 // Make sure we are not attempting to seal the package
|