< prev index next >

src/java.base/share/classes/java/lang/reflect/Module.java

Print this page




 106     private final ModuleDescriptor descriptor;
 107 
 108 
 109     /**
 110      * Creates a new named Module. The resulting Module will be defined to the
 111      * VM but will not read any other modules, will not have any exports setup
 112      * and will not be registered in the service catalog.
 113      */
 114     private Module(Layer layer,
 115                    ClassLoader loader,
 116                    ModuleDescriptor descriptor,
 117                    URI uri)
 118     {
 119         this.layer = layer;
 120         this.name = descriptor.name();
 121         this.loader = loader;
 122         this.descriptor = descriptor;
 123 
 124         // define module to VM
 125 
 126         boolean isOpen = descriptor.isOpen();
 127         Version version = descriptor.version().orElse(null);
 128         String vs = Objects.toString(version, null);
 129         String loc = Objects.toString(uri, null);
 130         String[] packages = descriptor.packages().toArray(new String[0]);
 131         defineModule0(this, isOpen, vs, loc, packages);
 132     }
 133 
 134 
 135     /**
 136      * Create the unnamed Module for the given ClassLoader.
 137      *
 138      * @see ClassLoader#getUnnamedModule
 139      */
 140     private Module(ClassLoader loader) {
 141         this.layer = null;
 142         this.name = null;
 143         this.loader = loader;
 144         this.descriptor = null;
 145     }
 146 


1149         return parent.layers()
1150                 .filter(l -> l.configuration() == cf)
1151                 .findAny()
1152                 .map(layer -> {
1153                     Optional<Module> om = layer.findModule(dn);
1154                     assert om.isPresent() : dn + " not found in layer";
1155                     Module m = om.get();
1156                     assert m.getLayer() == layer : m + " not in expected layer";
1157                     return m;
1158                 })
1159                 .orElse(null);
1160     }
1161 
1162     /**
1163      * Initialize the maps of exported and open packages for module m.
1164      */
1165     private static void initExportsAndOpens(ModuleDescriptor descriptor,
1166                                             Map<String, Module> nameToModule,
1167                                             Module m)
1168     {
1169         // The VM doesn't special case open or automatic modules so need to
1170         // export all packages
1171         if (descriptor.isOpen() || descriptor.isAutomatic()) {
1172             assert descriptor.opens().isEmpty();
1173             for (String source : descriptor.packages()) {
1174                 addExportsToAll0(m, source);
1175             }
1176             return;
1177         }
1178 
1179         Map<String, Set<Module>> openPackages = new HashMap<>();
1180         Map<String, Set<Module>> exportedPackages = new HashMap<>();
1181 
1182         // process the open packages first
1183         for (Opens opens : descriptor.opens()) {
1184             String source = opens.source();
1185 
1186             if (opens.isQualified()) {
1187                 // qualified opens
1188                 Set<Module> targets = new HashSet<>();
1189                 for (String target : opens.targets()) {
1190                     // only open to modules that are in this configuration
1191                     Module m2 = nameToModule.get(target);
1192                     if (m2 != null) {
1193                         addExports0(m, source, m2);
1194                         targets.add(m2);
1195                     }




 106     private final ModuleDescriptor descriptor;
 107 
 108 
 109     /**
 110      * Creates a new named Module. The resulting Module will be defined to the
 111      * VM but will not read any other modules, will not have any exports setup
 112      * and will not be registered in the service catalog.
 113      */
 114     private Module(Layer layer,
 115                    ClassLoader loader,
 116                    ModuleDescriptor descriptor,
 117                    URI uri)
 118     {
 119         this.layer = layer;
 120         this.name = descriptor.name();
 121         this.loader = loader;
 122         this.descriptor = descriptor;
 123 
 124         // define module to VM
 125 
 126         boolean isOpen = descriptor.isOpen() || descriptor.isAutomatic();
 127         Version version = descriptor.version().orElse(null);
 128         String vs = Objects.toString(version, null);
 129         String loc = Objects.toString(uri, null);
 130         String[] packages = descriptor.packages().toArray(new String[0]);
 131         defineModule0(this, isOpen, vs, loc, packages);
 132     }
 133 
 134 
 135     /**
 136      * Create the unnamed Module for the given ClassLoader.
 137      *
 138      * @see ClassLoader#getUnnamedModule
 139      */
 140     private Module(ClassLoader loader) {
 141         this.layer = null;
 142         this.name = null;
 143         this.loader = loader;
 144         this.descriptor = null;
 145     }
 146 


1149         return parent.layers()
1150                 .filter(l -> l.configuration() == cf)
1151                 .findAny()
1152                 .map(layer -> {
1153                     Optional<Module> om = layer.findModule(dn);
1154                     assert om.isPresent() : dn + " not found in layer";
1155                     Module m = om.get();
1156                     assert m.getLayer() == layer : m + " not in expected layer";
1157                     return m;
1158                 })
1159                 .orElse(null);
1160     }
1161 
1162     /**
1163      * Initialize the maps of exported and open packages for module m.
1164      */
1165     private static void initExportsAndOpens(ModuleDescriptor descriptor,
1166                                             Map<String, Module> nameToModule,
1167                                             Module m)
1168     {
1169         // The VM special cases open and automatic modules so don't need to
1170         // export their packages
1171         if (descriptor.isOpen() || descriptor.isAutomatic()) {




1172             return;
1173         }
1174 
1175         Map<String, Set<Module>> openPackages = new HashMap<>();
1176         Map<String, Set<Module>> exportedPackages = new HashMap<>();
1177 
1178         // process the open packages first
1179         for (Opens opens : descriptor.opens()) {
1180             String source = opens.source();
1181 
1182             if (opens.isQualified()) {
1183                 // qualified opens
1184                 Set<Module> targets = new HashSet<>();
1185                 for (String target : opens.targets()) {
1186                     // only open to modules that are in this configuration
1187                     Module m2 = nameToModule.get(target);
1188                     if (m2 != null) {
1189                         addExports0(m, source, m2);
1190                         targets.add(m2);
1191                     }


< prev index next >