Class URLClassSpace

    • Constructor Summary

      Constructors 
      Constructor Description
      URLClassSpace​(java.lang.ClassLoader loader)
      Creates a ClassSpace backed by a ClassLoader and its default class path.
      URLClassSpace​(java.lang.ClassLoader loader, java.net.URL[] path)
      Creates a ClassSpace backed by a ClassLoader with a restricted class path.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      DeferredClass<?> deferLoadClass​(java.lang.String name)
      Defers loading of the named class from the surrounding class space.
      boolean equals​(java.lang.Object rhs)  
      private static java.net.URL[] expandClassPath​(java.net.URL[] classPath)
      Expands the given URL class path to include Class-Path entries from local manifests.
      java.util.Enumeration<java.net.URL> findEntries​(java.lang.String path, java.lang.String glob, boolean recurse)
      Queries local class space content for entries matching the given pattern.
      private java.net.URL[] getClassPath()
      Returns the associated URL class path; this can either be explicit or implicit.
      private static java.lang.String[] getClassPathEntries​(java.net.URL url)
      Looks for Class-Path entries in the given jar or directory; returns empty array if none are found.
      java.net.URL getResource​(java.lang.String name)
      Queries the surrounding class space for the resource with the given name.
      java.util.Enumeration<java.net.URL> getResources​(java.lang.String name)
      Queries the surrounding class space for all resources with the given name.
      private static java.net.URL[] getSystemClassPath()
      Returns the system URL class path.
      java.net.URL[] getURLs()  
      int hashCode()  
      java.lang.Class<?> loadClass​(java.lang.String name)
      Loads the named class from the surrounding class space.
      private static java.net.URL normalizeEntry​(java.net.URL url)
      Normalizes the given class path entry by removing any extraneous "jar:"..."!/" padding.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

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

      • NO_URLS

        private static final java.net.URL[] NO_URLS
      • NO_ENTRIES

        private static final java.util.Enumeration<java.net.URL> NO_ENTRIES
      • EMPTY_CLASSPATH

        private static final java.lang.String[] EMPTY_CLASSPATH
      • SYSTEM_LOADER

        private static final java.lang.ClassLoader SYSTEM_LOADER
      • SYSTEM_CLASSPATH

        private static final java.lang.String SYSTEM_CLASSPATH
      • loader

        private final java.lang.ClassLoader loader
      • pathDetails

        private final java.lang.String pathDetails
      • classPath

        private java.net.URL[] classPath
    • Constructor Detail

      • URLClassSpace

        public URLClassSpace​(java.lang.ClassLoader loader)
        Creates a ClassSpace backed by a ClassLoader and its default class path.

        For URLClassLoaders this is their expanded Class-Path; otherwise it is empty.

        Parameters:
        loader - The class loader to use when getting/finding resources
      • URLClassSpace

        public URLClassSpace​(java.lang.ClassLoader loader,
                             java.net.URL[] path)
        Creates a ClassSpace backed by a ClassLoader with a restricted class path.
        Parameters:
        loader - The class loader to use when getting resources
        path - The class path to use when finding resources
        See Also:
        getResources(String), findEntries(String, String, boolean)
    • Method Detail

      • loadClass

        public final java.lang.Class<?> loadClass​(java.lang.String name)
        Description copied from interface: ClassSpace
        Loads the named class from the surrounding class space.
        Specified by:
        loadClass in interface ClassSpace
        Parameters:
        name - The class name
        Returns:
        Class instance
        See Also:
        ClassLoader.loadClass(String)
      • deferLoadClass

        public final DeferredClass<?> deferLoadClass​(java.lang.String name)
        Description copied from interface: ClassSpace
        Defers loading of the named class from the surrounding class space.
        Specified by:
        deferLoadClass in interface ClassSpace
        Parameters:
        name - The class name
        Returns:
        Deferred class
        See Also:
        ClassLoader.loadClass(String)
      • getResource

        public final java.net.URL getResource​(java.lang.String name)
        Description copied from interface: ClassSpace
        Queries the surrounding class space for the resource with the given name.
        Specified by:
        getResource in interface ClassSpace
        Parameters:
        name - The resource name
        Returns:
        URL pointing to the resource; null if it wasn't found
        See Also:
        ClassLoader.getResource(String)
      • getResources

        public final java.util.Enumeration<java.net.URL> getResources​(java.lang.String name)
        Description copied from interface: ClassSpace
        Queries the surrounding class space for all resources with the given name.
        Specified by:
        getResources in interface ClassSpace
        Parameters:
        name - The resource name
        Returns:
        Sequence of URLs, one for each matching resource
        See Also:
        ClassLoader.getResources(String)
      • findEntries

        public final java.util.Enumeration<java.net.URL> findEntries​(java.lang.String path,
                                                                     java.lang.String glob,
                                                                     boolean recurse)
        Description copied from interface: ClassSpace
        Queries local class space content for entries matching the given pattern.
        Specified by:
        findEntries in interface ClassSpace
        Parameters:
        path - The initial search directory; for example "META-INF"
        glob - The filename glob pattern; for example "*.xml"
        recurse - If true recurse into sub-directories; otherwise only search initial directory
        Returns:
        Sequence of URLs, one for each matching entry
        See Also:
        Bundle.findEntries(String, String, boolean)
      • getURLs

        public final java.net.URL[] getURLs()
      • hashCode

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

        public final boolean equals​(java.lang.Object rhs)
        Overrides:
        equals in class java.lang.Object
      • toString

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

        private java.net.URL[] getClassPath()
        Returns the associated URL class path; this can either be explicit or implicit.
      • getSystemClassPath

        private static java.net.URL[] getSystemClassPath()
        Returns the system URL class path.
      • expandClassPath

        private static java.net.URL[] expandClassPath​(java.net.URL[] classPath)
        Expands the given URL class path to include Class-Path entries from local manifests.
        Parameters:
        classPath - The URL class path
        Returns:
        Expanded URL class path
      • normalizeEntry

        private static java.net.URL normalizeEntry​(java.net.URL url)
        Normalizes the given class path entry by removing any extraneous "jar:"..."!/" padding.
        Parameters:
        path - The URL to normalize
        Returns:
        Normalized class path entry
      • getClassPathEntries

        private static java.lang.String[] getClassPathEntries​(java.net.URL url)
                                                       throws java.io.IOException
        Looks for Class-Path entries in the given jar or directory; returns empty array if none are found.
        Parameters:
        url - The jar or directory to inspect
        Returns:
        Array of Class-Path entries
        Throws:
        java.io.IOException