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 "Rony G. Flatscher" <Ro...@wu-wien.ac.at> on 2007/01/25 17:21:00 UTC

declareBean() vs. registerBean() (Re: overhead of new BSFManager()

Hi Linda,

there is a difference between declaring and registering a bean:
declareBean() tries to inform the BSF engine explicitly about the bean,
such - if supported by the language - that it gets implicitly defined
for the script, whereas declared beans need to be looked up by the
script before being able to use it.

Or with other words: have the script look-up the bean before using it.
E.g., in Javascript:

    myBean = bsf.lookupBean ("myBean");  /* retrieve a registered Java
    object */

HTH,

---rony


Re: Any open source or comercial javascript engine other than Rhino

Posted by Mario Neè <ma...@xmoon.org>.
try XMoon
http://www.xmoon.org


Daling Xu ha scritto:
> Hi,
>    
>   Because of the concern on the Rhino's GPL license. We would like to find some LGPL or comercial javascript engine supported by BSF. 
>    
>   So far, I found only one which is FESI. But it looks pretty old.
>    
>   Anybody here used any javascript engine other than Rhino?
>
> Thanks
>    
>   Linda
>
> "Rony G. Flatscher" <Ro...@wu-wien.ac.at> wrote:
>   Hi Linda,
>
> Daling Xu wrote:
>   
>> I continued to drill down on this issue. From reading of the BSF source code, I found that the "bsf" object that was put into the javascript global context is actually a object of BSFFunctions object which only contains a subset of BSFManager methods. The BSFFunctions doesn't have a getObjectRegistry method.
>>
>> This explains the reason of the exception I ran into. 
>>
>> Now my question is
>> (1) Why BSFFunctions doesn't support the getObjectRegistry method?
>>
>>     
> Don't really know what the developers had in mind here.
>
>   
>> (2) How can I retrieve the bean objects from the ObjectRegiestry inside the script code?
>>
>>     
> You can't. The real reason is with the original authors, maybe Sanjiva,
> if he reads this, could shed some light on this.
>
> However there may be one (good) reason: security. One never can be sure
> who writes which scripts. So for security reasons it makes sense to give
> no one the ability to figure out what the ObjectRegistry holds. The Java
> hosts (Java programs that dispatch scripts via BSF) would know what they
> put into the registry for the scripts to interact/work with, so for the
> scripts that would not really be a shortcoming. In the case that one
> needs to make a collection of Java objects available to the scripts,
> then one is able to register a collection object for the script.
>
> HTH,
>
> ---rony
>
> P.S.: The nice thing about FOSS is that in the case that you really hit
> a barrier you do not want to cope with, that you can go back to the
> sources and enhance/change/tailor the code to your needs.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: bsf-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: bsf-user-help@jakarta.apache.org
>
>
>
>  
> ---------------------------------
>  Get your own web address.
>  Have a HUGE year through Yahoo! Small Business.
>   


-- 
Mario Neè

Neex di Neè Mario
Via Vanzeghetto Sotto N. 2
25036 Palazzolo sull'Oglio (BS)
Tel 329.2323782
Fax 178.222.0639
mario.nee@neex.it

www.neex.it
--

CONFIDENZIALE: Questo messaggio e gli eventuali allegati sono confidenziali e riservati. Se vi e' stato recapitato per errore e non siete fra i destinatari elencati, siete pregati di darne immediatamente avviso al mittente. Le informazioni contenute non devono essere mostrate ad altri, ne utilizzate, memorizzate o copiate in qualsiasi forma.
CONFIDENTIALITY : This  e-mail  and  any attachments are confidential and may be privileged. If  you are not a named recipient, please notify the sender immediately and do not disclose the contents to another person, use it for any purpose or store or copy the information in any medium.


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


Re: Any open source or comercial javascript engine other than Rhino

Posted by "Rony G. Flatscher" <Ro...@wu-wien.ac.at>.
Hi Linda,
> Because of the concern on the Rhino's GPL license. We would like to find some LGPL or comercial javascript engine supported by BSF. 
>    
> So far, I found only one which is FESI. But it looks pretty old.
>    
> Anybody here used any javascript engine other than Rhino?
>   
hmm, I am pretty confident that it is not necessary to apply any changes
to Rhino, just to the BSF-Rhino/Javascript engine. Or with other words,
the speculation (short of knowing the respective Rhino interfaces):
there should be a means on board of Rhino to terminate/cancel a running
script; if so, then you would need to invoke it in the BSF-Rhino engine
(creating a terminate()-method in which you would exercise the Rhino
termination infrastrucgture). Only, if Rhino itself would not cater for
such a functionality would there be a need to apply changes to Rhino itself.

HTH,

---rony


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


Any open source or comercial javascript engine other than Rhino

Posted by Daling Xu <da...@yahoo.com>.
Hi,
   
  Because of the concern on the Rhino's GPL license. We would like to find some LGPL or comercial javascript engine supported by BSF. 
   
  So far, I found only one which is FESI. But it looks pretty old.
   
  Anybody here used any javascript engine other than Rhino?

Thanks
   
  Linda

"Rony G. Flatscher" <Ro...@wu-wien.ac.at> wrote:
  Hi Linda,

Daling Xu wrote:
> I continued to drill down on this issue. From reading of the BSF source code, I found that the "bsf" object that was put into the javascript global context is actually a object of BSFFunctions object which only contains a subset of BSFManager methods. The BSFFunctions doesn't have a getObjectRegistry method.
> 
> This explains the reason of the exception I ran into. 
> 
> Now my question is
> (1) Why BSFFunctions doesn't support the getObjectRegistry method?
> 
Don't really know what the developers had in mind here.

> (2) How can I retrieve the bean objects from the ObjectRegiestry inside the script code?
> 
You can't. The real reason is with the original authors, maybe Sanjiva,
if he reads this, could shed some light on this.

However there may be one (good) reason: security. One never can be sure
who writes which scripts. So for security reasons it makes sense to give
no one the ability to figure out what the ObjectRegistry holds. The Java
hosts (Java programs that dispatch scripts via BSF) would know what they
put into the registry for the scripts to interact/work with, so for the
scripts that would not really be a shortcoming. In the case that one
needs to make a collection of Java objects available to the scripts,
then one is able to register a collection object for the script.

HTH,

---rony

P.S.: The nice thing about FOSS is that in the case that you really hit
a barrier you do not want to cope with, that you can go back to the
sources and enhance/change/tailor the code to your needs.


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



 
---------------------------------
 Get your own web address.
 Have a HUGE year through Yahoo! Small Business.

Re: Using the ObjectRegistry

Posted by "Rony G. Flatscher" <Ro...@wu-wien.ac.at>.
Hi Linda,

Daling Xu wrote:
> I continued to drill down on this issue. From reading of the BSF source code, I found that the "bsf" object that was put into the javascript global context is actually a object of BSFFunctions object which only contains a subset of BSFManager methods. The BSFFunctions doesn't have a getObjectRegistry method.
>    
>   This explains the reason of the exception I ran into. 
>    
>   Now my question is
>   (1) Why BSFFunctions doesn't support the getObjectRegistry method?
>   
Don't really know what the developers had in mind here.

>   (2) How can I retrieve the bean objects from the ObjectRegiestry inside the script code?
>   
You can't. The real reason is with the original authors, maybe Sanjiva,
if he reads this, could shed some light on this.

However there may be one (good) reason: security. One never can be sure
who writes which scripts. So for security reasons it makes sense to give
no one the ability to figure out what the ObjectRegistry holds. The Java
hosts (Java programs that dispatch scripts via BSF) would know what they
put into the registry for the scripts to interact/work with, so for the
scripts that would not really be a shortcoming. In the case that one
needs to make a collection of Java objects available to the scripts,
then one is able to register a collection object for the script.

HTH,

---rony

P.S.: The nice thing about FOSS is that in the case that you really hit
a barrier you do not want to cope with, that you can go back to the
sources and enhance/change/tailor the code to your needs.


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


Re: Using the ObjectRegistry

Posted by Daling Xu <da...@yahoo.com>.
I continued to drill down on this issue. From reading of the BSF source code, I found that the "bsf" object that was put into the javascript global context is actually a object of BSFFunctions object which only contains a subset of BSFManager methods. The BSFFunctions doesn't have a getObjectRegistry method.
   
  This explains the reason of the exception I ran into. 
   
  Now my question is
  (1) Why BSFFunctions doesn't support the getObjectRegistry method?
  (2) How can I retrieve the bean objects from the ObjectRegiestry inside the script code?
  
Thanks
   
  Linda

Daling Xu <da...@yahoo.com> wrote:
  Hi Rony,

I think I am following the steps you described, here is my code:

final String BEAN_ANME = "myBeanName";
BSFManager manager = new BSFManager();


ObjectRegistry objReg = new ObjectRegistry( manager.getObjectRegistry() );
objReg.register(BEAN_NAME , new MyBeanClass("my String by objReg")); 


manager.setObjectRegistry( objReg );




manager.exec("javascript", "test", 0, 0, "bsf.getObjectRegistry().lookup(\"" + BEAN_NAME +"\")"+ ".myMethod();" ); //try case 1

//manager.exec("javascript", "test", 0, 0, "bsf.lookupBean(\"" + BEAN_NAME +"\")"+ ".myMethod();" ); //try case 2

//manager.exec("javascript", "test", 0, 0, BEAN_NAME + ".myMethod();" ); //try case 3

None of the three tries worked. 

For the try case 1, I got this error:
TypeError: Cannot find function getObjectRegistry. although I can directly call 
Although I can run the following code successfully in my java code:
Object obj = manager.getObjectRegistry().lookup( BEAN_NAME );
((MyBeanClass)obj).myMethod();

For the case 2, I got a java.lang.ClassCastException, here is part of my printstacktrace:
at org.apache.bsf.BSFManager.lookupBean(BSFManager.java:736)
at org.apache.bsf.util.BSFFunctions.lookupBean(BSFFunctions.java:46)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)


