Top Description Fields Constructors Methods
net.java.games.util.plugins

public Class PluginLoader

extends URLClassLoader
Class Inheritance
Imports
java.io.*, java.net.*

This class is used internally by the Plugin system. End users of the system are unlikely to need to be aware of it. This is the class loader used to keep the namespaces of different plugins isolated from each other and from the main app code. One plugin loader is created per Jar file in the sub-directory tree of the plugin directory. In addition to isolating java classes this loader also isolates DLLs such that plugins with conflicting DLL names may be used by simply placing the plugin and its associated DLL in a sub-folder of its own. This class also currently implements methods for testing classes for inheritance of superclasses or interfaces. This code is genericly useful and should really be moved to a seperate ClassUtils class.
Author
Jeffrey Kesselman

Field Summary

Modifier and TypeField and Description
pack-priv static final boolean
pack-priv boolean
pack-priv File

Constructor Summary

AccessConstructor and Description
public
PluginLoader(File
The JarFile to load the Plugins from.
jf
)

Creates a new instance of PluginLodaer If the system property "net.java.games.util.plugins.nolocalnative" is not set then the laoder will look for requried native libs in the same directory as the plugin jar.

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

Returns true if the class meets the criteria for a plugin. Otherwise returns false.
attemptPluginDefine
(Class<T>
The potential plug-in class to vette.
pc
)

This function is called as part of scanning the Jar for plugins.

private boolean
protected String

Returns:

Returns a string describing the actual loation of the native library in the native file system.
findLibrary
(String
The JNI name of the native library to locate.
libname
)

Overrides java.lang.ClassLoader.findLibrary.

This method is queried by the System.loadLibrary() code to find the actual native name and path to the native library to load.
Inherited from java.net.URLClassLoader:
addURLclosedefinePackagefindClassfindResourcefindResourcesgetPermissionsgetResourceAsStreamgetURLsnewInstancenewInstance

Field Detail

DEBUGback to summary
pack-priv static final boolean DEBUG
localDLLsback to summary
pack-priv boolean localDLLs
parentDirback to summary
pack-priv File parentDir

Constructor Detail

PluginLoaderback to summary
public PluginLoader(File jf) throws MalformedURLException

Creates a new instance of PluginLodaer If the system property "net.java.games.util.plugins.nolocalnative" is not set then the laoder will look for requried native libs in the same directory as the plugin jar. (Useful for handling name collision between plugins). If it IS set however, then it will fall back to the default way of loading natives. (Necessary for Java Web Start.)

Parameters
jf:File

The JarFile to load the Plugins from.

Exceptions
MalformedURLException:
Will throw this exception if jf does not refer to a legitimate Jar file.

Method Detail

attemptPluginDefineback to summary
public boolean attemptPluginDefine(Class<T> pc)

This function is called as part of scanning the Jar for plugins. It checks to make sure the class passed in is a legitimate plugin, which is to say that it meets the following criteria: (1) Is not itself an interface (2) Implements the Plugin marker interface either directly or through inheritance. interface, either

Parameters
pc:Class<T>

The potential plug-in class to vette.

Returns:boolean

Returns true if the class meets the criteria for a plugin. Otherwise returns false.

classImplementsPluginback to summary
private boolean classImplementsPlugin(Class<T> testClass)
findLibraryback to summary
protected String findLibrary(String libname)

Overrides java.lang.ClassLoader.findLibrary.

This method is queried by the System.loadLibrary() code to find the actual native name and path to the native library to load. This subclass implementation of this method ensures that the native library will be loaded from, and only from, the parent directory of the Jar file this loader was created to support. This allows different Plugins with supporting DLLs of the same name to co-exist, each in their own subdirectory. Setting the global "localDLLs" by setting the property net.java.games.util.plugins.nolocalnative defeats this behavior. This is necessary for Java Web Start apps which have strong restrictions on where and how native libs can be loaded.

Parameters
libname:String

The JNI name of the native library to locate.

Returns:String

Returns a string describing the actual loation of the native library in the native file system.