Class PluginLoader

All Implemented Interfaces:
Closeable, AutoCloseable

public class PluginLoader extends URLClassLoader
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.
  • Constructor Details

    • PluginLoader

      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 - The JarFile to load the Plugins from.
      Throws:
      MalformedURLException - Will throw this exception if jf does not refer to a legitimate Jar file.
  • Method Details

    • findLibrary

      protected String findLibrary(String libname)
      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.
      Overrides:
      findLibrary in class ClassLoader
      Parameters:
      libname - The JNI name of the native library to locate.
      Returns:
      Returns a string describing the actual loation of the native library in the native file system.
    • attemptPluginDefine

      public boolean attemptPluginDefine(Class 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 - The potential plug-in class to vette.
      Returns:
      Returns true if the class meets the criteria for a plugin. Otherwise returns false.