For the case 3, I know conceptly it not the right way to do, just use it to confirm my understanding. As expected, it gave me exception of "myBeanName" is not defined.

Conceptually, I think the case 1 here is the right way to do it, but why it didn't work?

Thanks

Linda


"Rony G. Flatscher" wrote:
bm=new org.apache.bsf.BSFManager();
// ... do whatever you need to do (setup, invoking scripsts, maybe
nothing, whatever)

or=new org.apache.bsf.ObjectRegistry();
// or if you want to use bm's ObjectRegistry object as a parent:
or=new org.apache.bsf.ObjectRegistry(bm.getObjectRegistry());
// do whatever you need to do with "or" (registering objects for the
scripts)....

bm.setObjectRegistry(or); // now set "bm" to the new
ObjectRegistry object "or"
// continue to invoke scripts

HTH,

---rony




---------------------------------
Food fight? Enjoy some healthy debate
in the Yahoo! Answers Food & Drink Q&A.

 	
---------------------------------
Everyone is raving about the all-new Yahoo! Mail beta.

Re: Using the ObjectRegistry

Posted by Daling Xu <da...@yahoo.com>.
Hi Rony,
   
  I think I am following the steps you described, here is my code:
   
  final String BEAN_ANME = "myBeanName";
  BSFManager manager = new BSFManager();
  
   
  ObjectRegistry objReg = new ObjectRegistry( manager.getObjectRegistry() );
  objReg.register(BEAN_NAME , new MyBeanClass("my String by objReg")); 
   
  
  manager.setObjectRegistry( objReg );
  
  
  
   
  manager.exec("javascript", "test", 0, 0, "bsf.getObjectRegistry().lookup(\"" + BEAN_NAME +"\")"+ ".myMethod();" );  //try case 1
   
  //manager.exec("javascript", "test", 0, 0, "bsf.lookupBean(\"" + BEAN_NAME +"\")"+ ".myMethod();" );  //try case 2
   
  //manager.exec("javascript", "test", 0, 0, BEAN_NAME + ".myMethod();" ); //try case 3
   
  None of the three tries worked. 
   
  For the try case 1, I got this error:
  TypeError: Cannot find function getObjectRegistry.  although I can directly call 
  Although I can run the following code successfully in my java code:
  Object obj = manager.getObjectRegistry().lookup( BEAN_NAME );
  ((MyBeanClass)obj).myMethod();
   
  For the case 2, I got a java.lang.ClassCastException, here is part of my printstacktrace:
  at org.apache.bsf.BSFManager.lookupBean(BSFManager.java:736)
  at org.apache.bsf.util.BSFFunctions.lookupBean(BSFFunctions.java:46)
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   
   
  For the case 3, I know conceptly it not the right way to do, just use it to confirm my understanding. As expected, it gave me exception of "myBeanName" is not defined.
   
  Conceptually, I think the case 1 here is the right way to do it, but why it didn't work?
  
