net.sourceforge.jnlp.runtime

## Class JNLPClassLoader

- java.lang.Object
- - java.lang.ClassLoader
  - - java.security.SecureClassLoader
    - - java.net.URLClassLoader
      - - net.sourceforge.jnlp.runtime.JNLPClassLoader

- All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable

      public class JNLPClassLoader
      extends java.net.URLClassLoader

  Classloader that takes it's resources from a JNLP file. If the JNLP file defines extensions, separate classloaders for these will be created automatically. Classes are loaded with the security context when the classloader was created.

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `JNLPClassLoader.CodeBaseClassLoader`
    `static class` | `JNLPClassLoader.DownloadAction` Actions to specify how cache is to be managed

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static java.lang.String` | `APPLICATION`
    `static java.lang.String` | `TEMPLATE` Signed JNLP File and Template

  - ### Constructor Summary

    Constructors
    Modifier | Constructor and Description
    --- | ---
    `protected` | `JNLPClassLoader(JNLPFile file, UpdatePolicy policy)` Create a new JNLPClassLoader from the specified file.
    `protected` | `JNLPClassLoader(JNLPFile file, UpdatePolicy policy, java.lang.String mainName)` Create a new JNLPClassLoader from the specified file.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected void` | `activateJars(java.util.List<JARDesc> jars)` Ensures that the list of jars have all been transferred, and makes them available to the classloader.
    `protected void` | `activateNative(JARDesc jar)` Search for and enable any native code contained in a JAR by copying the native files into the filesystem.
    `protected void` | `addAvailable()` Adds whatever resources have already been downloaded in the background.
    `protected void` | `addNativeDirectory(java.io.File nativeDirectory)` Adds the `File` to the search path of this `JNLPClassLoader` when trying to find a native library
    `protected JNLPClassLoader` | `addNextResource()` Adds the next unused resource to the classloader.
    `protected void` | `addPermission(java.security.Permission p)`
    `void` | `decrementLoaderUseCount()` Decrements loader use count by 1 If count reaches 0, loader is removed from list of available loaders
    `void` | `enableCodeBase()` Add applet's codebase URL.
    `protected void` | `fillInPartJars(java.util.List<JARDesc> jars)` Adds to the specified list of JARS any other JARs that need to be loaded at the same time as the JARs specified (ie, are in the same part).
    `protected java.lang.Class` | `findClass(java.lang.String name)` Find the class in this loader or any of its extension loaders.
    `protected java.lang.String` | `findLibrary(java.lang.String lib)` Return the absolute path to the native library.
    `protected java.lang.String` | `findLibraryExt(java.lang.String lib)` Try to find the library path from another peer classloader.
    `protected java.lang.Class` | `findLoadedClassAll(java.lang.String name)` Find the loaded class in this loader or any of its extension loaders.
    `java.net.URL` | `findResource(java.lang.String name)` Finds the resource in this, the parent, or the extension class loaders.
    `java.util.Enumeration<java.net.URL>` | `findResources(java.lang.String name)` Find the resources in this, the parent, or the extension class loaders.
    `java.security.AccessControlContext` | `getAccessControlContextForClassLoading()` Returns an appropriate AccessControlContext for loading classes in the running instance.
    `ApplicationInstance` | `getApplication()` Returns the JNLP app for this classloader
    `protected SecurityDesc` | `getCodeSourceSecurity(java.net.URL source)` Returns the security descriptor for given code source URL
    `java.lang.String` | `getExtensionHREF()` Deprecated.
    `java.lang.String` | `getExtensionName()` Deprecated.
    `static JNLPClassLoader` | `getInstance(JNLPFile file, UpdatePolicy policy)` Returns a JNLP classloader for the specified JNLP file.
    `static JNLPClassLoader` | `getInstance(JNLPFile file, UpdatePolicy policy, java.lang.String mainName)` Returns a JNLP classloader for the specified JNLP file.
    `static JNLPClassLoader` | `getInstance(java.net.URL location, java.lang.String uniqueKey, Version version, UpdatePolicy policy, java.lang.String mainName)` Returns a JNLP classloader for the JNLP file at the specified location.
    `JNLPFile` | `getJNLPFile()` Returns the JNLP file the classloader was created from.
    `protected java.io.File` | `getNativeDir()` Return the base directory to store native code files in.
    `protected java.util.List<java.io.File>` | `getNativeDirectories()` Returns a list of all directories in the search path of the current classloader when it tires to find a native library.
    `protected java.security.PermissionCollection` | `getPermissions(java.security.CodeSource cs)` Returns the permissions for the CodeSource.
    `protected SecurityDesc` | `getSecurity()`
    `boolean` | `getSigning()`
    `boolean` | `hasMainJar()` Returns true if this loader has the main jar
    `java.lang.Class<?>` | `loadClass(java.lang.String name)` Find a JAR in the shared 'extension' classloaders, this classloader, or one of the classloaders for the JNLP file's extensions.
    `boolean` | `resourceAvailableLocally(java.lang.String s)` Returns if the specified resource is available locally from a cached jar
    `void` | `setApplication(ApplicationInstance app)` Sets the JNLP app this group is for; can only be called once.

    - ### Methods inherited from class java.net.URLClassLoader

      `addURL, close, definePackage, getResourceAsStream, getURLs, newInstance, newInstance`

    - ### Methods inherited from class java.security.SecureClassLoader

      `defineClass, defineClass`

    - ### Methods inherited from class java.lang.ClassLoader

      `clearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findLoadedClass, findSystemClass, getClassLoadingLock, getPackage, getPackages, getParent, getResource, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, loadClass, registerAsParallelCapable, resolveClass, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### TEMPLATE

          public static final java.lang.String TEMPLATE

      Signed JNLP File and Template
      See Also:
        Constant Field Values

    - #### APPLICATION

          public static final java.lang.String APPLICATION

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### JNLPClassLoader

          protected JNLPClassLoader(JNLPFile file,
                         UpdatePolicy policy)
                             throws LaunchException

      Create a new JNLPClassLoader from the specified file.
      Parameters:
        `file` - the JNLP file
      Throws:
        `LaunchException`

    - #### JNLPClassLoader

          protected JNLPClassLoader(JNLPFile file,
                         UpdatePolicy policy,
                         java.lang.String mainName)
                             throws LaunchException

      Create a new JNLPClassLoader from the specified file.
      Parameters:
        `file` - the JNLP file
        `policy` - the UpdatePolicy for this class loader
        `mainName` - name of the application's main class
      Throws:
        `LaunchException`

  - ### Method Detail

    - #### getInstance

          public static JNLPClassLoader getInstance(JNLPFile file,
                                    UpdatePolicy policy)
                                             throws LaunchException

      Returns a JNLP classloader for the specified JNLP file.
      Parameters:
        `file` - the file to load classes for
        `policy` - the update policy to use when downloading resources
      Throws:
        `LaunchException`

    - #### getInstance

          public static JNLPClassLoader getInstance(JNLPFile file,
                                    UpdatePolicy policy,
                                    java.lang.String mainName)
                                             throws LaunchException

      Returns a JNLP classloader for the specified JNLP file.
      Parameters:
        `file` - the file to load classes for
        `policy` - the update policy to use when downloading resources
        `mainName` - Overrides the main class name of the application
      Throws:
        `LaunchException`

    - #### getInstance

          public static JNLPClassLoader getInstance(java.net.URL location,
                                    java.lang.String uniqueKey,
                                    Version version,
                                    UpdatePolicy policy,
                                    java.lang.String mainName)
                                             throws java.io.IOException,
                                                    ParseException,
                                                    LaunchException

      Returns a JNLP classloader for the JNLP file at the specified location.
      Parameters:
        `location` - the file's location
        `version` - the file's version
        `policy` - the update policy to use when downloading resources
        `mainName` - Overrides the main class name of the application
      Throws:
        `java.io.IOException`
        `ParseException`
        `LaunchException`

    - #### hasMainJar

          public boolean hasMainJar()

      Returns true if this loader has the main jar

    - #### enableCodeBase

          public void enableCodeBase()

      Add applet's codebase URL. This allows compatibility with applets that load resources from their codebase instead of through JARs, but can slow down resource loading. Resources loaded from the codebase are not cached.

    - #### setApplication

          public void setApplication(ApplicationInstance app)

      Sets the JNLP app this group is for; can only be called once.

    - #### getApplication

          public ApplicationInstance getApplication()

      Returns the JNLP app for this classloader

    - #### getJNLPFile

          public JNLPFile getJNLPFile()

      Returns the JNLP file the classloader was created from.

    - #### getPermissions

          protected java.security.PermissionCollection getPermissions(java.security.CodeSource cs)

      Returns the permissions for the CodeSource.
      Overrides:
        `getPermissions` in class `java.net.URLClassLoader`

    - #### addPermission

          protected void addPermission(java.security.Permission p)

    - #### fillInPartJars

          protected void fillInPartJars(java.util.List<JARDesc> jars)

      Adds to the specified list of JARS any other JARs that need to be loaded at the same time as the JARs specified (ie, are in the same part).

    - #### activateJars

          protected void activateJars(java.util.List<JARDesc> jars)

      Ensures that the list of jars have all been transferred, and makes them available to the classloader. If a jar contains native code, the libraries will be extracted and placed in the path.
      Parameters:
        `jars` - the list of jars to load

    - #### activateNative

          protected void activateNative(JARDesc jar)

      Search for and enable any native code contained in a JAR by copying the native files into the filesystem. Called in the security context of the classloader.

    - #### getNativeDir

          protected java.io.File getNativeDir()

      Return the base directory to store native code files in. This method does not need to return the same directory across calls.

    - #### addNativeDirectory

          protected void addNativeDirectory(java.io.File nativeDirectory)

      Adds the `File` to the search path of this `JNLPClassLoader` when trying to find a native library

    - #### getNativeDirectories

          protected java.util.List<java.io.File> getNativeDirectories()

      Returns a list of all directories in the search path of the current classloader when it tires to find a native library.
      Returns:
        a list of directories in the search path for native libraries

    - #### findLibrary

          protected java.lang.String findLibrary(java.lang.String lib)

      Return the absolute path to the native library.
      Overrides:
        `findLibrary` in class `java.lang.ClassLoader`

    - #### findLibraryExt

          protected java.lang.String findLibraryExt(java.lang.String lib)

      Try to find the library path from another peer classloader.

    - #### findLoadedClassAll

          protected java.lang.Class findLoadedClassAll(java.lang.String name)

      Find the loaded class in this loader or any of its extension loaders.

    - #### loadClass

          public java.lang.Class<?> loadClass(java.lang.String name)
                                       throws java.lang.ClassNotFoundException

      Find a JAR in the shared 'extension' classloaders, this classloader, or one of the classloaders for the JNLP file's extensions.
      Overrides:
        `loadClass` in class `java.lang.ClassLoader`
      Throws:
        `java.lang.ClassNotFoundException`

    - #### findClass

          protected java.lang.Class findClass(java.lang.String name)
                                       throws java.lang.ClassNotFoundException

      Find the class in this loader or any of its extension loaders.
      Overrides:
        `findClass` in class `java.net.URLClassLoader`
      Throws:
        `java.lang.ClassNotFoundException`

    - #### findResource

          public java.net.URL findResource(java.lang.String name)

      Finds the resource in this, the parent, or the extension class loaders.
      Overrides:
        `findResource` in class `java.net.URLClassLoader`
      Returns:
        a `URL` for the resource, or `null` if the resource could not be found.

    - #### findResources

          public java.util.Enumeration<java.net.URL> findResources(java.lang.String name)
                                                            throws java.io.IOException

      Find the resources in this, the parent, or the extension class loaders. Load lazy resources if not found in current resources.
      Overrides:
        `findResources` in class `java.net.URLClassLoader`
      Throws:
        `java.io.IOException`

    - #### resourceAvailableLocally

          public boolean resourceAvailableLocally(java.lang.String s)

      Returns if the specified resource is available locally from a cached jar
      Parameters:
        `s` - The name of the resource
      Returns:
        Whether or not the resource is available locally

    - #### addAvailable

          protected void addAvailable()

      Adds whatever resources have already been downloaded in the background.

    - #### addNextResource

          protected JNLPClassLoader addNextResource()
                                             throws LaunchException

      Adds the next unused resource to the classloader. That resource and all those in the same part will be downloaded and added to the classloader before returning. If there are no more resources to add, the method returns immediately.
      Returns:
        the classloader that resources were added to, or null
      Throws:
        `LaunchException` - Thrown if the signed JNLP file, within the main jar, fails to be verified or does not match

    - #### getExtensionName

          @Deprecated
          public java.lang.String getExtensionName()

      Deprecated.

    - #### getExtensionHREF

          @Deprecated
          public java.lang.String getExtensionHREF()

      Deprecated.

    - #### getSigning

          public boolean getSigning()

    - #### getSecurity

          protected SecurityDesc getSecurity()

    - #### getCodeSourceSecurity

          protected SecurityDesc getCodeSourceSecurity(java.net.URL source)

      Returns the security descriptor for given code source URL
      Parameters:
        `source` - the origin (remote) url of the code
      Returns:
        The SecurityDescriptor for that source

    - #### decrementLoaderUseCount

          public void decrementLoaderUseCount()

      Decrements loader use count by 1 If count reaches 0, loader is removed from list of available loaders
      Throws:
        `java.lang.SecurityException` - if caller is not trusted

    - #### getAccessControlContextForClassLoading

          public java.security.AccessControlContext getAccessControlContextForClassLoading()

      Returns an appropriate AccessControlContext for loading classes in the running instance. The default context during class-loading only allows connection to codebase. However applets are allowed to load jars from arbitrary locations and the codebase only access falls short if a class from one location needs a class from another. Given protected access since CodeBaseClassloader uses this function too.
      Returns:
        The appropriate AccessControlContext for loading classes for this instance

Submit a bug or feature