jdk/src/java.base/share/classes/java/lang/Module.java
changeset 45004 ea3137042a61
parent 44545 83b611b88ac8
child 45652 33342314ce89
child 46863 d2d62aec9891
equal deleted inserted replaced
44789:73fd39e0702e 45004:ea3137042a61
    55 
    55 
    56 import jdk.internal.loader.BuiltinClassLoader;
    56 import jdk.internal.loader.BuiltinClassLoader;
    57 import jdk.internal.loader.BootLoader;
    57 import jdk.internal.loader.BootLoader;
    58 import jdk.internal.misc.JavaLangAccess;
    58 import jdk.internal.misc.JavaLangAccess;
    59 import jdk.internal.misc.SharedSecrets;
    59 import jdk.internal.misc.SharedSecrets;
       
    60 import jdk.internal.module.ModuleLoaderMap;
    60 import jdk.internal.module.ServicesCatalog;
    61 import jdk.internal.module.ServicesCatalog;
    61 import jdk.internal.module.Resources;
    62 import jdk.internal.module.Resources;
    62 import jdk.internal.org.objectweb.asm.AnnotationVisitor;
    63 import jdk.internal.org.objectweb.asm.AnnotationVisitor;
    63 import jdk.internal.org.objectweb.asm.Attribute;
    64 import jdk.internal.org.objectweb.asm.Attribute;
    64 import jdk.internal.org.objectweb.asm.ClassReader;
    65 import jdk.internal.org.objectweb.asm.ClassReader;
   213     public ModuleDescriptor getDescriptor() {
   214     public ModuleDescriptor getDescriptor() {
   214         return descriptor;
   215         return descriptor;
   215     }
   216     }
   216 
   217 
   217     /**
   218     /**
   218      * Returns the layer that contains this module or {@code null} if this
   219      * Returns the module layer that contains this module or {@code null} if
   219      * module is not in a layer.
   220      * this module is not in a module layer.
   220      *
   221      *
   221      * A module layer contains named modules and therefore this method always
   222      * A module layer contains named modules and therefore this method always
   222      * returns {@code null} when invoked on an unnamed module.
   223      * returns {@code null} when invoked on an unnamed module.
   223      *
   224      *
   224      * <p> <a href="reflect/Proxy.html#dynamicmodule">Dynamic modules</a> are
   225      * <p> <a href="reflect/Proxy.html#dynamicmodule">Dynamic modules</a> are
   689      * access control checks.
   690      * access control checks.
   690      *
   691      *
   691      * <p> This method has no effect if the package is already <em>open</em>
   692      * <p> This method has no effect if the package is already <em>open</em>
   692      * to the given module. </p>
   693      * to the given module. </p>
   693      *
   694      *
       
   695      * @apiNote This method can be used for cases where a <em>consumer
       
   696      * module</em> uses a qualified opens to open a package to an <em>API
       
   697      * module</em> but where the reflective access to the members of classes in
       
   698      * the consumer module is delegated to code in another module. Code in the
       
   699      * API module can use this method to open the package in the consumer module
       
   700      * to the other module.
       
   701      *
   694      * @param  pn
   702      * @param  pn
   695      *         The package name
   703      *         The package name
   696      * @param  other
   704      * @param  other
   697      *         The module
   705      *         The module
   698      *
   706      *
  1075             String name = resolvedModule.name();
  1083             String name = resolvedModule.name();
  1076             ClassLoader loader = clf.apply(name);
  1084             ClassLoader loader = clf.apply(name);
  1077             if (loader != null) {
  1085             if (loader != null) {
  1078                 moduleToLoader.put(name, loader);
  1086                 moduleToLoader.put(name, loader);
  1079                 loaders.add(loader);
  1087                 loaders.add(loader);
  1080             } else if (!isBootLayer) {
  1088             } else if (!(clf instanceof ModuleLoaderMap.Mapper)) {
  1081                 throw new IllegalArgumentException("loader can't be 'null'");
  1089                 throw new IllegalArgumentException("loader can't be 'null'");
  1082             }
  1090             }
  1083         }
  1091         }
  1084 
  1092 
  1085         // define each module in the configuration to the VM
  1093         // define each module in the configuration to the VM
  1456      * <ul>
  1464      * <ul>
  1457      *     <li> If the resource name ends with  "{@code .class}" then it is not
  1465      *     <li> If the resource name ends with  "{@code .class}" then it is not
  1458      *     encapsulated. </li>
  1466      *     encapsulated. </li>
  1459      *
  1467      *
  1460      *     <li> A <em>package name</em> is derived from the resource name. If
  1468      *     <li> A <em>package name</em> is derived from the resource name. If
  1461      *     the package name is a {@link #getPackages() package} in the module
  1469      *     the package name is a {@linkplain #getPackages() package} in the
  1462      *     then the resource can only be located by the caller of this method
  1470      *     module then the resource can only be located by the caller of this
  1463      *     when the package is {@link #isOpen(String,Module) open} to at least
  1471      *     method when the package is {@linkplain #isOpen(String,Module) open}
  1464      *     the caller's module. If the resource is not in a package in the module
  1472      *     to at least the caller's module. If the resource is not in a
  1465      *     then the resource is not encapsulated. </li>
  1473      *     package in the module then the resource is not encapsulated. </li>
  1466      * </ul>
  1474      * </ul>
  1467      *
  1475      *
  1468      * <p> In the above, the <em>package name</em> for a resource is derived
  1476      * <p> In the above, the <em>package name</em> for a resource is derived
  1469      * from the subsequence of characters that precedes the last {@code '/'} in
  1477      * from the subsequence of characters that precedes the last {@code '/'} in
  1470      * the name and then replacing each {@code '/'} character in the subsequence
  1478      * the name and then replacing each {@code '/'} character in the subsequence
  1519         } else if (loader instanceof BuiltinClassLoader) {
  1527         } else if (loader instanceof BuiltinClassLoader) {
  1520             return ((BuiltinClassLoader) loader).findResourceAsStream(mn, name);
  1528             return ((BuiltinClassLoader) loader).findResourceAsStream(mn, name);
  1521         }
  1529         }
  1522 
  1530 
  1523         // locate resource in module
  1531         // locate resource in module
  1524         JavaLangAccess jla = SharedSecrets.getJavaLangAccess();
  1532         URL url = loader.findResource(mn, name);
  1525         URL url = jla.findResource(loader, mn, name);
       
  1526         if (url != null) {
  1533         if (url != null) {
  1527             try {
  1534             try {
  1528                 return url.openStream();
  1535                 return url.openStream();
  1529             } catch (SecurityException e) { }
  1536             } catch (SecurityException e) { }
  1530         }
  1537         }