[prev in list] [next in list] [prev in thread] [next in thread] 

List:       bcel-user
Subject:    Re: Anonymous Inner Class @ runtime
From:       "Juozas Baliuka" <baliuka () centras ! lt>
Date:       2003-05-27 4:54:10
[Download RAW message or body]

see cglib.sourceforge.net, MethodProxy class does something like this
without reflection, you can modify it for your use case
or use Enhancer.
I use adapters in voruta.sourceforge.net see
http://voruta.sourceforge.net/xref/net/sf/voruta/DbUtils.html#84, this code
uses
cglib to generate adapter factories for JDBC stuff.

----- Original Message -----
From: "Masahji Stewart" <masahji@masahji.com>
To: "BCEL Users List" <bcel-user@jakarta.apache.org>
Sent: Tuesday, May 27, 2003 1:25 AM
Subject: Re: Anonymous Inner Class @ runtime


> I am sorry. I realized that I was been very unclear in my past two
> emails.
> Basically, I am looking to BCEL for an implementation that would
> replace a reflective method call by generating a class that wraps the
> method (that returns some value) with a known method name. Of course,
> this can be done by creating an adapter for every getter of every used
> class. But, even if I did that new classes that come along would not
> work with my framework unless I created an adapter for every getter
> method.
> If I used the java.lang.reflect.Proxy class that you suggested,
> reflection would still be used (underneath the hood) to retrieve the
> data that I am looking for.
>
> So, just to make things more clear, I would like to dynamically create
> an adapter instance for any method that retrieves an Object.
> It might look like the following:
>
> interface RetrieverAdapter {
>      // o is an instance of the class that contains the getter for this
> retriever.
>      public Object getValue( Object o );
> }
>
> // a hand made implementation would look like the following
> RetrieverAdapter retriever = new RetrieverAdapter() {
>      public Object getValue( Object o ) {
>            return ((SomeClass)o).getName();
>      }
> };
>
>
> The class that I would like to implement using BCel has the following
> basic "reflective" implementation.
>
> // m would be something like that "getName" method that you see above.
> public RetrieverAdapter createRetrieverAdapter(final Method m) {
>       // ignore the lack of consistency checks
>        return new RetrieverAdapter() {
>
>            public Object getValue(Object o) {
>                return m.invoke( o, new Object[] {} );
>            }
>        };
> }
>
>
> Again, sorry for my lack of clarity in the last two emails.
> I hope this clears things up. I tried to implement this myself,
> following the provided HelloWorld example,
> but I am running into a boatload of problems. One is, how do I load a
> class without having to write it to a file
> first.
>
> Thanks in advance, again.
>
>
> masahji
>
>
>
> On Monday, May 26, 2003, at 11:59 AM, Toby Reyelts wrote:
>
> >
> > You can do this without BCEL using the standard java.lang.reflect.Proxy
> > class.
> >
> > God bless,
> > -Toby Reyelts
> >
> > ----- Original Message -----
> > From: "Masahji Stewart" <masahji@masahji.com>
> > To: <bcel-user@jakarta.apache.org>
> > Sent: Monday, May 26, 2003 1:44 PM
> > Subject: Anonymous Inner Class @ runtime
> >
> >
> >> Hello,
> >>
> >> I am trying to create an anonymous inner class at runtime that
> >> implements the following interface:
> >>
> >> interface Foo {
> >>      public Object getValue(Object instance);
> >> }
> >> ...
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: bcel-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: bcel-user-help@jakarta.apache.org
> >
> >
> -masahji
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: bcel-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: bcel-user-help@jakarta.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: bcel-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: bcel-user-help@jakarta.apache.org

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic