From:  Kenneth <>
Date:  25 Aug 2006 00:01:42 Hong Kong Time

Java String and switch/case statements

NNTP-Posting-Host:  null

I am having troubles getting the switch/case statements to work with
Java Strings.

To execute my script I have the following code:

public void runScript(String script) {
	Controller controller = new Controller();
	RhinoScriptEngineFactory factory = new RhinoScriptEngineFactory();
	ScriptEngine jsEngine = factory.getScriptEngine();
	Invocable jsInvoke = (Invocable) jsEngine;"run", new Object[]{controller});

If I try the following script, I get "it worked" in the debug logs:

function run(c) {
	var action = "begin";
	switch(action) {
		case "begin":
			c.debug("it worked");
			c.debug("it failed");

But, if I try the following script, I get "it failed" in the debug logs:

function run(c) {
	var action = c.getAction();  // returns Java String "begin"

I did find a reference that if I convert the Java String to a JavaScript
String, that it should work.  I tried the following, which did work:

function run(c) {
	var action = String( c.getAction() );  // returns Java String "begin"

So my question is, I would prefer to not have my users have to know this
quirk.  Is there a way to either have my Java method return a JavaScript
string, or is there possibly a patch for Rhino that addresses this issue?

Thanks in advance,

Posted via a free Usenet account from