On 10/28/06, Rony G. Flatscher <[EMAIL PROTECTED]> wrote:
<http://wi.wu-wien.ac.at/rgf/rexx/bsf4rexx/docs/docs.apache.bsf/org/apache/bsf/BSFEngine.html>)
and what they are meant for:
1. "exec(...)": Java coder needs to execute a script, there are
no arguments to be passed to the script nor is there any
return value expected,
2. "eval(...)": Java coder wants to evaluate a script, does not
need to supply any arguments, but expects a return value,
3. "apply(...)": Java coder needs to execute a script, needs to
supply arguments to the script and *is* expecting a return
value,
4. "call(...)": Java coder wants to invoke a method in a
script, supplying arguments and expecting a return value.
So you see, your patch would only alleviate the class reference issue in
the Jython engine for case # 1, where it probably could also help in
cases #2 and #3. (Maybe also for a "compileScript(...)" method if that
makes sense in the context of Jython.)
case #4 doesn't seem relevant for my patch... here's a patch for case
#1 to #3 to import packages
--- JythonEngine.java 2006-10-29 14:57:12.000000000 +0800
+++
/home/son/download/tmp/bsf-2.4.0/src/org/apache/bsf/engines/jython/JythonEngine.java
2006-10-06 23:53:00.000000000 +0800
@@ -16,11 +16,8 @@
package org.apache.bsf.engines.jython;
-import java.beans.PropertyChangeEvent;
import java.io.ByteArrayInputStream;
import java.util.Vector;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
import org.apache.bsf.BSFDeclaredBean;
import org.apache.bsf.BSFException;
@@ -31,7 +28,6 @@
import org.python.core.PyException;
import org.python.core.PyJavaInstance;
import org.python.core.PyObject;
-import org.python.core.PySystemState;
import org.python.util.InteractiveInterpreter;
/**
@@ -45,7 +41,6 @@
public class JythonEngine extends BSFEngineImpl {
BSFPythonInterpreter interp;
- private final static Pattern fromRegExp = Pattern.compile("from ([.^\\S]*)");
/**
* call the named method of the given object.
@@ -111,9 +106,7 @@
index++;
}
- String scriptStr = script.toString ();
- importPackage(scriptStr);
- interp.exec (scriptStr);
+ interp.exec (script.toString ());
Object result = interp.eval ("bsf_temp_fn()");
@@ -132,9 +125,7 @@
public Object eval (String source, int lineNo, int columnNo,
Object script) throws BSFException {
try {
- String scriptStr = byteify(script.toString ());
- importPackage(scriptStr);
- Object result = interp.eval (scriptStr);
+ Object result = interp.eval (byteify(script.toString ()));
if (result != null && result instanceof PyJavaInstance)
result = ((PyJavaInstance)result).__tojava__(Object.class);
return result;
@@ -150,30 +141,19 @@
public void exec (String source, int lineNo, int columnNo,
Object script) throws BSFException {
try {
- String scriptStr = byteify(script.toString());
- importPackage(scriptStr);
- interp.exec (scriptStr);
+ interp.exec (byteify(script.toString ()));
} catch (PyException e) {
throw new BSFException (BSFException.REASON_EXECUTION_ERROR,
"exception from Jython:\n" + e, e);
}
}
- private void importPackage(String script) {
- Matcher matcher = fromRegExp.matcher(script);
- while (matcher.find()) {
- String packageName = matcher.group(1);
- PySystemState.add_package(packageName);
- }
- }
-
/**
* Execute script code, emulating console interaction.
*/
public void iexec (String source, int lineNo, int columnNo,
Object script) throws BSFException {
String scriptStr = byteify(script.toString());
- importPackage(scriptStr);
int newline = scriptStr.indexOf("\n");
if (newline > -1)
@@ -261,15 +241,4 @@
}
}
}
-
-
- public void propertyChange(PropertyChangeEvent e) {
- super.propertyChange(e);
- String name = e.getPropertyName();
- Object value = e.getNewValue();
- if (name.equals("classLoader")) {
- Py.getSystemState().setClassLoader((ClassLoader) value);
- }
-
- }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]