682 *
683 * @implSpec The default implementation throws {@code ClassNotFoundException}.
684 *
685 * @param name
686 * The <a href="#binary-name">binary name</a> of the class
687 *
688 * @return The resulting {@code Class} object
689 *
690 * @throws ClassNotFoundException
691 * If the class could not be found
692 *
693 * @since 1.2
694 */
695 protected Class<?> findClass(String name) throws ClassNotFoundException {
696 throw new ClassNotFoundException(name);
697 }
698
699 /**
700 * Finds the class with the given <a href="#binary-name">binary name</a>
701 * in a module defined to this class loader.
702 * Class loader implementations that support the loading from modules
703 * should override this method.
704 *
705 * @apiNote This method returns {@code null} rather than throwing
706 * {@code ClassNotFoundException} if the class could not be found.
707 *
708 * @implSpec The default implementation attempts to find the class by
709 * invoking {@link #findClass(String)} when the {@code moduleName} is
710 * {@code null}. It otherwise returns {@code null}.
711 *
712 * @param moduleName
713 * The module name; or {@code null} to find the class in the
714 * {@linkplain #getUnnamedModule() unnamed module} for this
715 * class loader
716
717 * @param name
718 * The <a href="#binary-name">binary name</a> of the class
719 *
720 * @return The resulting {@code Class} object, or {@code null}
721 * if the class could not be found.
722 *
1264 * Sets the signers of a class. This should be invoked after defining a
1265 * class.
1266 *
1267 * @param c
1268 * The {@code Class} object
1269 *
1270 * @param signers
1271 * The signers for the class
1272 *
1273 * @since 1.1
1274 */
1275 protected final void setSigners(Class<?> c, Object[] signers) {
1276 c.setSigners(signers);
1277 }
1278
1279
1280 // -- Resources --
1281
1282 /**
1283 * Returns a URL to a resource in a module defined to this class loader.
1284 * Class loader implementations that support the loading from modules
1285 * should override this method.
1286 *
1287 * @apiNote This method is the basis for the {@link
1288 * Class#getResource Class.getResource}, {@link Class#getResourceAsStream
1289 * Class.getResourceAsStream}, and {@link Module#getResourceAsStream
1290 * Module.getResourceAsStream} methods. It is not subject to the rules for
1291 * encapsulation specified by {@code Module.getResourceAsStream}.
1292 *
1293 * @implSpec The default implementation attempts to find the resource by
1294 * invoking {@link #findResource(String)} when the {@code moduleName} is
1295 * {@code null}. It otherwise returns {@code null}.
1296 *
1297 * @param moduleName
1298 * The module name; or {@code null} to find a resource in the
1299 * {@linkplain #getUnnamedModule() unnamed module} for this
1300 * class loader
1301 * @param name
1302 * The resource name
1303 *
1304 * @return A URL to the resource; {@code null} if the resource could not be
1400 * loader for the resource; if the parent is {@code null} the path of the
1401 * class loader built into the virtual machine is searched. It then
1402 * invokes {@link #findResources(String)} to find the resources with the
1403 * name in this class loader. It returns an enumeration whose elements
1404 * are the URLs found by searching the parent class loader followed by
1405 * the elements found with {@code findResources}.
1406 *
1407 * @apiNote Where several modules are defined to the same class loader,
1408 * and where more than one module contains a resource with the given name,
1409 * then the ordering is not specified and may be very unpredictable.
1410 * When overriding this method it is recommended that an
1411 * implementation ensures that any delegation is consistent with the {@link
1412 * #getResource(java.lang.String) getResource(String)} method. This should
1413 * ensure that the first element returned by the Enumeration's
1414 * {@code nextElement} method is the same resource that the
1415 * {@code getResource(String)} method would return.
1416 *
1417 * @param name
1418 * The resource name
1419 *
1420 * @return An enumeration of {@link java.net.URL URL} objects for
1421 * the resource. If no resources could be found, the enumeration
1422 * will be empty. Resources for which a {@code URL} cannot be
1423 * constructed, are in package that is not opened unconditionally,
1424 * or access to the resource is denied by the security manager,
1425 * are not returned in the enumeration.
1426 *
1427 * @throws IOException
1428 * If I/O errors occur
1429 * @throws NullPointerException If {@code name} is {@code null}
1430 *
1431 * @since 1.2
1432 * @revised 9
1433 * @spec JPMS
1434 */
1435 public Enumeration<URL> getResources(String name) throws IOException {
1436 Objects.requireNonNull(name);
1437 @SuppressWarnings("unchecked")
1438 Enumeration<URL>[] tmp = (Enumeration<URL>[]) new Enumeration<?>[2];
1439 if (parent != null) {
1440 tmp[0] = parent.getResources(name);
1441 } else {
1442 tmp[0] = BootLoader.findResources(name);
1443 }
1444 tmp[1] = findResources(name);
1445
|
682 *
683 * @implSpec The default implementation throws {@code ClassNotFoundException}.
684 *
685 * @param name
686 * The <a href="#binary-name">binary name</a> of the class
687 *
688 * @return The resulting {@code Class} object
689 *
690 * @throws ClassNotFoundException
691 * If the class could not be found
692 *
693 * @since 1.2
694 */
695 protected Class<?> findClass(String name) throws ClassNotFoundException {
696 throw new ClassNotFoundException(name);
697 }
698
699 /**
700 * Finds the class with the given <a href="#binary-name">binary name</a>
701 * in a module defined to this class loader.
702 * Class loader implementations that support loading from modules
703 * should override this method.
704 *
705 * @apiNote This method returns {@code null} rather than throwing
706 * {@code ClassNotFoundException} if the class could not be found.
707 *
708 * @implSpec The default implementation attempts to find the class by
709 * invoking {@link #findClass(String)} when the {@code moduleName} is
710 * {@code null}. It otherwise returns {@code null}.
711 *
712 * @param moduleName
713 * The module name; or {@code null} to find the class in the
714 * {@linkplain #getUnnamedModule() unnamed module} for this
715 * class loader
716
717 * @param name
718 * The <a href="#binary-name">binary name</a> of the class
719 *
720 * @return The resulting {@code Class} object, or {@code null}
721 * if the class could not be found.
722 *
1264 * Sets the signers of a class. This should be invoked after defining a
1265 * class.
1266 *
1267 * @param c
1268 * The {@code Class} object
1269 *
1270 * @param signers
1271 * The signers for the class
1272 *
1273 * @since 1.1
1274 */
1275 protected final void setSigners(Class<?> c, Object[] signers) {
1276 c.setSigners(signers);
1277 }
1278
1279
1280 // -- Resources --
1281
1282 /**
1283 * Returns a URL to a resource in a module defined to this class loader.
1284 * Class loader implementations that support loading from modules
1285 * should override this method.
1286 *
1287 * @apiNote This method is the basis for the {@link
1288 * Class#getResource Class.getResource}, {@link Class#getResourceAsStream
1289 * Class.getResourceAsStream}, and {@link Module#getResourceAsStream
1290 * Module.getResourceAsStream} methods. It is not subject to the rules for
1291 * encapsulation specified by {@code Module.getResourceAsStream}.
1292 *
1293 * @implSpec The default implementation attempts to find the resource by
1294 * invoking {@link #findResource(String)} when the {@code moduleName} is
1295 * {@code null}. It otherwise returns {@code null}.
1296 *
1297 * @param moduleName
1298 * The module name; or {@code null} to find a resource in the
1299 * {@linkplain #getUnnamedModule() unnamed module} for this
1300 * class loader
1301 * @param name
1302 * The resource name
1303 *
1304 * @return A URL to the resource; {@code null} if the resource could not be
1400 * loader for the resource; if the parent is {@code null} the path of the
1401 * class loader built into the virtual machine is searched. It then
1402 * invokes {@link #findResources(String)} to find the resources with the
1403 * name in this class loader. It returns an enumeration whose elements
1404 * are the URLs found by searching the parent class loader followed by
1405 * the elements found with {@code findResources}.
1406 *
1407 * @apiNote Where several modules are defined to the same class loader,
1408 * and where more than one module contains a resource with the given name,
1409 * then the ordering is not specified and may be very unpredictable.
1410 * When overriding this method it is recommended that an
1411 * implementation ensures that any delegation is consistent with the {@link
1412 * #getResource(java.lang.String) getResource(String)} method. This should
1413 * ensure that the first element returned by the Enumeration's
1414 * {@code nextElement} method is the same resource that the
1415 * {@code getResource(String)} method would return.
1416 *
1417 * @param name
1418 * The resource name
1419 *
1420 * @return An enumeration of {@link java.net.URL URL} objects for the
1421 * resource. If no resources could be found, the enumeration will
1422 * be empty. Resources for which a {@code URL} cannot be
1423 * constructed, are in a package that is not opened
1424 * unconditionally, or access to the resource is denied by the
1425 * security manager, are not returned in the enumeration.
1426 *
1427 * @throws IOException
1428 * If I/O errors occur
1429 * @throws NullPointerException If {@code name} is {@code null}
1430 *
1431 * @since 1.2
1432 * @revised 9
1433 * @spec JPMS
1434 */
1435 public Enumeration<URL> getResources(String name) throws IOException {
1436 Objects.requireNonNull(name);
1437 @SuppressWarnings("unchecked")
1438 Enumeration<URL>[] tmp = (Enumeration<URL>[]) new Enumeration<?>[2];
1439 if (parent != null) {
1440 tmp[0] = parent.getResources(name);
1441 } else {
1442 tmp[0] = BootLoader.findResources(name);
1443 }
1444 tmp[1] = findResources(name);
1445
|