I too am intrigued by this thread. At the Joda project, we have implemented
something which I think is kind of similar. We have a 'Property' interface
which has set(Object) and toObject() methods, similar to the setValue and
getValue methods in the example below. The difference is that the Property
object stores a reference to the Bean it belongs to, whereas in the example
below the target is passed in. The Joda code is all Java - at present.
I am guessing the speed up comes because there is no need to do the String
searching based on field name. The BCEL coding will have 'dynamically hard
coded' the Field object.
I think that it could be useful to others if an open source version of this
concept was developed. (Especially as I have been thinking about writing
code in the area of Introspection!)
Stephen
----- Original Message -----
From: Charles Lloyd <[EMAIL PROTECTED]>
To: BCEL Users List <[EMAIL PROTECTED]>
Sent: Friday, May 17, 2002 4:58 AM
Subject: Re: Emulating java.lang.reflect.AccessibleObject
> Phil,
>
> Unfortunately, the code is a proprietary part of our system and
> considered confidential. I feel like a hypocrite for requesting example
> code and then not being willing (well, able) to give it up myself. I
> hope you can understand.
>
> I can tell you that we generate a class for each Field and that class
> has two methods. If it was written in java rather than bcel, it would
> look as follows.
>
> public class SomeClassName_someFieldName extends FieldAccessor
> {
> public void setValue(Object target, Object value)
> {
> ((SomeClassName)target).someFieldName = (SomeFieldClass)value;
> }
>
> public Object getValue(Object target)
> {
> return ((SomeClassName)target).someFieldName;
> }
>
> [There's more to it than this since you have to do something special for
> primitive type, but this should give you the basic idea.]
>
> We then access it as follows:
>
> SomeClassName target = new SomeClassName();
> SomeClassName_someFieldName accessor = new
> SomeClassName_someFieldName();
> accessor.setValue(target, someValue);
> SomeFieldClass fieldValue = (SomeFieldClass)accessor.value(target);
>
> I hope this helps!
>
> Charles.
>
>
> On Thursday, May 16, 2002, at 04:20 PM,
> [EMAIL PROTECTED] wrote:
>
> >
> > Can you post some example code somewhere? Our project could definately
> > use
> > some speedup in the portions that use reflect.
> >
> > Thanks,
> > -Phil
> >
> >
> >
> >
> > clloyd3@attbi
> > .com To: "BCEL Users List"
> > <[EMAIL PROTECTED]>
> > 05/16/2002 cc:
> > 02:14 PM Subject: Re: Emulating
> > Please
> > java.lang.reflect.AccessibleObject
> > respond to
> > "BCEL Users
> > List"
> >
> >
> >
> >
> >
> >
> > Yes, I measured it to be about 100x faster for both
> > Field and Method access, if I recall correctly.
> >
> > Charles.
> >>
> >> Is your BCEL implementation faster? Are there advantages to using BCEL
> >> over reflect? This is kind of fascinating.
> >>
> >> Thanks,
> >> -Phil
> >>
> >>
> >>
> >>
> >
> >> Charles Lloyd
> >
> >> <clloyd3@attb To:
> > [EMAIL PROTECTED]
> >> i.com> cc:
> >
> >> Subject: Emulating
> >
> >> 05/15/2002
> > java.lang.reflect.AccessibleObject
> >> 09:25 PM
> >
> >> Please
> >
> >> respond to
> >
> >> "BCEL Users
> >
> >> List"
> >
> >>
> >
> >>
> >
> >>
> >>
> >>
> >>
> >> I am trying to write a replacement for java.lang.reflect.Method and
> >> Field using BCEL. I have everything working nicely except I cannot
> >> figure out how to emulate the setAccessible(true) feature which allows
> >> for access (via reflection) to protected and private Methods and
> >> Fields.
> >>
> >> Suggestions or examples greatly appreciated.
> >>
> >> Charles.
> >>
> >>
> >> --
> >> To unsubscribe, e-mail: <
> > mailto:[EMAIL PROTECTED]>
> >> For additional commands, e-mail: <
> > mailto:[EMAIL PROTECTED]>
> >>
> >>
> >>
> >>
> >>
> >>
> >> --
> >> To unsubscribe, e-mail: <
> > mailto:[EMAIL PROTECTED]>
> >> For additional commands, e-mail: <
> > mailto:[EMAIL PROTECTED]>
> >>
> >
> > --
> > To unsubscribe, e-mail: <mailto:bcel-user-
> > [EMAIL PROTECTED]>
> > For additional commands, e-mail: <mailto:bcel-user-
> > [EMAIL PROTECTED]>
> >
> >
> >
> >
> >
> >
> > --
> > To unsubscribe, e-mail: <mailto:bcel-user-
> > [EMAIL PROTECTED]>
> > For additional commands, e-mail: <mailto:bcel-user-
> > [EMAIL PROTECTED]>
> >
>
>
> --
> To unsubscribe, e-mail:
<mailto:[EMAIL PROTECTED]>
> For additional commands, e-mail:
<mailto:[EMAIL PROTECTED]>
>
>
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>