Thanks
   
  Linda
  

"Rony G. Flatscher" <Ro...@wu-wien.ac.at> wrote:
  bm=new org.apache.bsf.BSFManager();
// ... do whatever you need to do (setup, invoking scripsts, maybe
nothing, whatever)

or=new org.apache.bsf.ObjectRegistry();
// or if you want to use bm's ObjectRegistry object as a parent:
or=new org.apache.bsf.ObjectRegistry(bm.getObjectRegistry());
// do whatever you need to do with "or" (registering objects for the
scripts)....

bm.setObjectRegistry(or); // now set "bm" to the new
ObjectRegistry object "or"
// continue to invoke scripts

HTH,

---rony



 
---------------------------------
Food fight? Enjoy some healthy debate
in the Yahoo! Answers Food & Drink Q&A.

Using the ObjectRegistry (Re: declareBean() vs. registerBean() (Re: overhead of new BSFManager()

Posted by "Rony G. Flatscher" <Ro...@wu-wien.ac.at>.
Hi Linda,
>   Thank you for you assistance.
>   
You are very welcome, glad that I could help a little bit.

>   I modified my code for the approach using manager.registerBean() :
>    
>   BSFManager manager = new BSFManager();
>   manager.registerBean( "myBeanName", new MyBeanClazz("str for regBean");
>   manager.exec( "javascript", "test", 0,0, "bsf.lookupBean(\"myBeanName\").myMethod();" );
>    
>   This time it works and printed out the string in the console. Thanks.
>   
Fine.

>   It looks that the BSFManager defaultly declared a bean "bsf" so the script can always use it just like a predefined object in the javascript.
>   
It is put into the global context by the Javascript engine.

>   But for my ObjectRegistery approach, even I tried to call bsf.lookupBean in the script code, it still doesn't work, anything still missing here?
>   
Hmm, did you set the the ObjectRegistry object to your BSFManager's
instance?

Something along the lines:

    bm=new org.apache.bsf.BSFManager();
    // ... do whatever you need to do (setup, invoking scripsts, maybe
    nothing, whatever)

    or=new org.apache.bsf.ObjectRegistry();
    // or if you want to use bm's ObjectRegistry object as a parent:
    or=new org.apache.bsf.ObjectRegistry(bm.getObjectRegistry());
    // do whatever you need to do with "or" (registering objects for the
    scripts)....

    bm.setObjectRegistry(or);    // now set "bm" to the new
    ObjectRegistry object "or"
    // continue to invoke scripts

HTH,

---rony


Re: declareBean() vs. registerBean() (Re: overhead of new BSFManager()

Posted by Daling Xu <da...@yahoo.com>.
Hi Rony,
   
  Thank you for you assistance.
   
  I modified my code for the approach using manager.registerBean() :
   
  BSFManager manager = new BSFManager();
  manager.registerBean( "myBeanName", new MyBeanClazz("str for regBean");
  manager.exec( "javascript", "test", 0,0, "bsf.lookupBean(\"myBeanName\").myMethod();" );
   
  This time it works and printed out the string in the console. Thanks.
   
  It looks that the BSFManager defaultly declared a bean "bsf" so the script can always use it just like a predefined object in the javascript.
   
  But for my ObjectRegistery approach, even I tried to call bsf.lookupBean in the script code, it still doesn't work, anything still missing here?
   
  Linda
   
  

"Rony G. Flatscher" <Ro...@wu-wien.ac.at> wrote:
  Hi Linda,

there is a difference between declaring and registering a bean:
declareBean() tries to inform the BSF engine explicitly about the bean,
such - if supported by the language - that it gets implicitly defined
for the script, whereas declared beans need to be looked up by the
script before being able to use it.

Or with other words: have the script look-up the bean before using it.
E.g., in Javascript:

myBean = bsf.lookupBean ("myBean"); /* retrieve a registered Java
object */

HTH,

---rony



 
---------------------------------
Finding fabulous fares is fun.
Let Yahoo! FareChase search your favorite travel sites to find flight and hotel bargains.