silly question: how to create a "scripted object" from within Java

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

silly question: how to create a "scripted object" from within Java

Andreas Rozek
Hello!

The question might sound silly,  but I'm still looking for the
best way to create dynamically extensible objects within Bean-
Shell:

What is the "officially recommended" way to create a "scripted
object" from within Java?

Should I "eval" a short script (e.g. "object()")  or may I in-
stantiate an object using Java method invocations?

Thanks in advance for any help,

Andreas Rozek         Phone:  ++49 (7031) 222305
Bunsenstra?e 80/1     Fax:    -
D-71032 B?blingen     EMail:  [hidden email]
Germany               URL:    http://www.Andreas-Rozek.de





-------------------------------------------------------
This SF.Net email is sponsored by the JBoss Inc.  Get Certified Today
Register for a JBoss Training Course.  Free Certification Exam
for All Training Attendees Through End of 2005. For more info visit:
http://ads.osdn.com/?ad_id=7628&alloc_id=16845&op=click
_______________________________________________
Beanshell-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/beanshell-users
Reply | Threaded
Open this post in threaded view
|

RE: silly question: how to create a "scripted object" from within Java

Daniel Leuck
When we say "scripted object" we mean something like:

foo() {
  printHello() {
    print("Aloha");
  }

  return this;
}

var myFoo = foo();

Dan

> -----Original Message-----
> From: [hidden email] [mailto:beanshell-users-
> [hidden email]] On Behalf Of Andreas Rozek
> Sent: Thursday, November 17, 2005 11:41 AM
> To: Beanshell Mail List (??. ?????)
> Subject: [Beanshell-users] silly question: how to create a "scripted
> object" from within Java
>
> Hello!
>
> The question might sound silly,  but I'm still looking for the
> best way to create dynamically extensible objects within Bean-
> Shell:
>
> What is the "officially recommended" way to create a "scripted
> object" from within Java?
>
> Should I "eval" a short script (e.g. "object()")  or may I in-
> stantiate an object using Java method invocations?
>
> Thanks in advance for any help,
>
> Andreas Rozek         Phone:  ++49 (7031) 222305
> Bunsenstraße 80/1     Fax:    -
> D-71032 Böblingen     EMail:  [hidden email]
> Germany               URL:    http://www.Andreas-Rozek.de
>
>
>
>
>
> -------------------------------------------------------
> This SF.Net email is sponsored by the JBoss Inc.  Get Certified Today
> Register for a JBoss Training Course.  Free Certification Exam
> for All Training Attendees Through End of 2005. For more info visit:
> http://ads.osdn.com/?ad_id=7628&alloc_id=16845&op=click
> _______________________________________________
> Beanshell-users mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/beanshell-users



-------------------------------------------------------
This SF.Net email is sponsored by the JBoss Inc.  Get Certified Today
Register for a JBoss Training Course.  Free Certification Exam
for All Training Attendees Through End of 2005. For more info visit:
<a href="http://ads.osdn.com/?ad_idv28&alloc_id845&op=click">http://ads.osdn.com/?ad_idv28&alloc_id845&op=click
_______________________________________________
Beanshell-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/beanshell-users
Reply | Threaded
Open this post in threaded view
|

Re: RE: silly question: how to create a "scripted object" from within Java

Andreas Rozek
Hello Daniel!

>When we say "scripted object" we mean something like:
>
>foo() {
>  printHello() {
>    print("Aloha");
>  }
>  return this;
>}
>
>var myFoo = foo();

Well, I know - but I would like to create them from with-
in my Java code.  To my current  understanding,  scripted
objects internally consist of (at least) two Java objects

 - a "bsh.This" object refering to a "namespace" and
 - a "bsh.NameSpace" which represents the actual object

If I could subclass "bsh.NameSpace"  (overwriting methods
like "setVariable" and "getVariable")  I could  implement
accessors myself while still keeping dynamic extensibili-
ty at runtime.

What I don't yet know:  how can I create  a "scripted ob-
ject"  which is based on  my subclass  of "bsh.NameSpace"
rather than the original implementation?

Thanks in advance for any ideas,

Andreas Rozek         Phone:  ++49 (7031) 222305
Bunsenstra?e 80/1     Fax:    -
D-71032 B?blingen     EMail:  [hidden email]
Germany               URL:    http://www.Andreas-Rozek.de





-------------------------------------------------------
This SF.Net email is sponsored by the JBoss Inc.  Get Certified Today
Register for a JBoss Training Course.  Free Certification Exam
for All Training Attendees Through End of 2005. For more info visit:
http://ads.osdn.com/?ad_id=7628&alloc_id=16845&op=click
_______________________________________________
Beanshell-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/beanshell-users
Reply | Threaded
Open this post in threaded view
|

Re: RE: silly question: how to create a "scripted object" from within Java

Andreas Rozek
Hello Daniel et al.!

My current approach to achieve both extensibility and get-
ter/setter-style access to properties of an object  within
BeanShell is as follows:

 - implement and compile a Java class ("XNameSpace") which
   - extends bsh.NameSpace
   - overwrites getVariable, setVariable etc. for getter/
     setter-style access

 - within BeanShell:
   - provide a method
     object (NameSpace) {setNameSpace(NameSpace); return this;};
   - and invoke it as follows
     var foo = object(new XNameSpace(this.namespace,"Name"));

(this is just a rough outline of my approach, but hopefully it
clarifies the mechanism)

This approach seems to work - but it also looks extremely inef-
ficient.

Is there a better way?

Andreas Rozek         Phone:  ++49 (7031) 222305
Bunsenstra?e 80/1     Fax:    -
D-71032 B?blingen     EMail:  [hidden email]
Germany               URL:    http://www.Andreas-Rozek.de





-------------------------------------------------------
This SF.Net email is sponsored by the JBoss Inc.  Get Certified Today
Register for a JBoss Training Course.  Free Certification Exam
for All Training Attendees Through End of 2005. For more info visit:
http://ads.osdn.com/?ad_id=7628&alloc_id=16845&op=click
_______________________________________________
Beanshell-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/beanshell-users