diff options
-rw-r--r-- | coreAPI/src/java/net/java/games/input/DefaultControllerEnvironment.java | 130 | ||||
-rw-r--r-- | plugins/linux/src/java/net/java/games/input/LinuxEnvironmentPlugin.java | 32 |
2 files changed, 50 insertions, 112 deletions
diff --git a/coreAPI/src/java/net/java/games/input/DefaultControllerEnvironment.java b/coreAPI/src/java/net/java/games/input/DefaultControllerEnvironment.java index 9507bd2..544562a 100644 --- a/coreAPI/src/java/net/java/games/input/DefaultControllerEnvironment.java +++ b/coreAPI/src/java/net/java/games/input/DefaultControllerEnvironment.java @@ -57,20 +57,6 @@ import net.java.games.util.plugins.*; * @author Michael Martak */ class DefaultControllerEnvironment extends ControllerEnvironment { - static final boolean DEBUG =false; - /** - * The name of the properties file to find plugins. - */ - private final static String PROPERTY_FILENAME = - "controller.properties"; - - /** - * The name of the property for identifying a plugin (used - * as the value, the key being the class name). - */ - private final static String ID_PLUGIN = - "ControllerEnvironment"; - /** * Location of the LIB directory. */ @@ -81,16 +67,6 @@ class DefaultControllerEnvironment extends ControllerEnvironment { */ private ArrayList controllers; - /** - * Plug-in properties. - */ - private Properties properties = new Properties(); - - /** - * Plug-in class loader. - */ - private PluginClassLoader pluginLoader = new PluginClassLoader(); - private Collection loadedPlugins = new ArrayList(); /** @@ -120,6 +96,22 @@ class DefaultControllerEnvironment extends ControllerEnvironment { public DefaultControllerEnvironment() { } + private static String getPrivilegedProperty(final String property) { + return (String)AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + return System.getProperty(property); + } + }); + } + + private static String getPrivilegedProperty(final String property, final String default_value) { + return (String)AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + return System.getProperty(property, default_value); + } + }); + } + /** * Returns a list of all controllers available to this environment, * or an empty array if there are no controllers in this environment. @@ -131,13 +123,13 @@ class DefaultControllerEnvironment extends ControllerEnvironment { AccessController.doPrivileged(new PrivilegedAction() { public Object run() { scanControllers(); - return DefaultControllerEnvironment.this; + return null; } }); //Check the properties for specified controller classes - String pluginClasses = System.getProperty("jinput.plugins", "") + " " + System.getProperty("net.java.games.input.plugins", ""); - if(!System.getProperty("jinput.useDefaultPlugin", "true").toLowerCase().trim().equals("false") && !System.getProperty("net.java.games.input.useDefaultPlugin", "true").toLowerCase().trim().equals("false")) { - String osName = System.getProperty("os.name", "").trim(); + String pluginClasses = getPrivilegedProperty("jinput.plugins", "") + " " + getPrivilegedProperty("net.java.games.input.plugins", ""); + if(!getPrivilegedProperty("jinput.useDefaultPlugin", "true").toLowerCase().trim().equals("false") && !getPrivilegedProperty("net.java.games.input.useDefaultPlugin", "true").toLowerCase().trim().equals("false")) { + String osName = getPrivilegedProperty("os.name", "").trim(); if(osName.equals("Linux")) { pluginClasses = pluginClasses + " net.java.games.input.LinuxEnvironmentPlugin"; } else if(osName.equals("Mac OS X")) { @@ -180,53 +172,16 @@ class DefaultControllerEnvironment extends ControllerEnvironment { return ret; } - /** - * Scans for controllers, placing them in the controllers list. - */ - /* This is Mike's old plugin code. - private void scanControllers() { - // Load properties object. - try { - loadProperties(); - } catch (IOException e) { - // Could not find or read file, simply return. - return; - } - // Create a list of ControllerEnvironment classes. - // For each ControllerEnvironment, locate the class - // using the plugin class loader. - Iterator it = properties.keySet().iterator(); - while (it.hasNext()) { - Object key = it.next(); - assert key != null; - Object value = properties.get(key); - assert value != null; - if (value.equals(ID_PLUGIN)) { - try { - ControllerEnvironment plugin = - newPlugin(key.toString()); - addControllers(plugin.getControllers()); - } catch (Throwable t) { - System.err.println( - "Warning : could not load plugin " + - key.toString() + ", received exeption " + - t.toString()); - t.printStackTrace(System.err); - } - } - } - }*/ - /* This is jeff's new plugin code using Jeff's Plugin manager */ private void scanControllers() { - String pluginPathName = System.getProperty("jinput.controllerPluginPath"); + String pluginPathName = getPrivilegedProperty("jinput.controllerPluginPath"); if(pluginPathName == null) { pluginPathName = "controller"; } - scanControllersAt(System.getProperty("java.home") + + scanControllersAt(getPrivilegedProperty("java.home") + File.separator + "lib"+File.separator + pluginPathName); - scanControllersAt(System.getProperty("user.dir")+ + scanControllersAt(getPrivilegedProperty("user.dir")+ File.separator + pluginPathName); } @@ -240,13 +195,11 @@ class DefaultControllerEnvironment extends ControllerEnvironment { Class[] envClasses = plugins.getExtends(ControllerEnvironment.class); for(int i=0;i<envClasses.length;i++){ try { - if (DEBUG) { - System.out.println("ControllerEnvironment "+ + ControllerEnvironment.logln("ControllerEnvironment "+ envClasses[i].getName() +" loaded by "+envClasses[i].getClassLoader()); - } ControllerEnvironment ce = (ControllerEnvironment) - envClasses[i].newInstance(); + envClasses[i].newInstance(); addControllers(ce.getControllers()); loadedPlugins.add(ce.getClass().getName()); } catch (Throwable e) { @@ -259,39 +212,6 @@ class DefaultControllerEnvironment extends ControllerEnvironment { } /** - * Retrieve the file "lib/control.properties" and - * load properties into properties object. - */ - private void loadProperties() throws IOException { - if (libPath == null) { - libPath = System.getProperty("java.home") + - File.separator + "lib"; - } - File file = new File(libPath + File.separator + - PROPERTY_FILENAME); - FileInputStream inputStream = new FileInputStream(file); - properties.load(inputStream); - inputStream.close(); - } - - /** - * Create a new plugin ControllerEnvironment object - */ - /* - private ControllerEnvironment newPlugin(String name) throws - ClassNotFoundException, InstantiationException, - IllegalAccessException { - Class pluginClass = pluginLoader.loadClass(name); - if (!ControllerEnvironment.class.isAssignableFrom(pluginClass)) { - throw new ClassCastException( - "Plugin class must be assignable from " + - ControllerEnvironment.class.getName()); - } - Object instance = pluginClass.newInstance(); - return (ControllerEnvironment)instance; - } - */ - /** * Add the array of controllers to our list of controllers. */ private void addControllers(Controller[] c) { diff --git a/plugins/linux/src/java/net/java/games/input/LinuxEnvironmentPlugin.java b/plugins/linux/src/java/net/java/games/input/LinuxEnvironmentPlugin.java index 69ab966..513c85d 100644 --- a/plugins/linux/src/java/net/java/games/input/LinuxEnvironmentPlugin.java +++ b/plugins/linux/src/java/net/java/games/input/LinuxEnvironmentPlugin.java @@ -296,7 +296,8 @@ public final class LinuxEnvironmentPlugin extends ControllerEnvironment implemen for (int i = 0; i < joystick_device_files.length; i++) { File event_file = joystick_device_files[i]; try { - LinuxJoystickDevice device = new LinuxJoystickDevice(event_file.getAbsolutePath()); + String path = getAbsolutePathPrivileged(event_file); + LinuxJoystickDevice device = new LinuxJoystickDevice(path); Controller controller = createJoystickFromJoystickDevice(device); if (controller != null) { controllers.add(controller); @@ -309,18 +310,34 @@ public final class LinuxEnvironmentPlugin extends ControllerEnvironment implemen } } - private final static File[] enumerateJoystickDeviceFiles(String dev_path) { - File dev = new File(dev_path); - return dev.listFiles(new FilenameFilter() { + private final static File[] enumerateJoystickDeviceFiles(final String dev_path) { + final File dev = new File(dev_path); + return listFilesPrivileged(dev, new FilenameFilter() { public final boolean accept(File dir, String name) { return name.startsWith("js"); } }); } + private static String getAbsolutePathPrivileged(final File file) { + return (String)AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + return file.getAbsolutePath(); + } + }); + } + + private static File[] listFilesPrivileged(final File dir, final FilenameFilter filter) { + return (File[])AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + return dir.listFiles(filter); + } + }); + } + private final void enumerateEventControllers(List controllers) { - File dev = new File("/dev/input"); - File[] event_device_files = dev.listFiles(new FilenameFilter() { + final File dev = new File("/dev/input"); + File[] event_device_files = listFilesPrivileged(dev, new FilenameFilter() { public final boolean accept(File dir, String name) { return name.startsWith("event"); } @@ -330,7 +347,8 @@ public final class LinuxEnvironmentPlugin extends ControllerEnvironment implemen for (int i = 0; i < event_device_files.length; i++) { File event_file = event_device_files[i]; try { - LinuxEventDevice device = new LinuxEventDevice(event_file.getAbsolutePath()); + String path = getAbsolutePathPrivileged(event_file); + LinuxEventDevice device = new LinuxEventDevice(path); try { Controller controller = createControllerFromDevice(device); if (controller != null) { |