aboutsummaryrefslogtreecommitdiffstats
path: root/coreAPI
diff options
context:
space:
mode:
authorendolf <[email protected]>2007-06-10 15:03:27 +0000
committerendolf <[email protected]>2007-06-10 15:03:27 +0000
commitde335a22ccd4056a3e12192ba8f3254fd327b4cd (patch)
treefe3c7c14775ca2bb3a7e90b29fe519c3d4056e23 /coreAPI
parentf8ed18121deed1c97e28f229406a82bc980d8386 (diff)
Implement the isSupported method and make plugins work again. There was an issue where accessing the static methods in DefaultControllerEnvironment and ControllerEnvironment would cause ploblems when the plugins were loaded using the PluginLoader class loader.
git-svn-id: file:///home/sven/projects/JOGL/git-svn/svn-server-sync/jinput/trunk@187 e343933a-64c8-49c5-92b1-88f2ce3e89e8
Diffstat (limited to 'coreAPI')
-rw-r--r--coreAPI/src/java/net/java/games/input/ControllerEnvironment.java10
-rw-r--r--coreAPI/src/java/net/java/games/input/DefaultControllerEnvironment.java80
2 files changed, 56 insertions, 34 deletions
diff --git a/coreAPI/src/java/net/java/games/input/ControllerEnvironment.java b/coreAPI/src/java/net/java/games/input/ControllerEnvironment.java
index c7a4a42..db6f1dc 100644
--- a/coreAPI/src/java/net/java/games/input/ControllerEnvironment.java
+++ b/coreAPI/src/java/net/java/games/input/ControllerEnvironment.java
@@ -38,6 +38,9 @@
*****************************************************************************/
package net.java.games.input;
+import java.io.File;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
import java.util.ArrayList;
import java.util.Iterator;
@@ -106,6 +109,13 @@ public abstract class ControllerEnvironment {
}
/**
+ * Returns the isSupported status of this environment.
+ * What makes an environment supported or not is up to the
+ * particular plugin, but may include OS or available hardware.
+ */
+ public abstract boolean isSupported();
+
+ /**
* Removes a listener for controller state change events.
*/
public void removeControllerListener(ControllerListener l) {
diff --git a/coreAPI/src/java/net/java/games/input/DefaultControllerEnvironment.java b/coreAPI/src/java/net/java/games/input/DefaultControllerEnvironment.java
index 544562a..098a1cf 100644
--- a/coreAPI/src/java/net/java/games/input/DefaultControllerEnvironment.java
+++ b/coreAPI/src/java/net/java/games/input/DefaultControllerEnvironment.java
@@ -41,6 +41,7 @@ package net.java.games.input;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
+import java.lang.reflect.Method;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.ArrayList;
@@ -57,18 +58,8 @@ import net.java.games.util.plugins.*;
* @author Michael Martak
*/
class DefaultControllerEnvironment extends ControllerEnvironment {
- /**
- * Location of the LIB directory.
- */
- static String libPath;
-
- /**
- * List of all controllers in this environment
- */
- private ArrayList controllers;
-
- private Collection loadedPlugins = new ArrayList();
-
+ static String libPath;
+
/**
* Static utility method for loading native libraries.
* It will try to load from either the path given by
@@ -90,28 +81,36 @@ class DefaultControllerEnvironment extends ControllerEnvironment {
});
}
- /**
- * Public no-arg constructor.
- */
- 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) {
+ static String getPrivilegedProperty(final String property) {
+ return (String)AccessController.doPrivileged(new PrivilegedAction() {
+ public Object run() {
+ return System.getProperty(property);
+ }
+ });
+ }
+
+
+ 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);
}
});
}
-
+
+ /**
+ * List of all controllers in this environment
+ */
+ private ArrayList controllers;
+
+ private Collection loadedPlugins = new ArrayList();
+
+ /**
+ * Public no-arg constructor.
+ */
+ public DefaultControllerEnvironment() {
+ }
+
/**
* Returns a list of all controllers available to this environment,
* or an empty array if there are no controllers in this environment.
@@ -147,15 +146,20 @@ class DefaultControllerEnvironment extends ControllerEnvironment {
System.out.println("Trying to use default plugin, OS name " + osName +" not recognised");
}
}
- ArrayList pluginClassList = new ArrayList();
+
StringTokenizer pluginClassTok = new StringTokenizer(pluginClasses, " \t\n\r\f,;:");
while(pluginClassTok.hasMoreTokens()) {
String className = pluginClassTok.nextToken();
try {
if(!loadedPlugins.contains(className)) {
- Class ceClass = Class.forName(className);
+ Class ceClass = Class.forName(className);
ControllerEnvironment ce = (ControllerEnvironment) ceClass.newInstance();
- addControllers(ce.getControllers());
+ if(ce.isSupported()) {
+ addControllers(ce.getControllers());
+ loadedPlugins.add(ce.getClass().getName());
+ } else {
+ logln(ceClass.getName() + " is not supported");
+ }
}
} catch (Throwable e) {
e.printStackTrace();
@@ -199,9 +203,13 @@ class DefaultControllerEnvironment extends ControllerEnvironment {
envClasses[i].getName()
+" loaded by "+envClasses[i].getClassLoader());
ControllerEnvironment ce = (ControllerEnvironment)
- envClasses[i].newInstance();
- addControllers(ce.getControllers());
- loadedPlugins.add(ce.getClass().getName());
+ envClasses[i].newInstance();
+ if(ce.isSupported()) {
+ addControllers(ce.getControllers());
+ loadedPlugins.add(ce.getClass().getName());
+ } else {
+ logln(envClasses[i].getName() + " is not supported");
+ }
} catch (Throwable e) {
e.printStackTrace();
}
@@ -219,4 +227,8 @@ class DefaultControllerEnvironment extends ControllerEnvironment {
controllers.add(c[i]);
}
}
+
+ public boolean isSupported() {
+ return true;
+ }
}