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]>

Reply via email to