This is an automated email from the ASF dual-hosted git repository.
garydgregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-bsf.git
The following commit(s) were added to refs/heads/master by this push:
new 0f6cd82 Sort members
0f6cd82 is described below
commit 0f6cd822c1e86d1f24d2ac3fd56ec76d38edd08e
Author: Gary Gregory <[email protected]>
AuthorDate: Wed Jul 15 14:23:59 2026 -0400
Sort members
---
src/main/java/org/apache/bsf/BSFManager.java | 386 ++++++++++-----------
src/main/java/org/apache/bsf/BSF_Log.java | 232 ++++++-------
src/main/java/org/apache/bsf/BSF_LogFactory.java | 10 +-
.../org/apache/bsf/engines/java/JavaEngine.java | 26 +-
.../org/apache/bsf/engines/jexl/JEXLEngine.java | 164 ++++-----
.../apache/bsf/engines/jython/JythonEngine.java | 166 ++++-----
.../org/apache/bsf/util/BSFEventProcessor.java | 32 +-
.../util/BSFEventProcessorReturningEventInfos.java | 56 +--
src/main/java/org/apache/bsf/util/cf/CFDriver.java | 12 +-
.../util/event/generator/AdapterClassLoader.java | 58 ++--
.../bsf/util/event/generator/ByteUtility.java | 72 ++--
.../java/org/apache/bsf/AbstractBSFEngineTest.java | 28 +-
.../java/org/apache/bsf/BSFEngineTestCase.java | 28 +-
src/test/java/org/apache/bsf/BSFTest.java | 62 ++--
src/test/java/org/apache/bsf/FakeEngine.java | 4 +-
src/test/java/org/apache/bsf/engines/JaclTest.java | 86 ++---
.../org/apache/bsf/engines/JavascriptTest.java | 80 ++---
.../java/org/apache/bsf/engines/JythonTest.java | 96 ++---
.../org/apache/bsf/engines/NetrexxTest_IGNORE.java | 68 ++--
src/test/java/org/apache/bsf/util/TestBean.java | 16 +-
20 files changed, 841 insertions(+), 841 deletions(-)
diff --git a/src/main/java/org/apache/bsf/BSFManager.java
b/src/main/java/org/apache/bsf/BSFManager.java
index 59fa36b..1cefef0 100644
--- a/src/main/java/org/apache/bsf/BSFManager.java
+++ b/src/main/java/org/apache/bsf/BSFManager.java
@@ -79,60 +79,6 @@ public class BSFManager {
* loader
*/
- /**
- * Returns the defined ClassLoader (the ClassLoader that got used to
define the org.apache.bsf.BSFManager class object).
- *
- * @return The defined ClassLoader instance
- */
- public static ClassLoader getDefinedClassLoader() // rgf, 20070917
- {
- return definedClassLoader;
- }
-
- // table of scripting engine instances created by this manager.
- // only one instance of a given language engine is created by a single
- // manager instance.
- protected Hashtable loadedEngines = new Hashtable();
-
- // table of registered beans for use by scripting engines.
- protected ObjectRegistry objectRegistry = new ObjectRegistry();
-
- // prop change support containing loaded engines to inform when any
- // of my interesting properties change
- protected PropertyChangeSupport pcs;
-
- /*
- * rgf (20070917): wrong assumption; context ClassLoader needs to be
explicitly requested before usage as BSF could be deployed with different
context
- * ClassLoaders on different threads!
- */
-
- // the class loader to use if a class loader is needed. Default is
- // he who loaded me (which may be null in which case its Class.forName).
- protected ClassLoader classLoader = getClass().getClassLoader();
- // rgf, 20070917, reset to original// protected ClassLoader classLoader =
Thread.currentThread().getContextClassLoader(); // rgf, 2006-01-05
-
- // temporary directory to use to dump temporary files into. Note that
- // if class files are dropped here then unless this dir is in the
- // classpath or unless the classloader knows to look here, the classes
- // will not be found.
- protected String tempDir = ".";
-
- // classpath used by those that need a classpath
- protected String classPath;
-
- // stores BSFDeclaredBeans representing objects
- // introduced by a client of BSFManager
- protected Vector declaredBeans = new Vector();
-
- // private Log logger = LogFactory.getLog(this.getClass().getName());
- private BSF_Log logger;
-
- //////////////////////////////////////////////////////////////////////
- //
- // pre-register engines that BSF supports off the shelf
- //
- //////////////////////////////////////////////////////////////////////
-
static {
final String strInfo = "org.apache.bsf.BSFManager.dumpEnvironment()
[from static{}]";
try {
@@ -204,10 +150,82 @@ public class BSFManager {
}
}
- public BSFManager() {
- pcs = new PropertyChangeSupport(this);
- // handle logger
- logger = BSF_LogFactory.getLog(this.getClass().getName());
+ /**
+ * Returns the defined ClassLoader (the ClassLoader that got used to
define the org.apache.bsf.BSFManager class object).
+ *
+ * @return The defined ClassLoader instance
+ */
+ public static ClassLoader getDefinedClassLoader() // rgf, 20070917
+ {
+ return definedClassLoader;
+ }
+
+ /**
+ * Determine the language of a script file by looking at the file
extension.
+ *
+ * @param fileName The name of the file
+ * @return The scripting language the file is in if the file extension is
known to me (must have been registered via registerScriptingEngine).
+ * @exception BSFException if file's extension is unknown.
+ */
+ public static String getLangFromFilename(final String fileName) throws
BSFException {
+ final int dotIndex = fileName.lastIndexOf(".");
+
+ if (dotIndex != -1) {
+ final String extn = fileName.substring(dotIndex + 1);
+ String langval = (String) extn2Lang.get(extn);
+ String lang = null;
+ int index, loops = 0;
+
+ if (langval != null) {
+ final ClassLoader tccl =
Thread.currentThread().getContextClassLoader(); // rgf, 2009-09-10
+
+ while ((index = langval.indexOf(":", 0)) != -1) {
+ // Great. Multiple language engines registered
+ // for this extension.
+ // Try to find first one that is in our classpath.
+ lang = langval.substring(0, index);
+ langval = langval.substring(index + 1);
+ loops++;
+
+ // Test to see if in classpath
+ String engineName = null;
+ try {
+ engineName = (String) registeredEngines.get(lang);
+
+ boolean bTryDefinedClassLoader = false;
+ if (tccl != null) // context CL available, try it first
+ {
+ try {
+ tccl.loadClass(engineName);
+ } catch (final ClassNotFoundException cnfe) {
+ bTryDefinedClassLoader = true;
+ }
+ }
+
+ if (bTryDefinedClassLoader || tccl == null) // not
found, try defined CL next
+ {
+ definedClassLoader.loadClass(engineName);
+ }
+ } catch (final ClassNotFoundException cnfe2) {
+ // Bummer.
+ lang = langval;
+ continue;
+ }
+
+ // Got past that? Good.
+ break;
+ }
+ if (loops == 0) {
+ lang = langval;
+ }
+ }
+
+ if (lang != null && lang != "") {
+ return lang;
+ }
+ }
+ throw new BSFException(BSFException.REASON_OTHER_ERROR,
+ "[BSFManager.getLangFromFilename] file extension missing or
unknown: unable to determine language for '" + fileName + "'");
}
/**
@@ -227,6 +245,84 @@ public class BSFManager {
return version;
}
+ /*
+ * rgf (20070917): wrong assumption; context ClassLoader needs to be
explicitly requested before usage as BSF could be deployed with different
context
+ * ClassLoaders on different threads!
+ */
+
+ /**
+ * Determine whether a language is registered.
+ *
+ * @param lang string identifying a language
+ * @return true iff it is
+ */
+ public static boolean isLanguageRegistered(final String lang) {
+ return (registeredEngines.get(lang) != null);
+ }
+
+ /**
+ * Register a scripting engine in the static registry of the BSFManager.
+ *
+ * @param lang string identifying language
+ * @param engineClassName fully qualified name of the class interfacing
the language to BSF.
+ * @param extensions array of file extensions that should be mapped
to this language type. may be null.
+ */
+ public static void registerScriptingEngine(final String lang, final String
engineClassName, final String[] extensions) {
+ registeredEngines.put(lang, engineClassName);
+ if (extensions != null) {
+ for (int i = 0; i < extensions.length; i++) {
+ String langstr = (String) extn2Lang.get(extensions[i]);
+ langstr = (langstr == null) ? lang : lang + ":" + langstr;
+ extn2Lang.put(extensions[i], langstr);
+ }
+ }
+ }
+
+ // table of scripting engine instances created by this manager.
+ // only one instance of a given language engine is created by a single
+ // manager instance.
+ protected Hashtable loadedEngines = new Hashtable();
+
+ // table of registered beans for use by scripting engines.
+ protected ObjectRegistry objectRegistry = new ObjectRegistry();
+
+ // prop change support containing loaded engines to inform when any
+ // of my interesting properties change
+ protected PropertyChangeSupport pcs;
+
+ //////////////////////////////////////////////////////////////////////
+ //
+ // pre-register engines that BSF supports off the shelf
+ //
+ //////////////////////////////////////////////////////////////////////
+
+ // the class loader to use if a class loader is needed. Default is
+ // he who loaded me (which may be null in which case its Class.forName).
+ protected ClassLoader classLoader = getClass().getClassLoader();
+ // rgf, 20070917, reset to original// protected ClassLoader classLoader =
Thread.currentThread().getContextClassLoader(); // rgf, 2006-01-05
+
+ // temporary directory to use to dump temporary files into. Note that
+ // if class files are dropped here then unless this dir is in the
+ // classpath or unless the classloader knows to look here, the classes
+ // will not be found.
+ protected String tempDir = ".";
+
+ // classpath used by those that need a classpath
+ protected String classPath;
+
+ // stores BSFDeclaredBeans representing objects
+ // introduced by a client of BSFManager
+ protected Vector declaredBeans = new Vector();
+
+ // private Log logger = LogFactory.getLog(this.getClass().getName());
+ private BSF_Log logger;
+
+ public BSFManager() {
+ pcs = new PropertyChangeSupport(this);
+ // handle logger
+ logger = BSF_LogFactory.getLog(this.getClass().getName());
+ }
+
/**
* Apply the given anonymous function of the given language to the given
parameters and return the resulting value.
*
@@ -341,6 +437,13 @@ public class BSFManager {
}
}
+ //////////////////////////////////////////////////////////////////////
+ //
+ // Convenience functions for exec'ing and eval'ing scripts directly
+ // without loading and dealing with engines etc..
+ //
+ //////////////////////////////////////////////////////////////////////
+
/**
* Compile the given script of the given language into the given {@code
CodeBuffer}.
*
@@ -445,13 +548,6 @@ public class BSFManager {
return result;
}
- //////////////////////////////////////////////////////////////////////
- //
- // Convenience functions for exec'ing and eval'ing scripts directly
- // without loading and dealing with engines etc..
- //
- //////////////////////////////////////////////////////////////////////
-
/**
* Execute the given script of the given language.
*
@@ -484,38 +580,6 @@ public class BSFManager {
}
}
- /**
- * Execute the given script of the given language, attempting to emulate
an interactive session w/ the language.
- *
- * @param lang language identifier
- * @param source (context info) the source of this expression (for
example, filename)
- * @param lineNo (context info) the line number in source for expr
- * @param columnNo (context info) the column number in source for expr
- * @param script The script to execute
- * @exception BSFException if anything goes wrong while running the script
- */
- public void iexec(final String lang, final String source, final int
lineNo, final int columnNo, final Object script) throws BSFException {
- logger.debug("BSFManager:iexec");
-
- final BSFEngine e = loadScriptingEngine(lang);
- final String sourcef = source;
- final int lineNof = lineNo, columnNof = columnNo;
- final Object scriptf = script;
-
- try {
- AccessController.doPrivileged(new PrivilegedExceptionAction() {
- public Object run() throws Exception {
- e.iexec(sourcef, lineNof, columnNof, scriptf);
- return null;
- }
- });
- } catch (final PrivilegedActionException prive) {
-
- logger.error("[BSFManager] Exception :", prive);
- throw (BSFException) prive.getException();
- }
- }
-
/**
* Get classLoader
*/
@@ -541,74 +605,6 @@ public class BSFManager {
return classPath;
}
- /**
- * Determine the language of a script file by looking at the file
extension.
- *
- * @param fileName The name of the file
- * @return The scripting language the file is in if the file extension is
known to me (must have been registered via registerScriptingEngine).
- * @exception BSFException if file's extension is unknown.
- */
- public static String getLangFromFilename(final String fileName) throws
BSFException {
- final int dotIndex = fileName.lastIndexOf(".");
-
- if (dotIndex != -1) {
- final String extn = fileName.substring(dotIndex + 1);
- String langval = (String) extn2Lang.get(extn);
- String lang = null;
- int index, loops = 0;
-
- if (langval != null) {
- final ClassLoader tccl =
Thread.currentThread().getContextClassLoader(); // rgf, 2009-09-10
-
- while ((index = langval.indexOf(":", 0)) != -1) {
- // Great. Multiple language engines registered
- // for this extension.
- // Try to find first one that is in our classpath.
- lang = langval.substring(0, index);
- langval = langval.substring(index + 1);
- loops++;
-
- // Test to see if in classpath
- String engineName = null;
- try {
- engineName = (String) registeredEngines.get(lang);
-
- boolean bTryDefinedClassLoader = false;
- if (tccl != null) // context CL available, try it first
- {
- try {
- tccl.loadClass(engineName);
- } catch (final ClassNotFoundException cnfe) {
- bTryDefinedClassLoader = true;
- }
- }
-
- if (bTryDefinedClassLoader || tccl == null) // not
found, try defined CL next
- {
- definedClassLoader.loadClass(engineName);
- }
- } catch (final ClassNotFoundException cnfe2) {
- // Bummer.
- lang = langval;
- continue;
- }
-
- // Got past that? Good.
- break;
- }
- if (loops == 0) {
- lang = langval;
- }
- }
-
- if (lang != null && lang != "") {
- return lang;
- }
- }
- throw new BSFException(BSFException.REASON_OTHER_ERROR,
- "[BSFManager.getLangFromFilename] file extension missing or
unknown: unable to determine language for '" + fileName + "'");
- }
-
/**
* Return the current object registry of the manager.
*
@@ -625,22 +621,44 @@ public class BSFManager {
return tempDir;
}
- /**
- * Determine whether a language is registered.
- *
- * @param lang string identifying a language
- * @return true iff it is
- */
- public static boolean isLanguageRegistered(final String lang) {
- return (registeredEngines.get(lang) != null);
- }
-
//////////////////////////////////////////////////////////////////////
//
// Bean scripting framework services
//
//////////////////////////////////////////////////////////////////////
+ /**
+ * Execute the given script of the given language, attempting to emulate
an interactive session w/ the language.
+ *
+ * @param lang language identifier
+ * @param source (context info) the source of this expression (for
example, filename)
+ * @param lineNo (context info) the line number in source for expr
+ * @param columnNo (context info) the column number in source for expr
+ * @param script The script to execute
+ * @exception BSFException if anything goes wrong while running the script
+ */
+ public void iexec(final String lang, final String source, final int
lineNo, final int columnNo, final Object script) throws BSFException {
+ logger.debug("BSFManager:iexec");
+
+ final BSFEngine e = loadScriptingEngine(lang);
+ final String sourcef = source;
+ final int lineNof = lineNo, columnNof = columnNo;
+ final Object scriptf = script;
+
+ try {
+ AccessController.doPrivileged(new PrivilegedExceptionAction() {
+ public Object run() throws Exception {
+ e.iexec(sourcef, lineNof, columnNof, scriptf);
+ return null;
+ }
+ });
+ } catch (final PrivilegedActionException prive) {
+
+ logger.error("[BSFManager] Exception :", prive);
+ throw (BSFException) prive.getException();
+ }
+ }
+
/**
* Load a scripting engine based on the lang string identifying it.
*
@@ -747,24 +765,6 @@ public class BSFManager {
objectRegistry.register(beanName, tempBean);
}
- /**
- * Register a scripting engine in the static registry of the BSFManager.
- *
- * @param lang string identifying language
- * @param engineClassName fully qualified name of the class interfacing
the language to BSF.
- * @param extensions array of file extensions that should be mapped
to this language type. may be null.
- */
- public static void registerScriptingEngine(final String lang, final String
engineClassName, final String[] extensions) {
- registeredEngines.put(lang, engineClassName);
- if (extensions != null) {
- for (int i = 0; i < extensions.length; i++) {
- String langstr = (String) extn2Lang.get(extensions[i]);
- langstr = (langstr == null) ? lang : lang + ":" + langstr;
- extn2Lang.put(extensions[i], langstr);
- }
- }
- }
-
/**
* Set the class loader for those that need to use it. Default is he who
loaded me or null (i.e., its Class.forName).
*
diff --git a/src/main/java/org/apache/bsf/BSF_Log.java
b/src/main/java/org/apache/bsf/BSF_Log.java
index 19ae595..96e8e08 100644
--- a/src/main/java/org/apache/bsf/BSF_Log.java
+++ b/src/main/java/org/apache/bsf/BSF_Log.java
@@ -141,6 +141,74 @@ public class BSF_Log // implements
org.apache.commons.logging.Log
oac_LogFactoryGetLog_String = oac_LogFactoryGetLog_String_;
}
+ static void dump(final BSF_Log bl) {
+ System.out.println("\n\tbl=[" + bl + "] --->>> --->>> --->>>");
+ System.err.print("/debug **/");
+ bl.debug("debug message. ");
+ System.err.println("\\** debug.\\");
+ System.err.print("/error **/");
+ bl.error("error message. ");
+ System.err.println("\\** error.\\");
+ System.err.print("/fatal **/");
+ bl.fatal("fatal message. ");
+ System.err.println("\\** fatal.\\");
+ System.err.print("/info **/");
+ bl.info("info message. ");
+ System.err.println("\\** info .\\");
+ System.err.print("/trace **/");
+ bl.trace("trace message. ");
+ System.err.println("\\** trace.\\");
+ System.err.print("/warn **/");
+ bl.warn("warn message. ");
+ System.err.println("\\** warn .\\");
+ System.err.println();
+
+ final Throwable t = new Throwable("Test from Rony for: " + bl);
+ System.err.print("/debug **/");
+ bl.debug("debug message. ", t);
+ System.err.println("\\** debug.\\");
+ System.err.print("/error **/");
+ bl.error("error message. ", t);
+ System.err.println("\\** error.\\");
+ System.err.print("/fatal **/");
+ bl.fatal("fatal message. ", t);
+ System.err.println("\\** fatal.\\");
+ System.err.print("/info **/");
+ bl.info("info message. ", t);
+ System.err.println("\\** info .\\");
+ System.err.print("/trace **/");
+ bl.trace("trace message. ", t);
+ System.err.println("\\** trace.\\");
+ System.err.print("/warn **/");
+ bl.warn("warn message. ", t);
+ System.err.println("\\** warn .\\");
+ System.err.println();
+
+ System.out.println("\tisDebugEnabled: " + bl.isDebugEnabled());
+ System.out.println("\tisErrorEnabled: " + bl.isErrorEnabled());
+ System.out.println("\tisFatalEnabled: " + bl.isFatalEnabled());
+ System.out.println("\tisInfo Enabled: " + bl.isInfoEnabled());
+ System.out.println("\tisTraceEnabled: " + bl.isTraceEnabled());
+ System.out.println("\tisWarn Enabled: " + bl.isWarnEnabled());
+
+ System.out.println("\tbl=[" + bl + "] <<<--- <<<--- <<<---");
+
System.out.println("--------------------------------------------------------");
+ }
+
+ // for development purposes only (to debug this class on its own)
+ public static void main(final String args[]) {
+ System.out.println("in BSF_Log ...");
+
System.out.println("--------------------------------------------------------");
+
System.out.println("--------------------------------------------------------");
+ BSF_Log bl = new BSF_Log();
+ dump(bl);
+ bl = new BSF_Log(Class.class);
+ dump(bl);
+ bl = new BSF_Log("Rony was here...");
+ dump(bl);
+
+ }
+
/** Name of the BSF_Log instance. */
final String name;
@@ -151,6 +219,10 @@ public class BSF_Log // implements
org.apache.commons.logging.Log
this("<?>");
}
+ public BSF_Log(final Class clazz) {
+ this(clazz.getName());
+ }
+
public BSF_Log(final String name) {
Object oac_logger_ = null;
this.name = name;
@@ -165,10 +237,6 @@ public class BSF_Log // implements
org.apache.commons.logging.Log
oac_logger = oac_logger_;
}
- public BSF_Log(final Class clazz) {
- this(clazz.getName());
- }
-
public void debug(final Object msg) {
if (oac_logger == null) {
return; // no org.apache.commons.logging.Log object ?
@@ -273,58 +341,6 @@ public class BSF_Log // implements
org.apache.commons.logging.Log
}
}
- public void trace(final Object msg) {
- if (oac_logger == null) {
- return; // no org.apache.commons.logging.Log object ?
- }
-
- try {
- // ((org.apache.commons.logging.Log) oac_logger).trace(msg);
- meths[trace1].invoke(oac_logger, new Object[] { msg });
- } catch (final Exception e) {
- e.printStackTrace();
- }
- }
-
- public void trace(final Object msg, final Throwable t) {
- if (oac_logger == null) {
- return; // no org.apache.commons.logging.Log object ?
- }
-
- try {
- // ((org.apache.commons.logging.Log) oac_logger).trace(msg, t);
- meths[trace2].invoke(oac_logger, new Object[] { msg, t });
- } catch (final Exception e) {
- e.printStackTrace();
- }
- }
-
- public void warn(final Object msg) {
- if (oac_logger == null) {
- return; // no org.apache.commons.logging.Log object ?
- }
-
- try {
- // ((org.apache.commons.logging.Log) oac_logger).warn(msg);
- meths[warn1].invoke(oac_logger, new Object[] { msg });
- } catch (final Exception e) {
- e.printStackTrace();
- }
- }
-
- public void warn(final Object msg, final Throwable t) {
- if (oac_logger == null) {
- return; // no org.apache.commons.logging.Log object ?
- }
-
- try {
- // ((org.apache.commons.logging.Log) oac_logger).warn(msg, t);
- meths[warn2].invoke(oac_logger, new Object[] { msg, t });
- } catch (final Exception e) {
- e.printStackTrace();
- }
- }
-
public boolean isDebugEnabled() {
if (oac_logger == null) {
return false;
@@ -409,71 +425,55 @@ public class BSF_Log // implements
org.apache.commons.logging.Log
}
}
- // for development purposes only (to debug this class on its own)
- public static void main(final String args[]) {
- System.out.println("in BSF_Log ...");
-
System.out.println("--------------------------------------------------------");
-
System.out.println("--------------------------------------------------------");
- BSF_Log bl = new BSF_Log();
- dump(bl);
- bl = new BSF_Log(Class.class);
- dump(bl);
- bl = new BSF_Log("Rony was here...");
- dump(bl);
+ public void trace(final Object msg) {
+ if (oac_logger == null) {
+ return; // no org.apache.commons.logging.Log object ?
+ }
+ try {
+ // ((org.apache.commons.logging.Log) oac_logger).trace(msg);
+ meths[trace1].invoke(oac_logger, new Object[] { msg });
+ } catch (final Exception e) {
+ e.printStackTrace();
+ }
}
- static void dump(final BSF_Log bl) {
- System.out.println("\n\tbl=[" + bl + "] --->>> --->>> --->>>");
- System.err.print("/debug **/");
- bl.debug("debug message. ");
- System.err.println("\\** debug.\\");
- System.err.print("/error **/");
- bl.error("error message. ");
- System.err.println("\\** error.\\");
- System.err.print("/fatal **/");
- bl.fatal("fatal message. ");
- System.err.println("\\** fatal.\\");
- System.err.print("/info **/");
- bl.info("info message. ");
- System.err.println("\\** info .\\");
- System.err.print("/trace **/");
- bl.trace("trace message. ");
- System.err.println("\\** trace.\\");
- System.err.print("/warn **/");
- bl.warn("warn message. ");
- System.err.println("\\** warn .\\");
- System.err.println();
+ public void trace(final Object msg, final Throwable t) {
+ if (oac_logger == null) {
+ return; // no org.apache.commons.logging.Log object ?
+ }
- final Throwable t = new Throwable("Test from Rony for: " + bl);
- System.err.print("/debug **/");
- bl.debug("debug message. ", t);
- System.err.println("\\** debug.\\");
- System.err.print("/error **/");
- bl.error("error message. ", t);
- System.err.println("\\** error.\\");
- System.err.print("/fatal **/");
- bl.fatal("fatal message. ", t);
- System.err.println("\\** fatal.\\");
- System.err.print("/info **/");
- bl.info("info message. ", t);
- System.err.println("\\** info .\\");
- System.err.print("/trace **/");
- bl.trace("trace message. ", t);
- System.err.println("\\** trace.\\");
- System.err.print("/warn **/");
- bl.warn("warn message. ", t);
- System.err.println("\\** warn .\\");
- System.err.println();
+ try {
+ // ((org.apache.commons.logging.Log) oac_logger).trace(msg, t);
+ meths[trace2].invoke(oac_logger, new Object[] { msg, t });
+ } catch (final Exception e) {
+ e.printStackTrace();
+ }
+ }
- System.out.println("\tisDebugEnabled: " + bl.isDebugEnabled());
- System.out.println("\tisErrorEnabled: " + bl.isErrorEnabled());
- System.out.println("\tisFatalEnabled: " + bl.isFatalEnabled());
- System.out.println("\tisInfo Enabled: " + bl.isInfoEnabled());
- System.out.println("\tisTraceEnabled: " + bl.isTraceEnabled());
- System.out.println("\tisWarn Enabled: " + bl.isWarnEnabled());
+ public void warn(final Object msg) {
+ if (oac_logger == null) {
+ return; // no org.apache.commons.logging.Log object ?
+ }
- System.out.println("\tbl=[" + bl + "] <<<--- <<<--- <<<---");
-
System.out.println("--------------------------------------------------------");
+ try {
+ // ((org.apache.commons.logging.Log) oac_logger).warn(msg);
+ meths[warn1].invoke(oac_logger, new Object[] { msg });
+ } catch (final Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ public void warn(final Object msg, final Throwable t) {
+ if (oac_logger == null) {
+ return; // no org.apache.commons.logging.Log object ?
+ }
+
+ try {
+ // ((org.apache.commons.logging.Log) oac_logger).warn(msg, t);
+ meths[warn2].invoke(oac_logger, new Object[] { msg, t });
+ } catch (final Exception e) {
+ e.printStackTrace();
+ }
}
}
diff --git a/src/main/java/org/apache/bsf/BSF_LogFactory.java
b/src/main/java/org/apache/bsf/BSF_LogFactory.java
index a8d964f..d668e34 100644
--- a/src/main/java/org/apache/bsf/BSF_LogFactory.java
+++ b/src/main/java/org/apache/bsf/BSF_LogFactory.java
@@ -25,14 +25,14 @@ package org.apache.bsf;
*/
public class BSF_LogFactory {
- protected BSF_LogFactory() {
- } // mimickries org.apache.commons.logging.LogFactory
+ static public BSF_Log getLog(final Class clz) {
+ return new BSF_Log(clz);
+ }
static public BSF_Log getLog(final String name) {
return new BSF_Log(name);
}
- static public BSF_Log getLog(final Class clz) {
- return new BSF_Log(clz);
- }
+ protected BSF_LogFactory() {
+ } // mimickries org.apache.commons.logging.LogFactory
}
diff --git a/src/main/java/org/apache/bsf/engines/java/JavaEngine.java
b/src/main/java/org/apache/bsf/engines/java/JavaEngine.java
index b254444..93f417e 100644
--- a/src/main/java/org/apache/bsf/engines/java/JavaEngine.java
+++ b/src/main/java/org/apache/bsf/engines/java/JavaEngine.java
@@ -74,10 +74,22 @@ import org.apache.bsf.util.ObjInfo;
* <p>
*/
public class JavaEngine extends BSFEngineImpl {
- Class javaclass = null;
+ private class GeneratedFile {
+ File file = null;
+ FileOutputStream fos = null;
+ String className = null;
+
+ GeneratedFile(final File file, final FileOutputStream fos, final
String className) {
+ this.file = file;
+ this.fos = fos;
+ this.className = className;
+ }
+ }
static Hashtable codeToClass = new Hashtable();
static String serializeCompilation = "";
static String placeholder = "$$CLASSNAME$$";
+ Class javaclass = null;
+
String minorPrefix;
// private Log logger = LogFactory.getLog(this.getClass().getName());
@@ -89,18 +101,6 @@ public class JavaEngine extends BSFEngineImpl {
*/
private int uniqueFileOffset = -1;
- private class GeneratedFile {
- File file = null;
- FileOutputStream fos = null;
- String className = null;
-
- GeneratedFile(final File file, final FileOutputStream fos, final
String className) {
- this.file = file;
- this.fos = fos;
- this.className = className;
- }
- }
-
/**
* Constructs a new instance.
*/
diff --git a/src/main/java/org/apache/bsf/engines/jexl/JEXLEngine.java
b/src/main/java/org/apache/bsf/engines/jexl/JEXLEngine.java
index 89c0e9f..f76c510 100644
--- a/src/main/java/org/apache/bsf/engines/jexl/JEXLEngine.java
+++ b/src/main/java/org/apache/bsf/engines/jexl/JEXLEngine.java
@@ -51,25 +51,16 @@ import
org.apache.commons.jexl3.introspection.JexlPermissions;
* @see <a href="https://commons.apache.org/jexl/">Commons JEXL</a>
*/
public class JEXLEngine extends BSFEngineImpl {
- private static JexlPermissions BSF_PERMISSIONS =
JexlPermissions.RESTRICTED;
- private static JexlFeatures BSF_FEATURES = JexlFeatures.createDefault();
- /** The engine. */
- private JexlEngine engine;
-
- /** The declared bean */
- private Map<String, Object> vars;
-
- /** The backing JexlContext for this engine. */
- private JexlContext jc;
-
/**
- * Sets the JEXL engine permissions.
- *
- * @param permissions The permissions
+ * A context sharing the variables.
*/
- public static void setPermissions(JexlPermissions permissions) {
- BSF_PERMISSIONS = permissions;
+ private static class BSFContext extends MapContext {
+ BSFContext(Map<String, Object> vars) {
+ super(vars);
+ }
}
+ private static JexlPermissions BSF_PERMISSIONS =
JexlPermissions.RESTRICTED;
+ private static JexlFeatures BSF_FEATURES = JexlFeatures.createDefault();
/**
* Sets the JEXL engine features.
@@ -80,45 +71,59 @@ public class JEXLEngine extends BSFEngineImpl {
}
/**
- * A context sharing the variables.
+ * Sets the JEXL engine permissions.
+ *
+ * @param permissions The permissions
*/
- private static class BSFContext extends MapContext {
- BSFContext(Map<String, Object> vars) {
- super(vars);
- }
+ public static void setPermissions(JexlPermissions permissions) {
+ BSF_PERMISSIONS = permissions;
}
/**
- * Initialize the JEXL engine by creating a JexlContext and populating it
with the declared beans.
+ * Creates a string from a reader.
*
- * @param mgr The {@link BSFManager}.
- * @param lang The language.
- * @param declaredBeans The vector of the initially declared beans.
- * @throws BSFException For any exception that occurs while trying to
initialize the engine.
+ * @param reader to be read.
+ * @return The contents of the reader as a String.
+ * @throws IOException on any error reading the reader.
*/
- public void initialize(final BSFManager mgr, final String lang, final
Vector declaredBeans) throws BSFException {
- super.initialize(mgr, lang, declaredBeans);
- vars = new ConcurrentHashMap<>();
- jc = new BSFContext(vars);
- for (int i = 0; i < declaredBeans.size(); i++) {
- final BSFDeclaredBean bean = (BSFDeclaredBean)
declaredBeans.elementAt(i);
- vars.put(bean.name, bean.bean);
+ protected static String toString(final BufferedReader reader) throws
IOException {
+ final StringBuilder buffer = new StringBuilder();
+ String line;
+ while ((line = reader.readLine()) != null) {
+ buffer.append(line).append('\n');
}
- vars.put("java.lang.System.out", System.out);
- vars.put("java.lang.System.in", System.in);
- vars.put("java.lang.System.err", System.err);
- vars.put("bsf", new BSFFunctions(mgr, this));
- engine = new
JexlBuilder().cache(32).permissions(BSF_PERMISSIONS).features(BSF_FEATURES).create();
+ return buffer.toString();
}
+ /** The engine. */
+ private JexlEngine engine;
+
+ /** The declared bean */
+ private Map<String, Object> vars;
+
+ /** The backing JexlContext for this engine. */
+ private JexlContext jc;
+
/**
- * Terminate the JEXL engine by clearing and destroying the backing
JEXLContext.
+ * Uses reflection to make the call.
+ *
+ * @param object The object to make the call on.
+ * @param name The call to make.
+ * @param args The arguments to pass.
+ * @return The result of the call.
+ * @throws BSFException For any exception that occurs while making the
call.
*/
- public void terminate() {
- if (jc != null) {
- vars.clear();
- jc = null;
- engine = null;
+ public Object call(Object object, final String name, final Object[] args)
throws BSFException {
+ try {
+ if (object == null) {
+ object = vars.get(name);
+ }
+ if (object instanceof JexlScript) {
+ return ((JexlScript) object).execute(jc, args);
+ }
+ return engine.invokeMethod(object, name, args);
+ } catch (final Exception e) {
+ throw new BSFException(BSFException.REASON_EXECUTION_ERROR,
"Exception from JEXLEngine:\n" + e.getMessage(), e);
}
}
@@ -132,16 +137,6 @@ public class JEXLEngine extends BSFEngineImpl {
vars.put(bean.name, bean.bean);
}
- /**
- * Removes this bean from the backing JexlContext.
- *
- * @param bean The {@link BSFDeclaredBean} to be removed from the backing
context.
- * @throws BSFException For any exception that occurs while trying to
undeclare the bean.
- */
- public void undeclareBean(final BSFDeclaredBean bean) throws BSFException {
- vars.remove(bean.name);
- }
-
/**
* Evaluates the expression as a JEXL Script.
*
@@ -220,26 +215,26 @@ public class JEXLEngine extends BSFEngineImpl {
}
/**
- * Uses reflection to make the call.
+ * Initialize the JEXL engine by creating a JexlContext and populating it
with the declared beans.
*
- * @param object The object to make the call on.
- * @param name The call to make.
- * @param args The arguments to pass.
- * @return The result of the call.
- * @throws BSFException For any exception that occurs while making the
call.
+ * @param mgr The {@link BSFManager}.
+ * @param lang The language.
+ * @param declaredBeans The vector of the initially declared beans.
+ * @throws BSFException For any exception that occurs while trying to
initialize the engine.
*/
- public Object call(Object object, final String name, final Object[] args)
throws BSFException {
- try {
- if (object == null) {
- object = vars.get(name);
- }
- if (object instanceof JexlScript) {
- return ((JexlScript) object).execute(jc, args);
- }
- return engine.invokeMethod(object, name, args);
- } catch (final Exception e) {
- throw new BSFException(BSFException.REASON_EXECUTION_ERROR,
"Exception from JEXLEngine:\n" + e.getMessage(), e);
+ public void initialize(final BSFManager mgr, final String lang, final
Vector declaredBeans) throws BSFException {
+ super.initialize(mgr, lang, declaredBeans);
+ vars = new ConcurrentHashMap<>();
+ jc = new BSFContext(vars);
+ for (int i = 0; i < declaredBeans.size(); i++) {
+ final BSFDeclaredBean bean = (BSFDeclaredBean)
declaredBeans.elementAt(i);
+ vars.put(bean.name, bean.bean);
}
+ vars.put("java.lang.System.out", System.out);
+ vars.put("java.lang.System.in", System.in);
+ vars.put("java.lang.System.err", System.err);
+ vars.put("bsf", new BSFFunctions(mgr, this));
+ engine = new
JexlBuilder().cache(32).permissions(BSF_PERMISSIONS).features(BSF_FEATURES).create();
}
/**
@@ -275,18 +270,23 @@ public class JEXLEngine extends BSFEngineImpl {
}
/**
- * Creates a string from a reader.
- *
- * @param reader to be read.
- * @return The contents of the reader as a String.
- * @throws IOException on any error reading the reader.
+ * Terminate the JEXL engine by clearing and destroying the backing
JEXLContext.
*/
- protected static String toString(final BufferedReader reader) throws
IOException {
- final StringBuilder buffer = new StringBuilder();
- String line;
- while ((line = reader.readLine()) != null) {
- buffer.append(line).append('\n');
+ public void terminate() {
+ if (jc != null) {
+ vars.clear();
+ jc = null;
+ engine = null;
}
- return buffer.toString();
+ }
+
+ /**
+ * Removes this bean from the backing JexlContext.
+ *
+ * @param bean The {@link BSFDeclaredBean} to be removed from the backing
context.
+ * @throws BSFException For any exception that occurs while trying to
undeclare the bean.
+ */
+ public void undeclareBean(final BSFDeclaredBean bean) throws BSFException {
+ vars.remove(bean.name);
}
}
diff --git a/src/main/java/org/apache/bsf/engines/jython/JythonEngine.java
b/src/main/java/org/apache/bsf/engines/jython/JythonEngine.java
index 532f16b..5f4352b 100644
--- a/src/main/java/org/apache/bsf/engines/jython/JythonEngine.java
+++ b/src/main/java/org/apache/bsf/engines/jython/JythonEngine.java
@@ -40,49 +40,23 @@ import org.python.util.InteractiveInterpreter;
*/
public class JythonEngine extends BSFEngineImpl {
- BSFPythonInterpreter interp;
- private static final Pattern fromRegExp = Pattern.compile("from
([.^\\S]*)");
-
- /**
- * call the named method of the given object.
- */
- public Object call(final Object object, final String method, final
Object[] args) throws BSFException {
- try {
- PyObject[] pyargs = Py.EmptyObjects;
-
- if (args != null) {
- pyargs = new PyObject[args.length];
- for (int i = 0; i < pyargs.length; i++) {
- pyargs[i] = Py.java2py(args[i]);
- }
- }
-
- if (object != null) {
- final PyObject o = Py.java2py(object);
- return unwrap(o.invoke(method, pyargs));
- }
+ private class BSFPythonInterpreter extends InteractiveInterpreter {
- PyObject m = interp.get(method);
+ public BSFPythonInterpreter() {
+ }
- if (m == null) {
- m = interp.eval(method);
- }
- if (m != null) {
- return unwrap(m.__call__(pyargs));
+ // Override runcode so as not to print the stack dump
+ public void runcode(final PyObject code) {
+ try {
+ this.exec(code);
+ } catch (final PyException exc) {
+ throw exc;
}
-
- return null;
- } catch (final PyException e) {
- throw new BSFException(BSFException.REASON_EXECUTION_ERROR,
"exception from Jython:\n" + e, e);
}
}
+ private static final Pattern fromRegExp = Pattern.compile("from
([.^\\S]*)");
- /**
- * Declare a bean
- */
- public void declareBean(final BSFDeclaredBean bean) throws BSFException {
- interp.set(bean.name, bean.bean);
- }
+ BSFPythonInterpreter interp;
/**
* Evaluate an anonymous function (differs from eval() in that apply()
handles multiple lines).
@@ -120,6 +94,60 @@ public class JythonEngine extends BSFEngineImpl {
}
}
+ private String byteify(final String orig) {
+ // Ugh. Jython likes to be fed bytes, rather than the input string.
+ final ByteArrayInputStream bais = new
ByteArrayInputStream(orig.getBytes());
+ final StringBuilder s = new StringBuilder();
+ int c;
+
+ while ((c = bais.read()) >= 0) {
+ s.append((char) c);
+ }
+
+ return s.toString();
+ }
+
+ /**
+ * call the named method of the given object.
+ */
+ public Object call(final Object object, final String method, final
Object[] args) throws BSFException {
+ try {
+ PyObject[] pyargs = Py.EmptyObjects;
+
+ if (args != null) {
+ pyargs = new PyObject[args.length];
+ for (int i = 0; i < pyargs.length; i++) {
+ pyargs[i] = Py.java2py(args[i]);
+ }
+ }
+
+ if (object != null) {
+ final PyObject o = Py.java2py(object);
+ return unwrap(o.invoke(method, pyargs));
+ }
+
+ PyObject m = interp.get(method);
+
+ if (m == null) {
+ m = interp.eval(method);
+ }
+ if (m != null) {
+ return unwrap(m.__call__(pyargs));
+ }
+
+ return null;
+ } catch (final PyException e) {
+ throw new BSFException(BSFException.REASON_EXECUTION_ERROR,
"exception from Jython:\n" + e, e);
+ }
+ }
+
+ /**
+ * Declare a bean
+ */
+ public void declareBean(final BSFDeclaredBean bean) throws BSFException {
+ interp.set(bean.name, bean.bean);
+ }
+
/**
* Evaluate an expression.
*/
@@ -150,14 +178,6 @@ public class JythonEngine extends BSFEngineImpl {
}
}
- private void importPackage(final String script) {
- final Matcher matcher = fromRegExp.matcher(script);
- while (matcher.find()) {
- final String packageName = matcher.group(1);
- PySystemState.add_package(packageName);
- }
- }
-
/**
* Execute script code, emulating console interaction.
*/
@@ -184,6 +204,14 @@ public class JythonEngine extends BSFEngineImpl {
}
}
+ private void importPackage(final String script) {
+ final Matcher matcher = fromRegExp.matcher(script);
+ while (matcher.find()) {
+ final String packageName = matcher.group(1);
+ PySystemState.add_package(packageName);
+ }
+ }
+
/**
* Initialize the engine.
*/
@@ -207,6 +235,16 @@ public class JythonEngine extends BSFEngineImpl {
}
}
+ public void propertyChange(final PropertyChangeEvent e) {
+ super.propertyChange(e);
+ final String name = e.getPropertyName();
+ final Object value = e.getNewValue();
+ if (name.equals("classLoader")) {
+ Py.getSystemState().setClassLoader((ClassLoader) value);
+ }
+
+ }
+
/**
* Undeclare a previously declared bean.
*/
@@ -223,42 +261,4 @@ public class JythonEngine extends BSFEngineImpl {
}
return result;
}
-
- private String byteify(final String orig) {
- // Ugh. Jython likes to be fed bytes, rather than the input string.
- final ByteArrayInputStream bais = new
ByteArrayInputStream(orig.getBytes());
- final StringBuilder s = new StringBuilder();
- int c;
-
- while ((c = bais.read()) >= 0) {
- s.append((char) c);
- }
-
- return s.toString();
- }
-
- private class BSFPythonInterpreter extends InteractiveInterpreter {
-
- public BSFPythonInterpreter() {
- }
-
- // Override runcode so as not to print the stack dump
- public void runcode(final PyObject code) {
- try {
- this.exec(code);
- } catch (final PyException exc) {
- throw exc;
- }
- }
- }
-
- public void propertyChange(final PropertyChangeEvent e) {
- super.propertyChange(e);
- final String name = e.getPropertyName();
- final Object value = e.getNewValue();
- if (name.equals("classLoader")) {
- Py.getSystemState().setClassLoader((ClassLoader) value);
- }
-
- }
}
diff --git a/src/main/java/org/apache/bsf/util/BSFEventProcessor.java
b/src/main/java/org/apache/bsf/util/BSFEventProcessor.java
index 2e1adb8..aa1a68b 100644
--- a/src/main/java/org/apache/bsf/util/BSFEventProcessor.java
+++ b/src/main/java/org/apache/bsf/util/BSFEventProcessor.java
@@ -29,12 +29,28 @@ import org.apache.bsf.util.event.EventProcessor;
* This is used to support binding scripts to be run when an event occurs.
*/
public class BSFEventProcessor implements EventProcessor {
+ private static boolean isFilteredEvent(final String filter, final String
inFilter) {
+ boolean bRes = filter.equalsIgnoreCase(inFilter);
+ if (bRes) {
+ return bRes;
+ }
+
+ final String[] chunks = filter.replace('+', ' ').split(" ");
+ for (int i = 0; i < chunks.length; i++) {
+ bRes = chunks[i].equalsIgnoreCase(inFilter);
+ if (bRes) {
+ return bRes;
+ }
+ }
+ return bRes;
+ }
BSFEngine engine;
BSFManager manager;
String filter;
String source;
int lineNo;
int columnNo;
+
Object script;
/**
@@ -87,20 +103,4 @@ public class BSFEventProcessor implements EventProcessor {
engine.exec(source, lineNo, columnNo, script);
// System.err.println("returned from engine.exec.");
}
-
- private static boolean isFilteredEvent(final String filter, final String
inFilter) {
- boolean bRes = filter.equalsIgnoreCase(inFilter);
- if (bRes) {
- return bRes;
- }
-
- final String[] chunks = filter.replace('+', ' ').split(" ");
- for (int i = 0; i < chunks.length; i++) {
- bRes = chunks[i].equalsIgnoreCase(inFilter);
- if (bRes) {
- return bRes;
- }
- }
- return bRes;
- }
}
diff --git
a/src/main/java/org/apache/bsf/util/BSFEventProcessorReturningEventInfos.java
b/src/main/java/org/apache/bsf/util/BSFEventProcessorReturningEventInfos.java
index 516b225..0c86811 100644
---
a/src/main/java/org/apache/bsf/util/BSFEventProcessorReturningEventInfos.java
+++
b/src/main/java/org/apache/bsf/util/BSFEventProcessorReturningEventInfos.java
@@ -41,6 +41,22 @@ import org.apache.bsf.util.event.EventProcessor;
* org.apache.bsf.util.BSFEventProcessor.
*/
public class BSFEventProcessorReturningEventInfos implements EventProcessor {
+ private static boolean isFilteredEvent(final String filter, final String
inFilter) {
+ boolean bRes = filter.equalsIgnoreCase(inFilter);
+ if (bRes) {
+ return bRes;
+ }
+
+ final String[] chunks = filter.replace('+', ' ').split(" ");
+ for (int i = 0; i < chunks.length; i++) {
+ bRes = chunks[i].equalsIgnoreCase(inFilter);
+ if (bRes) {
+ return bRes;
+ }
+ }
+ return bRes;
+ }
+
BSFEngine engine;
BSFManager manager;
@@ -55,10 +71,18 @@ public class BSFEventProcessorReturningEventInfos
implements EventProcessor {
Object script;
+ // for example an object reference to forward event with received
arguments to
+
Object dataFromScriptingEngine; // ---rgf, 2006-02-24: data coming from the
// script engine, could be
- // for example an object reference to forward event with received
arguments to
+ // ////////////////////////////////////////////////////////////////////////
+ //
+ // event is delegated to me by the adapters using this. inFilter is
+ // in general the name of the method via which the event was received
+ // at the adapter. For prop/veto change events, inFilter is the name
+ // of the property. In any case, in the event processor, I only forward
+ // those events if for which the filters match (if one is specified).
/**
* Package-protected constructor makes this class unavailable for public
use.
@@ -80,11 +104,9 @@ public class BSFEventProcessorReturningEventInfos
implements EventProcessor {
// ////////////////////////////////////////////////////////////////////////
//
- // event is delegated to me by the adapters using this. inFilter is
- // in general the name of the method via which the event was received
- // at the adapter. For prop/veto change events, inFilter is the name
- // of the property. In any case, in the event processor, I only forward
- // those events if for which the filters match (if one is specified).
+ // same as above, but used when the method event method may generate
+ // an exception which must go all the way back to the source (as in
+ // the vetoableChange case)
public void processEvent(final String inFilter, final Object[] evtInfo) {
try {
@@ -100,12 +122,6 @@ public class BSFEventProcessorReturningEventInfos
implements EventProcessor {
}
}
- // ////////////////////////////////////////////////////////////////////////
- //
- // same as above, but used when the method event method may generate
- // an exception which must go all the way back to the source (as in
- // the vetoableChange case)
-
public void processExceptionableEvent(final String inFilter, final
Object[] evtInfo) throws Exception {
// System.err.println(this+": inFilter=["+inFilter+"],
@@ -153,20 +169,4 @@ public class BSFEventProcessorReturningEventInfos
implements EventProcessor {
// System.err.println("returned from engine.exec.");
}
-
- private static boolean isFilteredEvent(final String filter, final String
inFilter) {
- boolean bRes = filter.equalsIgnoreCase(inFilter);
- if (bRes) {
- return bRes;
- }
-
- final String[] chunks = filter.replace('+', ' ').split(" ");
- for (int i = 0; i < chunks.length; i++) {
- bRes = chunks[i].equalsIgnoreCase(inFilter);
- if (bRes) {
- return bRes;
- }
- }
- return bRes;
- }
}
diff --git a/src/main/java/org/apache/bsf/util/cf/CFDriver.java
b/src/main/java/org/apache/bsf/util/cf/CFDriver.java
index 91b0d7b..4331a0a 100644
--- a/src/main/java/org/apache/bsf/util/cf/CFDriver.java
+++ b/src/main/java/org/apache/bsf/util/cf/CFDriver.java
@@ -38,12 +38,6 @@ import java.io.Writer;
*/
public class CFDriver {
- /**
- * Not used.
- */
- public CFDriver() {
- }
-
/**
* A driver for {@code CodeFormatter}.
* <p>
@@ -163,4 +157,10 @@ public class CFDriver {
System.out.println(" [-delim group] default: " +
CodeFormatter.DEFAULT_DELIM);
System.out.println(" [-sdelim group] default: " +
CodeFormatter.DEFAULT_S_DELIM);
}
+
+ /**
+ * Not used.
+ */
+ public CFDriver() {
+ }
}
diff --git
a/src/main/java/org/apache/bsf/util/event/generator/AdapterClassLoader.java
b/src/main/java/org/apache/bsf/util/event/generator/AdapterClassLoader.java
index 0a90d89..b19d543 100644
--- a/src/main/java/org/apache/bsf/util/event/generator/AdapterClassLoader.java
+++ b/src/main/java/org/apache/bsf/util/event/generator/AdapterClassLoader.java
@@ -31,7 +31,36 @@ import org.apache.bsf.BSF_LogFactory;
import java.util.Hashtable;
public class AdapterClassLoader extends ClassLoader {
+ /**
+ * Inner class to create a ClassLoader with the current Thread's class
loader as parent.
+ */
+ class LocalThreadClassLoader extends ClassLoader {
+ // public LocalThreadClassLoader(){super
(Thread.currentThread().getContextClassLoader());};
+ public LocalThreadClassLoader(final ClassLoader cl) {
+ super(cl);
+ }
+
+ public Class defineClass(final String name, final byte[] b) {
+ return defineClass(name, b, 0, b.length); // protected in
ClassLoader, hence invoking it this way
+ }
+
+ // use a signature that allows invoking super's protected method via
inheritance resolution
+ Class findClass(final String name, final char nixi) throws
ClassNotFoundException {
+ return findClass(name);
+ }
+
+ // use a signature that allows invoking super's protected method via
inheritance resolution
+ Class findLoadedClass(final String name, final char nixi) {
+ return findLoadedClass(name);
+ }
+
+ // use a signature that allows invoking super's protected method via
inheritance resolution
+ Class findSystemClass(final String name, final char nixi) throws
ClassNotFoundException {
+ return findSystemClass(name);
+ }
+ }
private static final Hashtable classCache = new Hashtable();
+
private Class c;
// private Log logger = LogFactory.getLog(this.getClass().getName());
@@ -132,33 +161,4 @@ public class AdapterClassLoader extends ClassLoader {
classCache.put(name, c);
}
- /**
- * Inner class to create a ClassLoader with the current Thread's class
loader as parent.
- */
- class LocalThreadClassLoader extends ClassLoader {
- // public LocalThreadClassLoader(){super
(Thread.currentThread().getContextClassLoader());};
- public LocalThreadClassLoader(final ClassLoader cl) {
- super(cl);
- }
-
- public Class defineClass(final String name, final byte[] b) {
- return defineClass(name, b, 0, b.length); // protected in
ClassLoader, hence invoking it this way
- }
-
- // use a signature that allows invoking super's protected method via
inheritance resolution
- Class findLoadedClass(final String name, final char nixi) {
- return findLoadedClass(name);
- }
-
- // use a signature that allows invoking super's protected method via
inheritance resolution
- Class findClass(final String name, final char nixi) throws
ClassNotFoundException {
- return findClass(name);
- }
-
- // use a signature that allows invoking super's protected method via
inheritance resolution
- Class findSystemClass(final String name, final char nixi) throws
ClassNotFoundException {
- return findSystemClass(name);
- }
- }
-
}
diff --git a/src/main/java/org/apache/bsf/util/event/generator/ByteUtility.java
b/src/main/java/org/apache/bsf/util/event/generator/ByteUtility.java
index 2036da9..a9c3a27 100644
--- a/src/main/java/org/apache/bsf/util/event/generator/ByteUtility.java
+++ b/src/main/java/org/apache/bsf/util/event/generator/ByteUtility.java
@@ -23,27 +23,27 @@ package org.apache.bsf.util.event.generator;
* 5 April 1999 - functions to append standard types to byte arrays functions
to produce standard types from byte arrays
*/
public class ByteUtility {
- public static byte[] addBytes(byte[] array, final byte[] value) {
+ public static byte[] addBytes(byte[] array, final byte value) {
if (array != null) {
- final byte[] newarray = new byte[array.length + value.length];
+ final byte[] newarray = new byte[array.length + 1];
System.arraycopy(array, 0, newarray, 0, array.length);
- System.arraycopy(value, 0, newarray, array.length, value.length);
+ newarray[newarray.length - 1] = value;
array = newarray;
} else {
- array = value;
+ array = new byte[1];
+ array[0] = value;
}
return array;
}
- public static byte[] addBytes(byte[] array, final byte value) {
+ public static byte[] addBytes(byte[] array, final byte[] value) {
if (array != null) {
- final byte[] newarray = new byte[array.length + 1];
+ final byte[] newarray = new byte[array.length + value.length];
System.arraycopy(array, 0, newarray, 0, array.length);
- newarray[newarray.length - 1] = value;
+ System.arraycopy(value, 0, newarray, array.length, value.length);
array = newarray;
} else {
- array = new byte[1];
- array[0] = value;
+ array = value;
}
return array;
}
@@ -84,20 +84,6 @@ public class ByteUtility {
return array;
}
- public static byte[] addBytes(byte[] array, final String value) {
- if (value != null) {
- if (array != null) {
- final byte[] newarray = new byte[array.length +
value.length()];
- System.arraycopy(array, 0, newarray, 0, array.length);
- System.arraycopy(value.getBytes(), 0, newarray, array.length,
value.length());
- array = newarray;
- } else {
- array = value.getBytes();
- }
- }
- return array;
- }
-
public static byte[] addBytes(byte[] array, final short value) {
if (array != null) {
final byte[] newarray = new byte[array.length + 2];
@@ -113,19 +99,18 @@ public class ByteUtility {
return array;
}
- public static double byteArrayToDouble(final byte high[], final byte
low[]) {
- double temp = 0;
- // high bytes
- temp += (((long) high[0]) & 0xFF) << 56;
- temp += (((long) high[1]) & 0xFF) << 48;
- temp += (((long) high[2]) & 0xFF) << 40;
- temp += (((long) high[3]) & 0xFF) << 32;
- // low bytes
- temp += (((long) low[0]) & 0xFF) << 24;
- temp += (((long) low[1]) & 0xFF) << 16;
- temp += (((long) low[2]) & 0xFF) << 8;
- temp += (((long) low[3]) & 0xFF);
- return temp;
+ public static byte[] addBytes(byte[] array, final String value) {
+ if (value != null) {
+ if (array != null) {
+ final byte[] newarray = new byte[array.length +
value.length()];
+ System.arraycopy(array, 0, newarray, 0, array.length);
+ System.arraycopy(value.getBytes(), 0, newarray, array.length,
value.length());
+ array = newarray;
+ } else {
+ array = value.getBytes();
+ }
+ }
+ return array;
}
public static double byteArrayToDouble(final byte value[]) {
@@ -142,6 +127,21 @@ public class ByteUtility {
return byteArrayToDouble(high, low);
}
+ public static double byteArrayToDouble(final byte high[], final byte
low[]) {
+ double temp = 0;
+ // high bytes
+ temp += (((long) high[0]) & 0xFF) << 56;
+ temp += (((long) high[1]) & 0xFF) << 48;
+ temp += (((long) high[2]) & 0xFF) << 40;
+ temp += (((long) high[3]) & 0xFF) << 32;
+ // low bytes
+ temp += (((long) low[0]) & 0xFF) << 24;
+ temp += (((long) low[1]) & 0xFF) << 16;
+ temp += (((long) low[2]) & 0xFF) << 8;
+ temp += (((long) low[3]) & 0xFF);
+ return temp;
+ }
+
public static float byteArrayToFloat(final byte value[]) {
float temp = 0;
temp += (value[0] & 0xFF) << 24;
diff --git a/src/test/java/org/apache/bsf/AbstractBSFEngineTest.java
b/src/test/java/org/apache/bsf/AbstractBSFEngineTest.java
index d68e200..22b8ad1 100644
--- a/src/test/java/org/apache/bsf/AbstractBSFEngineTest.java
+++ b/src/test/java/org/apache/bsf/AbstractBSFEngineTest.java
@@ -36,14 +36,12 @@ public abstract class AbstractBSFEngineTest {
tmpOut = new PrintStream(tmpBaos);
}
- public void setUp() {
- bsfManager = new BSFManager();
- System.setOut(tmpOut);
- }
-
- public void tearDown() {
- System.setOut(sysOut);
- resetTmpOut();
+ protected String failMessage(final String failure, final Exception e) {
+ String message = failure;
+ message += "\nReason:\n";
+ message += e.getMessage();
+ message += "\n";
+ return message;
}
protected String getTmpOutStr() {
@@ -54,11 +52,13 @@ public abstract class AbstractBSFEngineTest {
tmpBaos.reset();
}
- protected String failMessage(final String failure, final Exception e) {
- String message = failure;
- message += "\nReason:\n";
- message += e.getMessage();
- message += "\n";
- return message;
+ public void setUp() {
+ bsfManager = new BSFManager();
+ System.setOut(tmpOut);
+ }
+
+ public void tearDown() {
+ System.setOut(sysOut);
+ resetTmpOut();
}
}
diff --git a/src/test/java/org/apache/bsf/BSFEngineTestCase.java
b/src/test/java/org/apache/bsf/BSFEngineTestCase.java
index 93a8853..b227d3a 100644
--- a/src/test/java/org/apache/bsf/BSFEngineTestCase.java
+++ b/src/test/java/org/apache/bsf/BSFEngineTestCase.java
@@ -40,14 +40,12 @@ public abstract class BSFEngineTestCase extends TestCase {
tmpOut = new PrintStream(tmpBaos);
}
- public void setUp() {
- bsfManager = new BSFManager();
- System.setOut(tmpOut);
- }
-
- public void tearDown() {
- System.setOut(sysOut);
- resetTmpOut();
+ protected String failMessage(final String failure, final Exception e) {
+ String message = failure;
+ message += "\nReason:\n";
+ message += e.getMessage();
+ message += "\n";
+ return message;
}
protected String getTmpOutStr() {
@@ -58,11 +56,13 @@ public abstract class BSFEngineTestCase extends TestCase {
tmpBaos.reset();
}
- protected String failMessage(final String failure, final Exception e) {
- String message = failure;
- message += "\nReason:\n";
- message += e.getMessage();
- message += "\n";
- return message;
+ public void setUp() {
+ bsfManager = new BSFManager();
+ System.setOut(tmpOut);
+ }
+
+ public void tearDown() {
+ System.setOut(sysOut);
+ resetTmpOut();
}
}
diff --git a/src/test/java/org/apache/bsf/BSFTest.java
b/src/test/java/org/apache/bsf/BSFTest.java
index 29f4fd4..aec677f 100644
--- a/src/test/java/org/apache/bsf/BSFTest.java
+++ b/src/test/java/org/apache/bsf/BSFTest.java
@@ -35,10 +35,6 @@ import junit.textui.TestRunner;
public class BSFTest extends BSFEngineTestCase {
public static String[] testNames;
- public BSFTest(final String name) {
- super(name);
- }
-
public static void main(final String args[]) {
final TestRunner runner = new TestRunner();
final TestSuite suite = (TestSuite) suite();
@@ -77,21 +73,35 @@ public class BSFTest extends BSFEngineTestCase {
return suite;
}
+ public BSFTest(final String name) {
+ super(name);
+ }
+
public void setUp() {
super.setUp();
BSFManager.registerScriptingEngine("fakeEngine",
FakeEngine.class.getName(), new String[] { "fakeEng", "fE" });
}
- public void testRegisterEngine() {
- assertTrue(bsfManager.isLanguageRegistered("fakeEngine"));
+ public void testDeclareBean() {
+ try {
+ bsfManager.declareBean("foo", Integer.valueOf(1), Integer.class);
+ } catch (final Exception e) {
+ fail(failMessage("declareBean() test failed", e));
+ }
+
+ assertEquals(Integer.valueOf(1), (Integer)
bsfManager.lookupBean("foo"));
}
- public void testGetLangFromFileName() {
+ public void testEval() {
+ Boolean retval = Boolean.FALSE;
+
try {
- assertEquals("fakeEngine",
BSFManager.getLangFromFilename("Test.fE"));
+ retval = (Boolean) bsfManager.eval("fakeEngine", "Test.fE", 0, 0,
"Fake Syntax");
} catch (final Exception e) {
- fail(failMessage("getLangFromFilename() test failed", e));
+ fail(failMessage("eval() test failed", e));
}
+
+ assertTrue(retval.booleanValue());
}
public void testExec() {
@@ -104,16 +114,12 @@ public class BSFTest extends BSFEngineTestCase {
assertEquals("PASSED", getTmpOutStr());
}
- public void testEval() {
- Boolean retval = Boolean.FALSE;
-
+ public void testGetLangFromFileName() {
try {
- retval = (Boolean) bsfManager.eval("fakeEngine", "Test.fE", 0, 0,
"Fake Syntax");
+ assertEquals("fakeEngine",
BSFManager.getLangFromFilename("Test.fE"));
} catch (final Exception e) {
- fail(failMessage("eval() test failed", e));
+ fail(failMessage("getLangFromFilename() test failed", e));
}
-
- assertTrue(retval.booleanValue());
}
public void testIexec() {
@@ -126,14 +132,19 @@ public class BSFTest extends BSFEngineTestCase {
assertEquals("PASSED", getTmpOutStr());
}
- public void testDeclareBean() {
+ public void testRegisterEngine() {
+ assertTrue(bsfManager.isLanguageRegistered("fakeEngine"));
+ }
+
+ public void testTerminate() throws Exception {
try {
- bsfManager.declareBean("foo", Integer.valueOf(1), Integer.class);
+ bsfManager.loadScriptingEngine("fakeEngine");
+ bsfManager.terminate();
} catch (final Exception e) {
- fail(failMessage("declareBean() test failed", e));
+ fail(failMessage("terminate() test failed", e));
}
- assertEquals(Integer.valueOf(1), (Integer)
bsfManager.lookupBean("foo"));
+ assertEquals("PASSED", getTmpOutStr());
}
public void testUndeclareBean() {
@@ -146,15 +157,4 @@ public class BSFTest extends BSFEngineTestCase {
assertNull(bsfManager.lookupBean("foo"));
}
-
- public void testTerminate() throws Exception {
- try {
- bsfManager.loadScriptingEngine("fakeEngine");
- bsfManager.terminate();
- } catch (final Exception e) {
- fail(failMessage("terminate() test failed", e));
- }
-
- assertEquals("PASSED", getTmpOutStr());
- }
}
diff --git a/src/test/java/org/apache/bsf/FakeEngine.java
b/src/test/java/org/apache/bsf/FakeEngine.java
index 567c8c1..82e3b6b 100644
--- a/src/test/java/org/apache/bsf/FakeEngine.java
+++ b/src/test/java/org/apache/bsf/FakeEngine.java
@@ -29,11 +29,11 @@ public class FakeEngine extends BSFEngineImpl {
return Boolean.TRUE;
}
- public void iexec(final String source, final int lineNo, final int
columnNo, final Object script) throws BSFException {
+ public void exec(final String source, final int lineNo, final int
columnNo, final Object script) throws BSFException {
System.out.print("PASSED");
}
- public void exec(final String source, final int lineNo, final int
columnNo, final Object script) throws BSFException {
+ public void iexec(final String source, final int lineNo, final int
columnNo, final Object script) throws BSFException {
System.out.print("PASSED");
}
diff --git a/src/test/java/org/apache/bsf/engines/JaclTest.java
b/src/test/java/org/apache/bsf/engines/JaclTest.java
index 82cf997..2581f8b 100644
--- a/src/test/java/org/apache/bsf/engines/JaclTest.java
+++ b/src/test/java/org/apache/bsf/engines/JaclTest.java
@@ -47,24 +47,13 @@ public class JaclTest extends AbstractBSFEngineTest {
}
@Test
- public void testExec() {
- try {
- jaclEngine.exec("Test.jacl", 0, 0, "puts -nonewline \"PASSED\"");
- } catch (final Exception e) {
- fail(failMessage("exec() test failed", e));
- }
-
- assertEquals("PASSED", getTmpOutStr());
- }
-
- @Test
- public void testEval() {
+ public void testBSFManagerEval() {
Integer retval = null;
try {
- retval = (Integer) jaclEngine.eval("Test.jacl", 0, 0, "expr 1 +
1");
+ retval = (Integer) bsfManager.eval("jacl", "Test.jacl", 0, 0,
"expr 1 + 1");
} catch (final Exception e) {
- fail(failMessage("eval() test failed", e));
+ fail(failMessage("BSFManager eval() test failed", e));
}
assertEquals(Integer.valueOf(2), retval);
@@ -86,90 +75,101 @@ public class JaclTest extends AbstractBSFEngineTest {
}
@Test
- public void testIexec() {
+ public void testDeclareBean() {
+ final Integer foo = Integer.valueOf(1);
+ Integer bar = null;
+
try {
- jaclEngine.iexec("Test.jacl", 0, 0, "puts -nonewline \"PASSED\"");
+ bsfManager.declareBean("foo", foo, Integer.class);
+ bar = (Integer) jaclEngine.eval("Test.jacl", 0, 0, "proc ret {}
{\n upvar 1 foo lfoo\n return $lfoo\n }\n ret");
} catch (final Exception e) {
- fail(failMessage("iexec() test failed", e));
+ fail(failMessage("declareBean() test failed", e));
}
- assertEquals("PASSED", getTmpOutStr());
+ assertEquals(foo, bar);
}
@Test
- public void testBSFManagerEval() {
+ public void testEval() {
Integer retval = null;
try {
- retval = (Integer) bsfManager.eval("jacl", "Test.jacl", 0, 0,
"expr 1 + 1");
+ retval = (Integer) jaclEngine.eval("Test.jacl", 0, 0, "expr 1 +
1");
} catch (final Exception e) {
- fail(failMessage("BSFManager eval() test failed", e));
+ fail(failMessage("eval() test failed", e));
}
assertEquals(Integer.valueOf(2), retval);
}
@Test
- public void testRegisterBean() {
- final Integer foo = Integer.valueOf(1);
- Integer bar = null;
+ public void testExec() {
+ try {
+ jaclEngine.exec("Test.jacl", 0, 0, "puts -nonewline \"PASSED\"");
+ } catch (final Exception e) {
+ fail(failMessage("exec() test failed", e));
+ }
+
+ assertEquals("PASSED", getTmpOutStr());
+ }
+ @Test
+ public void testIexec() {
try {
- bsfManager.registerBean("foo", foo);
- bar = (Integer) jaclEngine.eval("Test.jacl", 0, 0, "bsf lookupBean
\"foo\"");
+ jaclEngine.iexec("Test.jacl", 0, 0, "puts -nonewline \"PASSED\"");
} catch (final Exception e) {
- fail(failMessage("registerBean() test failed", e));
+ fail(failMessage("iexec() test failed", e));
}
- assertEquals(foo, bar);
+ assertEquals("PASSED", getTmpOutStr());
}
@Test
- public void testUnregisterBean() {
+ public void testRegisterBean() {
final Integer foo = Integer.valueOf(1);
Integer bar = null;
try {
bsfManager.registerBean("foo", foo);
- bsfManager.unregisterBean("foo");
bar = (Integer) jaclEngine.eval("Test.jacl", 0, 0, "bsf lookupBean
\"foo\"");
- } catch (final BSFException bsfE) {
- // Do nothing. This is the expected case.
} catch (final Exception e) {
- fail(failMessage("unregisterBean() test failed", e));
+ fail(failMessage("registerBean() test failed", e));
}
- assertNull(bar);
+ assertEquals(foo, bar);
}
@Test
- public void testDeclareBean() {
+ public void testUndeclareBean() {
final Integer foo = Integer.valueOf(1);
Integer bar = null;
try {
bsfManager.declareBean("foo", foo, Integer.class);
- bar = (Integer) jaclEngine.eval("Test.jacl", 0, 0, "proc ret {}
{\n upvar 1 foo lfoo\n return $lfoo\n }\n ret");
+ bsfManager.undeclareBean("foo");
+ bar = (Integer) jaclEngine.eval("Test.jacl", 0, 0, "expr $foo +
1");
} catch (final Exception e) {
- fail(failMessage("declareBean() test failed", e));
+ fail(failMessage("undeclareBean() test failed", e));
}
assertEquals(foo, bar);
}
@Test
- public void testUndeclareBean() {
+ public void testUnregisterBean() {
final Integer foo = Integer.valueOf(1);
Integer bar = null;
try {
- bsfManager.declareBean("foo", foo, Integer.class);
- bsfManager.undeclareBean("foo");
- bar = (Integer) jaclEngine.eval("Test.jacl", 0, 0, "expr $foo +
1");
+ bsfManager.registerBean("foo", foo);
+ bsfManager.unregisterBean("foo");
+ bar = (Integer) jaclEngine.eval("Test.jacl", 0, 0, "bsf lookupBean
\"foo\"");
+ } catch (final BSFException bsfE) {
+ // Do nothing. This is the expected case.
} catch (final Exception e) {
- fail(failMessage("undeclareBean() test failed", e));
+ fail(failMessage("unregisterBean() test failed", e));
}
- assertEquals(foo, bar);
+ assertNull(bar);
}
}
diff --git a/src/test/java/org/apache/bsf/engines/JavascriptTest.java
b/src/test/java/org/apache/bsf/engines/JavascriptTest.java
index 7d69dd4..551a781 100644
--- a/src/test/java/org/apache/bsf/engines/JavascriptTest.java
+++ b/src/test/java/org/apache/bsf/engines/JavascriptTest.java
@@ -44,21 +44,22 @@ public class JavascriptTest extends BSFEngineTestCase {
}
}
- public void testExec() {
+ public void testBSFManagerAvailability() {
+ Object retval = null;
try {
- engine.exec("Test.js", 0, 0, "java.lang.System.out.print
(\"PASSED\");");
+ retval = engine.eval("Test.js", 0, 0, "bsf.lookupBean(\"foo\")");
} catch (final Exception e) {
- fail(failMessage("exec() test failed", e));
+ fail(failMessage("Test of BSFManager availability failed", e));
}
- assertEquals("PASSED", getTmpOutStr());
+ assertNull(retval);
}
- public void testEval() {
+ public void testBSFManagerEval() {
Double retval = null;
try {
- retval = Double.valueOf((engine.eval("Test.js", 0, 0, "1 +
1").toString()));
+ retval = Double.valueOf((bsfManager.eval("javascript", "Test.js",
0, 0, "1 + 1")).toString());
} catch (final Exception e) {
- fail(failMessage("eval() test failed", e));
+ fail(failMessage("BSFManager eval() test failed", e));
}
assertEquals(2.0, retval);
}
@@ -75,83 +76,82 @@ public class JavascriptTest extends BSFEngineTestCase {
assertEquals(2.0, retval);
}
- public void testIexec() {
+ public void testDeclareBean() {
+ final Double foo = 1.0;
+ Double bar = null;
try {
- engine.iexec("Test.js", 0, 0, "java.lang.System.out.print
(\"PASSED\")");
+ bsfManager.declareBean("foo", foo, Double.class);
+ bar = (Double) engine.eval("Test.js", 0, 0, "foo + 1");
} catch (final Exception e) {
- fail(failMessage("iexec() test failed", e));
+ fail(failMessage("declareBean() test failed", e));
}
- assertEquals("PASSED", getTmpOutStr());
+ assertEquals(2.0, bar);
}
- public void testBSFManagerEval() {
+ public void testEval() {
Double retval = null;
try {
- retval = Double.valueOf((bsfManager.eval("javascript", "Test.js",
0, 0, "1 + 1")).toString());
+ retval = Double.valueOf((engine.eval("Test.js", 0, 0, "1 +
1").toString()));
} catch (final Exception e) {
- fail(failMessage("BSFManager eval() test failed", e));
+ fail(failMessage("eval() test failed", e));
}
assertEquals(2.0, retval);
}
- public void testBSFManagerAvailability() {
- Object retval = null;
+ public void testExec() {
try {
- retval = engine.eval("Test.js", 0, 0, "bsf.lookupBean(\"foo\")");
+ engine.exec("Test.js", 0, 0, "java.lang.System.out.print
(\"PASSED\");");
} catch (final Exception e) {
- fail(failMessage("Test of BSFManager availability failed", e));
+ fail(failMessage("exec() test failed", e));
}
- assertNull(retval);
+ assertEquals("PASSED", getTmpOutStr());
}
- public void testRegisterBean() {
- final Double foo = 1.0;
- Double bar = null;
+ public void testIexec() {
try {
- bsfManager.registerBean("foo", foo);
- bar = (Double) engine.eval("Test.js", 0, 0,
"bsf.lookupBean(\"foo\")");
+ engine.iexec("Test.js", 0, 0, "java.lang.System.out.print
(\"PASSED\")");
} catch (final Exception e) {
- fail(failMessage("registerBean() test failed", e));
+ fail(failMessage("iexec() test failed", e));
}
- assertEquals(foo, bar);
+ assertEquals("PASSED", getTmpOutStr());
}
- public void testUnregisterBean() {
+ public void testRegisterBean() {
final Double foo = 1.0;
Double bar = null;
try {
bsfManager.registerBean("foo", foo);
- bsfManager.unregisterBean("foo");
bar = (Double) engine.eval("Test.js", 0, 0,
"bsf.lookupBean(\"foo\")");
} catch (final Exception e) {
- fail(failMessage("unregisterBean() test failed", e));
+ fail(failMessage("registerBean() test failed", e));
}
- assertNull(bar);
+ assertEquals(foo, bar);
}
- public void testDeclareBean() {
+ public void testUndeclareBean() {
final Double foo = 1.0;
Double bar = null;
try {
bsfManager.declareBean("foo", foo, Double.class);
+ bsfManager.undeclareBean("foo");
bar = (Double) engine.eval("Test.js", 0, 0, "foo + 1");
+ } catch (final BSFException bsfE) {
+ // Do nothing. This is the expected case.
} catch (final Exception e) {
- fail(failMessage("declareBean() test failed", e));
+ fail(failMessage("undeclareBean() test failed", e));
}
- assertEquals(2.0, bar);
+ assertNull(bar);
}
- public void testUndeclareBean() {
+ public void testUnregisterBean() {
final Double foo = 1.0;
Double bar = null;
try {
- bsfManager.declareBean("foo", foo, Double.class);
- bsfManager.undeclareBean("foo");
- bar = (Double) engine.eval("Test.js", 0, 0, "foo + 1");
- } catch (final BSFException bsfE) {
- // Do nothing. This is the expected case.
+ bsfManager.registerBean("foo", foo);
+ bsfManager.unregisterBean("foo");
+ bar = (Double) engine.eval("Test.js", 0, 0,
"bsf.lookupBean(\"foo\")");
} catch (final Exception e) {
- fail(failMessage("undeclareBean() test failed", e));
+ fail(failMessage("unregisterBean() test failed", e));
}
assertNull(bar);
}
diff --git a/src/test/java/org/apache/bsf/engines/JythonTest.java
b/src/test/java/org/apache/bsf/engines/JythonTest.java
index 5ceded1..bda4a50 100644
--- a/src/test/java/org/apache/bsf/engines/JythonTest.java
+++ b/src/test/java/org/apache/bsf/engines/JythonTest.java
@@ -41,23 +41,25 @@ public class JythonTest extends BSFEngineTestCase {
}
}
- public void testExec() {
+ public void testBSFManagerAvailability() {
+ Object retval = null;
+
try {
- jythonEngine.exec("Test.py", 0, 0, "print \"PASSED\",");
+ retval = jythonEngine.eval("Test.py", 0, 0,
"bsf.lookupBean(\"foo\")");
} catch (final Exception e) {
- fail(failMessage("exec() test failed", e));
+ fail(failMessage("Test of BSFManager availability failed", e));
}
- assertEquals("PASSED", getTmpOutStr());
+ assertEquals("None", retval.toString());
}
- public void testEval() {
+ public void testBSFManagerEval() {
Integer retval = null;
try {
- retval = Integer.valueOf((jythonEngine.eval("Test.py", 0, 0, "1 +
1")).toString());
+ retval = Integer.valueOf((bsfManager.eval("jython", "Test.py", 0,
0, "1 + 1")).toString());
} catch (final Exception e) {
- fail(failMessage("eval() test failed", e));
+ fail(failMessage("BSFManager eval() test failed", e));
}
assertEquals(Integer.valueOf(2), retval);
@@ -77,99 +79,97 @@ public class JythonTest extends BSFEngineTestCase {
assertEquals(Integer.valueOf(2), retval);
}
- public void testIexec() {
- // iexec() differs from exec() in this engine, primarily
- // in that it only executes up to the first newline.
+ public void testDeclareBean() {
+ final Integer foo = Integer.valueOf(1);
+ Integer bar = null;
+
try {
- jythonEngine.iexec("Test.py", 0, 0, "print \"PASSED\",\nprint
\"FAILED\",");
+ bsfManager.declareBean("foo", foo, Integer.class);
+ bar = Integer.valueOf((jythonEngine.eval("Test.py", 0, 0, "foo +
1")).toString());
} catch (final Exception e) {
- fail(failMessage("iexec() test failed", e));
+ fail(failMessage("declareBean() test failed", e));
}
- assertEquals("PASSED", getTmpOutStr());
+ assertEquals(Integer.valueOf(2), bar);
}
- public void testBSFManagerEval() {
+ public void testEval() {
Integer retval = null;
try {
- retval = Integer.valueOf((bsfManager.eval("jython", "Test.py", 0,
0, "1 + 1")).toString());
+ retval = Integer.valueOf((jythonEngine.eval("Test.py", 0, 0, "1 +
1")).toString());
} catch (final Exception e) {
- fail(failMessage("BSFManager eval() test failed", e));
+ fail(failMessage("eval() test failed", e));
}
assertEquals(Integer.valueOf(2), retval);
}
- public void testBSFManagerAvailability() {
- Object retval = null;
-
+ public void testExec() {
try {
- retval = jythonEngine.eval("Test.py", 0, 0,
"bsf.lookupBean(\"foo\")");
+ jythonEngine.exec("Test.py", 0, 0, "print \"PASSED\",");
} catch (final Exception e) {
- fail(failMessage("Test of BSFManager availability failed", e));
+ fail(failMessage("exec() test failed", e));
}
- assertEquals("None", retval.toString());
+ assertEquals("PASSED", getTmpOutStr());
}
- public void testRegisterBean() {
- final Integer foo = Integer.valueOf(1);
- Integer bar = null;
-
+ public void testIexec() {
+ // iexec() differs from exec() in this engine, primarily
+ // in that it only executes up to the first newline.
try {
- bsfManager.registerBean("foo", foo);
- bar = Integer.valueOf((jythonEngine.eval("Test.py", 0, 0,
"bsf.lookupBean(\"foo\")")).toString());
+ jythonEngine.iexec("Test.py", 0, 0, "print \"PASSED\",\nprint
\"FAILED\",");
} catch (final Exception e) {
- fail(failMessage("registerBean() test failed", e));
+ fail(failMessage("iexec() test failed", e));
}
- assertEquals(foo, bar);
+ assertEquals("PASSED", getTmpOutStr());
}
- public void testUnregisterBean() {
+ public void testRegisterBean() {
final Integer foo = Integer.valueOf(1);
- Object bar = null;
+ Integer bar = null;
try {
bsfManager.registerBean("foo", foo);
- bsfManager.unregisterBean("foo");
- bar = jythonEngine.eval("Test.py", 0, 0,
"bsf.lookupBean(\"foo\")");
+ bar = Integer.valueOf((jythonEngine.eval("Test.py", 0, 0,
"bsf.lookupBean(\"foo\")")).toString());
} catch (final Exception e) {
- fail(failMessage("unregisterBean() test failed", e));
+ fail(failMessage("registerBean() test failed", e));
}
- assertEquals("None", bar.toString());
+ assertEquals(foo, bar);
}
- public void testDeclareBean() {
+ public void testUndeclareBean() {
final Integer foo = Integer.valueOf(1);
Integer bar = null;
try {
bsfManager.declareBean("foo", foo, Integer.class);
+ bsfManager.undeclareBean("foo");
bar = Integer.valueOf((jythonEngine.eval("Test.py", 0, 0, "foo +
1")).toString());
+ } catch (final BSFException bsfE) {
+ // Do nothing. This is the expected case.
} catch (final Exception e) {
- fail(failMessage("declareBean() test failed", e));
+ fail(failMessage("undeclareBean() test failed", e));
}
- assertEquals(Integer.valueOf(2), bar);
+ assertNull(bar);
}
- public void testUndeclareBean() {
+ public void testUnregisterBean() {
final Integer foo = Integer.valueOf(1);
- Integer bar = null;
+ Object bar = null;
try {
- bsfManager.declareBean("foo", foo, Integer.class);
- bsfManager.undeclareBean("foo");
- bar = Integer.valueOf((jythonEngine.eval("Test.py", 0, 0, "foo +
1")).toString());
- } catch (final BSFException bsfE) {
- // Do nothing. This is the expected case.
+ bsfManager.registerBean("foo", foo);
+ bsfManager.unregisterBean("foo");
+ bar = jythonEngine.eval("Test.py", 0, 0,
"bsf.lookupBean(\"foo\")");
} catch (final Exception e) {
- fail(failMessage("undeclareBean() test failed", e));
+ fail(failMessage("unregisterBean() test failed", e));
}
- assertNull(bar);
+ assertEquals("None", bar.toString());
}
}
diff --git a/src/test/java/org/apache/bsf/engines/NetrexxTest_IGNORE.java
b/src/test/java/org/apache/bsf/engines/NetrexxTest_IGNORE.java
index b72308c..193c62b 100644
--- a/src/test/java/org/apache/bsf/engines/NetrexxTest_IGNORE.java
+++ b/src/test/java/org/apache/bsf/engines/NetrexxTest_IGNORE.java
@@ -48,6 +48,30 @@ public class NetrexxTest_IGNORE extends BSFEngineTestCase {
super.tearDown();
}
+ public void ignore_testBSFManagerAvailability() {
+ Object retValue = null;
+
+ try {
+ retValue = bsfManager.eval("netrexx", "Test.nrx", 0, 0,
"bsf.lookupBean(\"foo\")");
+ } catch (final Exception ex) {
+ fail(failMessage("BSFManagerAvailability() test failed", ex));
+ }
+
+ assertNull(retValue);
+ }
+
+ public void ignore_testBSFManagerEval() {
+ Object retValue = null;
+
+ try {
+ retValue = Integer.valueOf((bsfManager.eval("netrexx", "Test.nrx",
0, 0, "1 + (-1)")).toString());
+ } catch (final Exception ex) {
+ fail(failMessage("BSFManagerEval() test failed", ex));
+ }
+
+ assertEquals(retValue, Integer.valueOf(0));
+ }
+
public void ignore_testDeclareBean() {
final Integer foo = Integer.valueOf(0);
Integer bar = null;
@@ -62,6 +86,16 @@ public class NetrexxTest_IGNORE extends BSFEngineTestCase {
assertEquals(bar, Integer.valueOf(1));
}
+ public void ignore_testExec() {
+ try {
+ netrexxEngine.exec("Test.nrx", 0, 0, "say \"PASSED\"");
+ } catch (final BSFException bsfe) {
+ fail(failMessage("exec() test fail", bsfe));
+ }
+
+ assertEquals("PASSED" + lineSeparatorStr, getTmpOutStr());
+ }
+
public void ignore_testRegisterBean() {
final Integer foo = Integer.valueOf(0);
Integer bar = null;
@@ -76,16 +110,6 @@ public class NetrexxTest_IGNORE extends BSFEngineTestCase {
assertEquals(bar, Integer.valueOf(0));
}
- public void ignore_testExec() {
- try {
- netrexxEngine.exec("Test.nrx", 0, 0, "say \"PASSED\"");
- } catch (final BSFException bsfe) {
- fail(failMessage("exec() test fail", bsfe));
- }
-
- assertEquals("PASSED" + lineSeparatorStr, getTmpOutStr());
- }
-
public void ignore_testUndeclareBean() {
// FIXME: Netrexx is a little chatty about the missing variable...
final Integer foo = Integer.valueOf(0);
@@ -119,30 +143,6 @@ public class NetrexxTest_IGNORE extends BSFEngineTestCase {
assertNull(retValue);
}
- public void ignore_testBSFManagerAvailability() {
- Object retValue = null;
-
- try {
- retValue = bsfManager.eval("netrexx", "Test.nrx", 0, 0,
"bsf.lookupBean(\"foo\")");
- } catch (final Exception ex) {
- fail(failMessage("BSFManagerAvailability() test failed", ex));
- }
-
- assertNull(retValue);
- }
-
- public void ignore_testBSFManagerEval() {
- Object retValue = null;
-
- try {
- retValue = Integer.valueOf((bsfManager.eval("netrexx", "Test.nrx",
0, 0, "1 + (-1)")).toString());
- } catch (final Exception ex) {
- fail(failMessage("BSFManagerEval() test failed", ex));
- }
-
- assertEquals(retValue, Integer.valueOf(0));
- }
-
public void testAllIgnoredUntilNetrexxIsSetUp() {
// empty
}
diff --git a/src/test/java/org/apache/bsf/util/TestBean.java
b/src/test/java/org/apache/bsf/util/TestBean.java
index 5c8aa26..c7b6861 100644
--- a/src/test/java/org/apache/bsf/util/TestBean.java
+++ b/src/test/java/org/apache/bsf/util/TestBean.java
@@ -34,6 +34,14 @@ public class TestBean implements Serializable {
this.strValue = value;
}
+ public Number getNumericValue() {
+ return numValue;
+ }
+
+ public String getStringValue() {
+ return strValue;
+ }
+
public void setValue(final String value) {
this.strValue = value;
}
@@ -42,12 +50,4 @@ public class TestBean implements Serializable {
this.strValue = sValue;
this.numValue = nValue;
}
-
- public String getStringValue() {
- return strValue;
- }
-
- public Number getNumericValue() {
- return numValue;
- }
}