You are viewing a plain text version of this content. The canonical link for it is here.
Posted to bsf-user@jakarta.apache.org by "Mark R. Diggory" <md...@latte.harvard.edu> on 2003/01/30 01:50:07 UTC

BSF and defining primitive types.

I'm currently working on a taglibrary for Jelly that does two things

1.) Allows one to "Build" new Classes using BCEL. This supports creation 
of new "properties" with getters and/or setters. I handle this entirely 
with the BCEL library.

2.) Support for creating new "methods" that use BSF as a mechanism to 
exec scripts defining the actions/behaviors of those new methods. (See 
my privious thread in the Jelly list).

http://www.mail-archive.com/commons-user@jakarta.apache.org/msg01591.html

and on the BCEL list:

http://www.mail-archive.com/commons-dev@jakarta.apache.org/msg15546.html


My questions concern issue to do with "primitives" and appropriate 
behavior in BSF..

I'm generating methods that look something like this (simplified):

public Object myMethod(int foo, java.lang.Double bar )
throws com.ibm.bsf.BSFException{

         manager.declareBean("foo", new Integer(foo), Integer.class);
         manager.declareBean("bar", bar, bar.getClass());

         BSFEngine engine = manager.loadScriptingEngine("javascript");

         return engine.eval("my_class.my_generated_method",0, 0, 
"foo+bar;");

}

from jelly script that looks something like:

<bcel:class name="Foo">
	<bcel:property name="hello" type="java.lang.String"/>
	<bcel:method>
		<bcel:arg name="foo" type="int"/>
		<bcel:arg name="bar" type="java.lang.Double/>
		<bcel:body engine="bsf" language="javascript">
			foo + bar;
		</bcel:body>
	</bcel:method>
</bcel:class>

My question concerns appropriate issues with registering primitives, 
you'll notice I'm using:

manager.declareBean("foo", new Integer(foo), Integer.class);

my concern is that this wrapping should still allow:

"foo+bar"

to function properly

I'm wondering if my approach is best concerning the design of 
BSFEngine/Manager and it behavior with such objects? I notice no clearly 
defined methods for registering primitives.

Should I define it the "Integer.class" as its defined class or 
"int.class" as its defined class? I'm assuming Integer.class, but it 
unclear to me if BSF has any "unwrapping" going on internally.

-thanks,
Mark Diggory






Re: [jelly] [BSF] Loading Scripting Engines

Posted by "Mark R. Diggory" <md...@latte.harvard.edu>.
Thanks, that was it, all seems better now -

Maybe it would be ideal to document somwhere which jars are required to 
support which languages. But I suspect this is something that would be 
dealt with on the BSF site and not  the Jelly site (while the 
documenation for the Jelly BSF Taglibrary might point to the BSF site 
with a salient comment that you need to get such things to use the 
taglibrary in Jelly).

thanks for the help,
Mark

p.s. the BCEL/BSF Class Builder taglibrary is coming along, I've been 
debugging some classes which support "BCEL generation" of "BSF backed" 
methods, Seems to function with few inital problems (relating to my 
limited knowledge of BCEL). Now I just need to add the tags for it to 
the library.

James Strachan wrote:

>It looks like you need to add rhino.jar to your classpath. BSF is a
>universal API to scripting languages, but you also need to add the scripting
>langauge implementation jar to the classpath too (e.g. rhino for JavaScript,
>jython, beanshell etc).
>
>http://www.ibiblio.org/maven/rhino/jars/
>
>James
>-------
>http://radio.weblogs.com/0112098/
>----- Original Message -----
>From: "Mark R. Diggory" <md...@latte.harvard.edu>
>To: "Jakarta Commons Users List" <co...@jakarta.apache.org>
>Sent: Thursday, January 30, 2003 4:17 AM
>Subject: [jelly] [BSF] Loading Scripting Engines
>
>
>  
>
>>I'm having problems loading the javascript ScriptingEngine in version
>>2.2 of BSF that is present in the jelly BSF Taglibrary
>>
>>where and what is org/mozilla/javascript/JavaScriptException
>>
>>unable to load language: javascript: java.lang.NoClassDefFoundError:
>>org/mozilla/javascript/JavaScriptException
>>         at java.lang.Class.getDeclaredConstructors0(Native Method)
>>         at
>>    
>>
>java.lang.Class.privateGetDeclaredConstructors(Class.java:1576)
>  
>
>>         at java.lang.Class.getConstructor0(Class.java:1748)
>>         at java.lang.Class.newInstance0(Class.java:266)
>>         at java.lang.Class.newInstance(Class.java:249)
>>         at com.ibm.bsf.BSFManager.loadScriptingEngine(Unknown Source)
>>         at
>>    
>>
>org.apache.commons.jelly.tags.bcel.Test.myMethod2(Test.java:36)
>  
>
>>         at org.apache.commons.jelly.tags.bcel.Test.main(Test.java:45)
>>Exception in thread "main"
>>
>>
>>seems to occur when I do
>>
>>BSFEngine engine = manager.loadScriptingEngine("javascript");
>>
>>Am I missing something obvious concerning loading Scripting engines?
>>
>>-Mark
>>
>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: bsf-user-unsubscribe@jakarta.apache.org
>>For additional commands, e-mail: bsf-user-help@jakarta.apache.org
>>
>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
>>For additional commands, e-mail: commons-user-help@jakarta.apache.org
>>
>>    
>>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
>  
>



