opensubscriber
   Find in this group all groups
 
Unknown more information…

b : bsf-user@jakarta.apache.org 26 January 2007 • 1:34AM -0500

Re: Using the ObjectRegistry
by Daling Xu

REPLY TO AUTHOR
 
REPLY TO GROUP




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-w...> 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.

Bookmark with:

Delicious   Digg   reddit   Facebook   StumbleUpon

Related Messages

opensubscriber is not affiliated with the authors of this message nor responsible for its content.