Hello, I've attached a patch to BSFManager.java which will allow BSFEngine implementations to be automatically registered simply by including their jar in the classpath.
The change that I made was to allow BSFManager.java to search through all jars in the classpath for org/apache/bsf/Languages.properties files, rather than simply finding the first match. This means that BSFEngine implementations which are distributed separately from BSF can include within their jar an additional Languages.properties file that specifies only their own class name. For example: [bsf.jar] org/apache/bsf/Languages.properties: javascript = org.apache.bsf.engines.javascript.JavaScriptEngine, js ... perl = org.apache.bsf.engines.perl.PerlEngine, pl ... [bsfperl.jar] org/apache/bsf/Languages.properties: bsfperl = net.sourceforge.bsfperl.PerlEngineImpl, pl If BSFManager is run with the above two jars in the classpath, it will read both Languages.properties files. It will also resolve the "pl" extension to the "bsfperl" language, because the "org.apache.bsf.engines.perl.PerlEngine" class is not located in the classpath, but "net.sourceforge.bsfperl.PerlEngineImpl" is. This change should be entirely backwards-compatible. Thanks, Don
--- BSFManager.java 2004-08-06 23:49:31.000000000 -0500 +++ BSFManager.java.new 2004-08-06 23:44:03.000000000 -0500 @@ -59,6 +59,7 @@ import java.io.*; import java.beans.*; import java.security.*; +import java.net.URL; import org.apache.bsf.util.*; import org.apache.bsf.util.DebugLog; @@ -126,28 +127,38 @@ static { try { - ResourceBundle rb = - ResourceBundle.getBundle("org.apache.bsf.Languages"); - Enumeration keys = rb.getKeys(); - - while (keys.hasMoreElements()) { - String key = (String) keys.nextElement(); - String value = rb.getString(key); + Enumeration e = BSFManager.class.getClassLoader().getResources("org/apache/bsf/Languages.properties"); + while (e.hasMoreElements()) { + URL url = (URL)e.nextElement(); + InputStream is = url.openStream(); + + Properties p = new Properties(); + p.load(is); + + Enumeration keys = p.propertyNames(); + while (keys.hasMoreElements()) { + String key = (String) keys.nextElement(); + String value = p.getProperty(key); - StringTokenizer tokens = new StringTokenizer(value, ","); - String className = (String) tokens.nextToken(); + StringTokenizer tokens = new StringTokenizer(value, ","); + String className = (String) tokens.nextToken(); - // get the extensions for this language - String exts = (String) tokens.nextToken(); - StringTokenizer st = new StringTokenizer(exts, "|"); - String[] extensions = new String[st.countTokens()]; - for (int i = 0; st.hasMoreTokens(); i++) { - extensions[i] = ((String) st.nextToken()).trim(); + // get the extensions for this language + String exts = (String) tokens.nextToken(); + StringTokenizer st = new StringTokenizer(exts, "|"); + String[] extensions = new String[st.countTokens()]; + for (int i = 0; st.hasMoreTokens(); i++) { + extensions[i] = ((String) st.nextToken()).trim(); + } + + registerScriptingEngine(key, className, extensions); } - - registerScriptingEngine(key, className, extensions); } } + catch (IOException ex) { + ex.printStackTrace(); + System.err.println("Error reading Languages file " + ex); + } catch (NoSuchElementException nsee) { nsee.printStackTrace(); System.err.println("Syntax error in Languages resource bundle");
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]