Subj : Re: e4x Rhino question To : netscape.public.mozilla.jseng From : Igor Bukanov Date : Thu Sep 23 2004 04:46 pm -------- Original Message -------- Subject: RE: e4x Rhino question Date: Thu, 23 Sep 2004 08:41:53 -0500 From: Francis Sullivan To: Igor Bukanov That is interesting - thanks for the suggestion. It looks like I have two other versions of javax.xml.namespace.QName in my classpath (I have many jar files in my classpath), and that would explain it. The culprit is: jaxrpc.jar 2383 Fri Jun 13 09:19:36 CDT 2003 javax/xml/namespace/QName.class BTW, I am using a 1.4.* jvm c:/ jre(599)$ bin/java -version java version "1.4.2_03" Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_03-b02) Java HotSpot(TM) Client VM (build 1.4.2_03-b02, mixed mode) Thanks for the pointer Igor. That saved me a bunch of time... -----Original Message----- From: Igor Bukanov [mailto:igor@fastmail.fm] Sent: Thursday, September 23, 2004 8:16 AM To: Francis Sullivan Subject: Re: e4x Rhino question [Note: the message is cross-posted to netscape.public.mozilla.jseng newsgroup.] Which version of JVM do you use? For E4X implementation Rhino uses http://xmlbeans.apache.org/. Their xmlbean.jar includes for convenience javax.xml.namespace.QName which is provided in J2EE 1.4.* as well. AFAIK some earlier J2EE distributions included a version of javax.xml.namespace.QName without getPrefix() so if that class takes precedence over the one supplied in xmlbean.jar, then the code obviously would not work. Regards, Igor Francis Sullivan wrote: > Hi Igor, > > > > First, let me say that I'm really impressed with E4X Rhino. It is such > an obviously better way to process XML from javascript. > > > > I have a question that you might be able to point me in the right > direction to track down: > > > > I have narrowed this down to a very simple script that is trying to > iterate through attributes name, value pair: > > > > var vxml = > > > > > > > > > > ; > > > > var hm = java.util.HashMap(); > > for each (var a in vxml.attributes()) { > > print ("X=" + a); > > hm.put(a.name(), a); > > } > > print (hm); > > > > > > It works just fine when I run it through the javascript shell: > > c:/rhino1_6R1(555)$ java -cp "js.jar;xbean.jar" > org.mozilla.javascript.tools.shell.Main /temp/test.js > > X=a1 > > X=a2 > > X=a3 > > X=a4 > > X=a5 > > {aAttr4=a4, aAttr3=a3, aAttr2=a2, aAttr1=a1, aAttr5=a5} > > > > > > However, we have some code that embeds Rhino, and I get the following > exception: > > X=a1 > > java.lang.NoSuchMethodError: > javax.xml.namespace.QName.getPrefix()Ljava/lang/String; > > at org.mozilla.javascript.xmlimpl.XML.name(XML.java:2332) > > at > org.mozilla.javascript.xmlimpl.XMLObjectImpl.execIdCall(XMLObjectImpl.ja va:565) > > at > org.mozilla.javascript.IdFunctionObject.call(IdFunctionObject.java:122) > > at > org.mozilla.javascript.xmlimpl.XMLList.call(XMLList.java:1578) > > at > org.mozilla.javascript.Interpreter.interpret(Interpreter.java:2613) > > at > org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java :143) > > at > org.mozilla.javascript.ScriptRuntime.evalSpecial(ScriptRuntime.java:2223 ) > > at > org.mozilla.javascript.ScriptRuntime.callSpecial(ScriptRuntime.java:2079 ) > > at > org.mozilla.javascript.optimizer.OptRuntime.callSpecial(OptRuntime.java: 201) > > at > org.mozilla.javascript.gen.c2._c1(InstrumentationExecutive.js:63) > > at > org.mozilla.javascript.gen.c2.call(InstrumentationExecutive.js) > > at > org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:2771) > > at > org.mozilla.javascript.gen.c2.call(InstrumentationExecutive.js) > > at > org.mozilla.javascript.ScriptableObject.callMethod(ScriptableObject.java :1518) > > at > org.mozilla.javascript.ScriptableObject.callMethod(ScriptableObject.java :1497) > > > > > > Naturally, I'm assuming that I am not embedding Rhino Properly, but the > call to the name() function on an attribute croaks in the embedded > version. Do you have any idea what I might be doing wrong? > > > > The code that embeds rhino runs a couple of javascript scripts, the > second of which evals the above code fragment. > > > > // Begin JavaScript > > Context cx = Context.enter(); > > > > // Initialize the standard objects > (Object, Function, etc.) > > // This must be done before scripts > can be executed. > > Scriptable scope = > cx.initStandardObjects(null); > > > > // Now we can evaluate a script. > Let's create a new object > > // using the object literal notation. > > Object result = null; > > try > > > { > > > String code = > getScriptCode("script1.js"); > > String code2 = > getScriptCode("script2.js"); > > result = > cx.evaluateString(scope, code2, "script2.js", 1, null); > > result = > cx.evaluateString(scope, code, "script1.js", 1, null); > > Object[] args = new > Object[] { "arg1", "arg2", null}; > > result = > ScriptableObject.callMethod(scope, "myMethod", args); > > } > > catch (JavaScriptException jse) > > { > > jse.printStackTrace(); > > } > > > > Context.exit(); > > > > Thanks for any help on this, and again, great work! > .