jakarta-bsf-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Daling Xu <daling...@yahoo.com>
Subject Re: Using the ObjectRegistry
Date Thu, 25 Jan 2007 17:34:40 GMT
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" <Rony.Flatscher@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.
Mime
  • Unnamed multipart/alternative (inline, 8-Bit, 0 bytes)
View raw message