new methods for existing Java classes?

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

new methods for existing Java classes?

Andreas Rozek
Hello again!

Is it possible to provide additional methods for existing (Java)
classes?

Let me give an example to clarify the situation.  Imagine that I
would like to provide a method

  java.lang.String.reverse()

which yields the reverse of a given string object and would like
to apply that method to any Java string object.

Of course, BeanShell would throw an error since java.lang.String
does not provide  neither  the requested method  nor an "invoke"
method to catch the situation.

Is there any kind of mechanism (there is no need for utmost per-
formance) to emulate "invoke" for existing classes/objects?

Thanks in advance for your effort!

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





-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP.  Click here to play: http://sourceforge.net/geronimo.php
_______________________________________________
Beanshell-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/beanshell-users
Reply | Threaded
Open this post in threaded view
|

RE: new methods for existing Java classes?

Kireitchik, Valeri
try anonyous class as follows:

extendedStr = new String(){
  reverse(){
    // your implementation here
  }
};

// than use extendedStr


Or you can create named subclass of String.

best regards

Kireitchik Valery


-----Original Message-----
From: [hidden email] [mailto:[hidden email]]On Behalf Of Andreas Rozek
Sent: Friday, November 11, 2005 6:09 PM
To: Beanshell Mail List (??. ?????)
Subject: [Beanshell-users] new methods for existing Java classes?


Hello again!

Is it possible to provide additional methods for existing (Java)
classes?

Let me give an example to clarify the situation.  Imagine that I
would like to provide a method

  java.lang.String.reverse()

which yields the reverse of a given string object and would like
to apply that method to any Java string object.

Of course, BeanShell would throw an error since java.lang.String
does not provide  neither  the requested method  nor an "invoke"
method to catch the situation.

Is there any kind of mechanism (there is no need for utmost per-
formance) to emulate "invoke" for existing classes/objects?

Thanks in advance for your effort!

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





-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP.  Click here to play: http://sourceforge.net/geronimo.php
_______________________________________________
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: new methods for existing Java classes?

Mikael Aronsson
String is final so you cannot subclass it.

Mikael

----- Original Message -----
From: "Kireitchik, Valeri" <[hidden email]>
To: <[hidden email]>; "Beanshell Mail List (??. ?????)"
<[hidden email]>
Sent: Tuesday, November 15, 2005 12:17 PM
Subject: RE: [Beanshell-users] new methods for existing Java classes?


try anonyous class as follows:

extendedStr = new String(){
  reverse(){
    // your implementation here
  }
};

// than use extendedStr


Or you can create named subclass of String.

best regards

Kireitchik Valery


-----Original Message-----
From: [hidden email]
[mailto:[hidden email]]On Behalf Of Andreas
Rozek
Sent: Friday, November 11, 2005 6:09 PM
To: Beanshell Mail List (??. ?????)
Subject: [Beanshell-users] new methods for existing Java classes?


Hello again!

Is it possible to provide additional methods for existing (Java)
classes?

Let me give an example to clarify the situation.  Imagine that I
would like to provide a method

  java.lang.String.reverse()

which yields the reverse of a given string object and would like
to apply that method to any Java string object.

Of course, BeanShell would throw an error since java.lang.String
does not provide  neither  the requested method  nor an "invoke"
method to catch the situation.

Is there any kind of mechanism (there is no need for utmost per-
formance) to emulate "invoke" for existing classes/objects?

Thanks in advance for your effort!

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





-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP.  Click here to play: http://sourceforge.net/geronimo.php
_______________________________________________
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=ick">http://ads.osdn.com/?ad_idv28&alloc_id845&op=ick
_______________________________________________
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: new methods for existing Java classes?

Kireitchik, Valeri
In reply to this post by Andreas Rozek
you are right, Mikael, my fault.


-----Original Message-----
From: [hidden email] [mailto:[hidden email]]On Behalf Of mikael-aronsson
Sent: Tuesday, November 15, 2005 1:42 PM
To: Kireitchik, Valeri; [hidden email]; Beanshell Mail List (??. ?????)
Subject: Re: [Beanshell-users] new methods for existing Java classes?


String is final so you cannot subclass it.

Mikael

----- Original Message -----
From: "Kireitchik, Valeri" <[hidden email]>
To: <[hidden email]>; "Beanshell Mail List (??. ?????)"
<[hidden email]>
Sent: Tuesday, November 15, 2005 12:17 PM
Subject: RE: [Beanshell-users] new methods for existing Java classes?


try anonyous class as follows:

extendedStr = new String(){
  reverse(){
    // your implementation here
  }
};

// than use extendedStr


Or you can create named subclass of String.

best regards

Kireitchik Valery


-----Original Message-----
From: [hidden email]
[mailto:[hidden email]]On Behalf Of Andreas
Rozek
Sent: Friday, November 11, 2005 6:09 PM
To: Beanshell Mail List (??. ?????)
Subject: [Beanshell-users] new methods for existing Java classes?


Hello again!

Is it possible to provide additional methods for existing (Java)
classes?

Let me give an example to clarify the situation.  Imagine that I
would like to provide a method

  java.lang.String.reverse()

which yields the reverse of a given string object and would like
to apply that method to any Java string object.

Of course, BeanShell would throw an error since java.lang.String
does not provide  neither  the requested method  nor an "invoke"
method to catch the situation.

Is there any kind of mechanism (there is no need for utmost per-
formance) to emulate "invoke" for existing classes/objects?

Thanks in advance for your effort!

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





-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP.  Click here to play: http://sourceforge.net/geronimo.php
_______________________________________________
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=ick">http://ads.osdn.com/?ad_idv28&alloc_id845&op=ick
_______________________________________________
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=ick">http://ads.osdn.com/?ad_idv28&alloc_id845&op=ick
_______________________________________________
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: new methods for existing Java classes?

Andreas Rozek
Hello Mikael, Valeri, et al.

Thanks for your answers!

Anyway, it might have been unclear what has been in my mind
when I asked my question - thus, let me clarify the problem
a bit:

For scripted objects, Beanshell provides a generic "invoke"
method which gets called  whenever a requested method could
not be found, neither in the original object itself nor its
parent namespaces.

Is there a similar mechanism or approach  for existing Java
classes? (remember,I've described an approach for Beanshell
commands  with variable argument lists  based on "invoke" a
few days ago)

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