Class ModuleRef

  • All Implemented Interfaces:
    java.lang.Comparable<ModuleRef>

    public class ModuleRef
    extends java.lang.Object
    implements java.lang.Comparable<ModuleRef>
    A ModuleReference proxy, written using reflection to preserve backwards compatibility with JDK 7 and 8.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.lang.ClassLoader classLoader
      The ClassLoader that loads classes in the module.
      private java.lang.Object descriptor
      The ModuleDescriptor for the module.
      private java.lang.Object layer
      The ModuleLayer for the module.
      private java.net.URI location
      The location URI for the module (may be null).
      private java.io.File locationFile
      A file formed from the location URI.
      private java.lang.String locationStr
      The location URI for the module, as a cached string (may be null).
      private java.lang.String name
      The name of the module.
      private java.util.List<java.lang.String> packages
      The packages in the module.
      private java.lang.String rawVersion
      The raw module version, or null if none.
      private java.lang.Object reference
      The ModuleReference for the module.
      (package private) ReflectionUtils reflectionUtils  
    • Constructor Summary

      Constructors 
      Constructor Description
      ModuleRef​(java.lang.Object moduleReference, java.lang.Object moduleLayer, ReflectionUtils reflectionUtils)
      Constructor.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int compareTo​(ModuleRef o)  
      boolean equals​(java.lang.Object obj)  
      java.lang.ClassLoader getClassLoader()
      Get the class loader for the module.
      java.lang.Object getDescriptor()
      Get the module descriptor, i.e.
      java.lang.Object getLayer()
      Get the module layer (of JPMS type ModuleLayer).
      java.net.URI getLocation()
      Get the module location, i.e.
      java.io.File getLocationFile()
      Get the module location as a File, i.e.
      java.lang.String getLocationStr()
      Get the module location as a string, i.e.
      java.lang.String getName()
      Get the module name, i.e.
      java.util.List<java.lang.String> getPackages()
      Get a list of packages in the module.
      java.lang.String getRawVersion()
      Get the raw version string of the module, or null if the module did not provide one.
      java.lang.Object getReference()
      Get the module reference (of JPMS type ModuleReference).
      int hashCode()  
      boolean isSystemModule()
      Checks if this module is a system module.
      ModuleReaderProxy open()
      Open the module, returning a ModuleReaderProxy.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Field Detail

      • name

        private final java.lang.String name
        The name of the module.
      • reference

        private final java.lang.Object reference
        The ModuleReference for the module.
      • layer

        private final java.lang.Object layer
        The ModuleLayer for the module.
      • descriptor

        private final java.lang.Object descriptor
        The ModuleDescriptor for the module.
      • packages

        private final java.util.List<java.lang.String> packages
        The packages in the module.
      • location

        private final java.net.URI location
        The location URI for the module (may be null).
      • locationStr

        private java.lang.String locationStr
        The location URI for the module, as a cached string (may be null).
      • locationFile

        private java.io.File locationFile
        A file formed from the location URI. The file will not exist if the location URI is a "jrt:" URI.
      • rawVersion

        private java.lang.String rawVersion
        The raw module version, or null if none.
      • classLoader

        private final java.lang.ClassLoader classLoader
        The ClassLoader that loads classes in the module. May be null, to represent the bootstrap classloader.
    • Constructor Detail

      • ModuleRef

        public ModuleRef​(java.lang.Object moduleReference,
                         java.lang.Object moduleLayer,
                         ReflectionUtils reflectionUtils)
        Constructor.
        Parameters:
        moduleReference - The module reference, of JPMS type ModuleReference.
        moduleLayer - The module layer, of JPMS type ModuleLayer
        reflectionUtils - The ReflectionUtils instance.
    • Method Detail

      • getName

        public java.lang.String getName()
        Get the module name, i.e. getReference().descriptor().name().
        Returns:
        The module name, i.e. getReference().descriptor().name(). Potentially null or empty.
      • getReference

        public java.lang.Object getReference()
        Get the module reference (of JPMS type ModuleReference).
        Returns:
        The module reference (of JPMS type ModuleReference).
      • getLayer

        public java.lang.Object getLayer()
        Get the module layer (of JPMS type ModuleLayer).
        Returns:
        The module layer (of JPMS type ModuleLayer).
      • getDescriptor

        public java.lang.Object getDescriptor()
        Get the module descriptor, i.e. getReference().descriptor() (of JPMS type ModuleDescriptor).
        Returns:
        The module descriptor, i.e. getReference().descriptor() (of JPMS type ModuleDescriptor).
      • getPackages

        public java.util.List<java.lang.String> getPackages()
        Get a list of packages in the module. (Does not include non-package directories.)
        Returns:
        The list of packages in the module. (Does not include non-package directories.)
      • getLocation

        public java.net.URI getLocation()
        Get the module location, i.e. getReference().location(). Returns null for modules that do not have a location.
        Returns:
        The module location, i.e. getReference().location(). Returns null for modules that do not have a location.
      • getLocationStr

        public java.lang.String getLocationStr()
        Get the module location as a string, i.e. getReference().location().toString(). Returns null for modules that do not have a location.
        Returns:
        The module location as a string, i.e. getReference().location().toString(). Returns null for modules that do not have a location.
      • getLocationFile

        public java.io.File getLocationFile()
        Get the module location as a File, i.e. new File(getReference().location()). Returns null for modules that do not have a location, or for system (or jlinked) modules, which have "jrt:" location URIs that include only the module name and not the module jar location.
        Returns:
        The module location as a File, i.e. new File(getReference().location()). Returns null for modules that do not have a location, or for modules whole location is a "jrt:" URI.
      • getRawVersion

        public java.lang.String getRawVersion()
        Get the raw version string of the module, or null if the module did not provide one.
        Returns:
        The raw version of the module, obtained by ModuleReference#rawVersion().orElse(null).
      • isSystemModule

        public boolean isSystemModule()
        Checks if this module is a system module.
        Returns:
        true if this module is a system module.
      • getClassLoader

        public java.lang.ClassLoader getClassLoader()
        Get the class loader for the module.
        Returns:
        The classloader for the module, i.e. moduleLayer.findLoader(getReference().descriptor().name()).
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • compareTo

        public int compareTo​(ModuleRef o)
        Specified by:
        compareTo in interface java.lang.Comparable<ModuleRef>