Re: [jelly] [BSF] Loading Scripting Engines

Posted by James Strachan <ja...@yahoo.co.uk>.
It looks like you need to add rhino.jar to your classpath. BSF is a
universal API to scripting languages, but you also need to add the scripting
langauge implementation jar to the classpath too (e.g. rhino for JavaScript,
jython, beanshell etc).

http://www.ibiblio.org/maven/rhino/jars/

James
-------
http://radio.weblogs.com/0112098/
----- Original Message -----
From: "Mark R. Diggory" <md...@latte.harvard.edu>
To: "Jakarta Commons Users List" <co...@jakarta.apache.org>
Sent: Thursday, January 30, 2003 4:17 AM
Subject: [jelly] [BSF] Loading Scripting Engines


> I'm having problems loading the javascript ScriptingEngine in version
> 2.2 of BSF that is present in the jelly BSF Taglibrary
>
> where and what is org/mozilla/javascript/JavaScriptException
>
> unable to load language: javascript: java.lang.NoClassDefFoundError:
> org/mozilla/javascript/JavaScriptException
>          at java.lang.Class.getDeclaredConstructors0(Native Method)
>          at
java.lang.Class.privateGetDeclaredConstructors(Class.java:1576)
>          at java.lang.Class.getConstructor0(Class.java:1748)
>          at java.lang.Class.newInstance0(Class.java:266)
>          at java.lang.Class.newInstance(Class.java:249)
>          at com.ibm.bsf.BSFManager.loadScriptingEngine(Unknown Source)
>          at
org.apache.commons.jelly.tags.bcel.Test.myMethod2(Test.java:36)
>          at org.apache.commons.jelly.tags.bcel.Test.main(Test.java:45)
> Exception in thread "main"
>
>
> seems to occur when I do
>
> BSFEngine engine = manager.loadScriptingEngine("javascript");
>
> Am I missing something obvious concerning loading Scripting engines?
>
> -Mark
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: bsf-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: bsf-user-help@jakarta.apache.org
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>


[jelly] [BSF] Loading Scripting Engines

Posted by "Mark R. Diggory" <md...@latte.harvard.edu>.
I'm having problems loading the javascript ScriptingEngine in version 
2.2 of BSF that is present in the jelly BSF Taglibrary

where and what is org/mozilla/javascript/JavaScriptException

unable to load language: javascript: java.lang.NoClassDefFoundError:
org/mozilla/javascript/JavaScriptException
         at java.lang.Class.getDeclaredConstructors0(Native Method)
         at java.lang.Class.privateGetDeclaredConstructors(Class.java:1576)
         at java.lang.Class.getConstructor0(Class.java:1748)
         at java.lang.Class.newInstance0(Class.java:266)
         at java.lang.Class.newInstance(Class.java:249)
         at com.ibm.bsf.BSFManager.loadScriptingEngine(Unknown Source)
         at org.apache.commons.jelly.tags.bcel.Test.myMethod2(Test.java:36)
         at org.apache.commons.jelly.tags.bcel.Test.main(Test.java:45)
Exception in thread "main"


seems to occur when I do

BSFEngine engine = manager.loadScriptingEngine("javascript");

Am I missing something obvious concerning loading Scripting engines?

-Mark



---------------------------------------------------------------------
To unsubscribe, e-mail: bsf-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: bsf-user-help@jakarta.apache.org



Loading Scripting Engines

Posted by "Mark R. Diggory" <md...@latte.harvard.edu>.
I'm having problems loading the javascript ScriptingEngine in version 2.2

unable to load language: javascript: java.lang.NoClassDefFoundError: 
org/mozilla/javascript/JavaScriptException
         at java.lang.Class.getDeclaredConstructors0(Native Method)
         at java.lang.Class.privateGetDeclaredConstructors(Class.java:1576)
         at java.lang.Class.getConstructor0(Class.java:1748)
         at java.lang.Class.newInstance0(Class.java:266)
         at java.lang.Class.newInstance(Class.java:249)
         at com.ibm.bsf.BSFManager.loadScriptingEngine(Unknown Source)
         at org.apache.commons.jelly.tags.bcel.Test.myMethod2(Test.java:36)
         at org.apache.commons.jelly.tags.bcel.Test.main(Test.java:45)
Exception in thread "main"


seems to occur when I do

BSFEngine engine = manager.loadScriptingEngine("javascript");

Am I missing something obvious concerning loading Scripting engines?

-Mark