You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Niall Pemberton <ni...@btInternet.com> on 2002/04/15 21:04:29 UTC

RE: Creating beans dynamically from byte code in a byte[] withClassLoader.defineClass - how to do it right?

This is exactly what DynaBeans were invented for.

Using BCEL to generate classes on the fly is impressive, but wouldn't it be
simpler to just use the DynaBeans, which I believe are in 1.1?

Niall

> -----Original Message-----
> From: Thorbjørn Ravn Andersen (Scandiatransplant)
> [mailto:tra@biobase.dk]
> Sent: 15 April 2002 16:15
> To: Struts Users Mailing List
> Subject: Creating beans dynamically from byte code in a byte[]
> withClassLoader.defineClass - how to do it right?
>
>
>
> I have spent some time lately figuring out how I can generate beans
> on-the-fly with fields completely specified at run-time, since this would
> be an enourmeous help when working with JDBC and Struts in an informal
> matter (which is why I ask here :-)
>
> I have used Apache Jakarta BCEL to construct the byte-code I need for the
> bean (verified by dumping it to disk, and using "java" and 'javap -c' on
> the class file), and I would then like to get the SystemClassLoader and
> call defineClass on my byte array to get a Class, and then resolve it.
>
> Unfortunately I cannot do this, since the defineClass method is protected
> final, so I am a bit at a loss here.  I just need some code which can
> instantiate my byte code into a Class, so I can get this working.   I
> would prefer not to use physical files, but I have a JSP-environment so
> that might be an option.  (Resin+Tomcat).
>
> Is there somebody who have a solution for this problem?  I would
> appreciate all pointers.
>
> --
>   Thorbjørn Ravn Andersen
>   Scandiatransplant, c/o Christian Mondrup
>   89 49 53 01
>   http://biobase.dk/~tra
>
>
> --
> To unsubscribe, e-mail:
> <ma...@jakarta.apache.org>
> For additional commands, e-mail:
> <ma...@jakarta.apache.org>
>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: Creating beans dynamically from byte code in a byte[] withClassLoader.defineClass - how to do it right?

Posted by "Thorbjørn Ravn Andersen (Scandiatransplant)" <tr...@biobase.dk>.
On Mon, 15 Apr 2002, Niall Pemberton wrote:

> This is exactly what DynaBeans were invented for.

I have spent quite some time looking for such an automatic bean creation
facility, and apparently it is something which is quite unique to the
Struts project in that there is a working solution.

> Using BCEL to generate classes on the fly is impressive, but wouldn't it be
> simpler to just use the DynaBeans, which I believe are in 1.1?

Ah, that's why I didn't see it before.  I have only looked at 1.0.2 since
we need stable software (as in non-changing, not bug-free), so any 1.1
features would have to wait until 1.1 was formally released.

I'll give it a try.  Thanks for your answer.
-- 
  Thorbjørn Ravn Andersen
  Scandiatransplant, c/o Christian Mondrup
  89 49 53 01
  http://biobase.dk/~tra


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>