Package 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:
Closeable
,AutoCloseable
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 ClassesModifier and TypeClassDescriptionstatic class
static enum
Actions to specify how cache is to be managed *static interface
SecurityDelegate, in real usage, relies on having a "parent" JNLPClassLoader instance.static class
Handles security decision logic for the JNLPClassLoader, eg which permission level to assign to JARs.static enum
-
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
JNLPClassLoader
(JNLPFile file, UpdatePolicy policy) Create a new JNLPClassLoader from the specified file.protected
JNLPClassLoader
(JNLPFile file, UpdatePolicy policy, String mainName, boolean enableCodeBase) Create a new JNLPClassLoader from the specified file. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
activateJars
(List<JARDesc> jars) Ensures that the list of jars have all been transferred, and makes them available to the classloader.protected void
Adds whatever resources have already been downloaded in the background.protected JNLPClassLoader
Adds the next unused resource to the classloader.protected void
checkForAttributeInJars
(List<JARDesc> jars, Attributes.Name name) * Checks for the jar that contains the attribute.void
Decrements loader use count by 1 If count reaches 0, loader is removed from list of available loadersvoid
Add applet's codebase URL.protected void
fillInPartJars
(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 Class
<?> Find the class in this loader or any of its extension loaders.protected String
findLibrary
(String lib) Return the absolute path to the native library.protected String
findLibraryExt
(String lib) Try to find the library path from another peer classloader.protected Class
<?> findLoadedClassAll
(String name) Find the loaded class in this loader or any of its extension loaders.findResource
(String name) Finds the resource in this, the parent, or the extension class loaders.findResources
(String name) Find the resources in this, the parent, or the extension class loaders.Returns an appropriate AccessControlContext for loading classes in the running instance.protected SecurityDesc
getCodeSourceSecurity
(URL source) Returns the security descriptor for given code source URLDeprecated.Deprecated.static JNLPClassLoader
getInstance
(URL location, String uniqueKey, Version version, ParserSettings settings, UpdatePolicy policy, String mainName, boolean enableCodeBase) Returns a JNLP classloader for the JNLP file at the specified location.static JNLPClassLoader
getInstance
(JNLPFile file, UpdatePolicy policy, boolean enableCodeBase) Returns a JNLP classloader for the specified JNLP file.static JNLPClassLoader
getInstance
(JNLPFile file, UpdatePolicy policy, String mainName, boolean enableCodeBase) Returns a JNLP classloader for the specified JNLP file.getManifestAttribute
(URL location, Attributes.Name attribute) Gets the name of the main method if specified in the manifestprotected PermissionCollection
Returns the permissions for the CodeSource.protected SecurityDesc
boolean
boolean
static boolean
boolean
isStrict()
Class
<?> Find a JAR in the shared 'extension' classloaders, this classloader, or one of the classloaders for the JNLP file's extensions.boolean
Returns if the specified resource is available locally from a cached jarvoid
Sets the JNLP app this group is for; can only be called once.void
boolean
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, findClass, findLoadedClass, findResource, findSystemClass, getClassLoadingLock, getDefinedPackage, getDefinedPackages, getName, getPackage, getPackages, getParent, getPlatformClassLoader, getResource, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, getUnnamedModule, isRegisteredAsParallelCapable, loadClass, registerAsParallelCapable, resolveClass, resources, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners
-
Field Details
-
TEMPLATE
Signed JNLP File and Template- See Also:
-
APPLICATION
- See Also:
-
-
Constructor Details
-
JNLPClassLoader
Create a new JNLPClassLoader from the specified file.- Parameters:
file
- the JNLP filepolicy
- update policy of loader- Throws:
LaunchException
- if app can not be loaded
-
JNLPClassLoader
protected JNLPClassLoader(JNLPFile file, UpdatePolicy policy, String mainName, boolean enableCodeBase) throws LaunchException Create a new JNLPClassLoader from the specified file.- Parameters:
file
- the JNLP filepolicy
- the UpdatePolicy for this class loadermainName
- name of the application's main classenableCodeBase
- switch whether this classloader can search in codebase or not- Throws:
LaunchException
- when need to kill an app comes.
-
-
Method Details
-
isCertUnderestimated
public static boolean isCertUnderestimated() -
isStrict
public boolean isStrict() -
getInstance
public static JNLPClassLoader getInstance(JNLPFile file, UpdatePolicy policy, boolean enableCodeBase) throws LaunchException Returns a JNLP classloader for the specified JNLP file.- Parameters:
file
- the file to load classes forpolicy
- the update policy to use when downloading resourcesenableCodeBase
- true if codebase can be searched (ok for applets,false for apps)- Returns:
- existing classloader. creates new if none reliable exists
- Throws:
LaunchException
- when launch is doomed
-
getInstance
public static JNLPClassLoader getInstance(JNLPFile file, UpdatePolicy policy, String mainName, boolean enableCodeBase) throws LaunchException Returns a JNLP classloader for the specified JNLP file.- Parameters:
file
- the file to load classes forpolicy
- the update policy to use when downloading resourcesmainName
- Overrides the main class name of the applicationenableCodeBase
- ue if codebase can be searched (ok for applets,false for apps)- Returns:
- existing classloader. creates new if none reliable exists
- Throws:
LaunchException
- when launch is doomed
-
getInstance
public static JNLPClassLoader getInstance(URL location, String uniqueKey, Version version, ParserSettings settings, UpdatePolicy policy, String mainName, boolean enableCodeBase) throws IOException, ParseException, LaunchException Returns a JNLP classloader for the JNLP file at the specified location.- Parameters:
location
- the file's locationuniqueKey
- key to manage applets/applications in shared vmversion
- the file's versionsettings
- settings of parserpolicy
- the update policy to use when downloading resourcesmainName
- Overrides the main class name of the applicationenableCodeBase
- whether to enable codebase search or not- Returns:
- classlaoder of this appp
- Throws:
IOException
- when IO failsParseException
- when parsing failsLaunchException
- when launch is doomed
-
checkForAttributeInJars
* Checks for the jar that contains the attribute.- Parameters:
jars
- Jars that are checked to see if they contain the main classname
- attribute to be found- Returns:
- value of attribute if found
-
getManifestAttribute
Gets the name of the main method if specified in the manifest- Parameters:
location
- The JAR locationattribute
- name of the attribute to find- Returns:
- the attribute value, null if there isn't one of if there was an error
-
hasMainJar
public boolean hasMainJar()- Returns:
- true if this loader has the main jar
-
setRunInSandbox
- Throws:
LaunchException
-
userPromptedForSandbox
public boolean userPromptedForSandbox() -
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
Sets the JNLP app this group is for; can only be called once.- Parameters:
app
- application to be ser to this group
-
getApplication
- Returns:
- the JNLP app for this classloader
-
getJNLPFile
- Returns:
- the JNLP file the classloader was created from.
-
getPermissions
Returns the permissions for the CodeSource.- Overrides:
getPermissions
in classURLClassLoader
-
addPermission
-
fillInPartJars
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).- Parameters:
jars
- jar archives to be added
-
activateJars
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
-
findLibrary
Return the absolute path to the native library.- Overrides:
findLibrary
in classClassLoader
-
findLibraryExt
Try to find the library path from another peer classloader.- Parameters:
lib
- library to be found- Returns:
- location of library
-
findLoadedClassAll
Find the loaded class in this loader or any of its extension loaders.- Parameters:
name
- name of class- Returns:
- the class found by name
-
loadClass
Find a JAR in the shared 'extension' classloaders, this classloader, or one of the classloaders for the JNLP file's extensions. This method used to be qualified "synchronized." This was done solely for the purpose of ensuring only one thread entered the method at a time. This was not strictly necessary - ensuring that all affected fields are thread-safe is sufficient. Locking on the JNLPClassLoader instance when this method is called can result in deadlock if another thread is dealing with the CodebaseClassLoader at the same time. This solution is very heavy-handed as the instance lock is not truly required, and taking the lock on the classloader instance when not needed is not in general a good idea because it can and will lead to deadlock when multithreaded classloading is in effect. The solution is to keep the fields thread safe on their own. This is accomplished by wrapping them in Collections.synchronized* to provide atomic add/remove operations, and synchronizing on them when iterating or performing multiple mutations. See bug report RH976833. On some systems this bug will manifest itself as deadlock on every webpage with more than one Java applet, potentially also causing the browser process to hang. More information in the mailing list archives: http://mail.openjdk.java.net/pipermail/distro-pkg-dev/2013-September/024536.html Affected fields: available, classpaths, jarIndexes, jarEntries, jarLocationSecurityMap- Overrides:
loadClass
in classClassLoader
- Throws:
ClassNotFoundException
-
findClass
Find the class in this loader or any of its extension loaders.- Overrides:
findClass
in classURLClassLoader
- Throws:
ClassNotFoundException
-
findResource
Finds the resource in this, the parent, or the extension class loaders.- Overrides:
findResource
in classURLClassLoader
- Returns:
- a
URL
for the resource, ornull
if the resource could not be found.
-
findResources
Find the resources in this, the parent, or the extension class loaders. Load lazy resources if not found in current resources.- Overrides:
findResources
in classURLClassLoader
- Throws:
IOException
-
resourceAvailableLocally
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
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.- Returns:
- title if available. Substitutions if not.
-
getExtensionHREF
Deprecated.- Returns:
- location if jnlp
-
getSigning
public boolean getSigning() -
getSigningState
-
getSecurity
-
getCodeSourceSecurity
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:
SecurityException
- if caller is not trusted
-
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
-
getMainClass
-