velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Geir Magnusson Jr." <geirmagnusso...@yahoo.com>
Subject Re: Introspection weirdness?
Date Wed, 14 Nov 2001 09:04:09 GMT
On 11/14/01 3:52 AM, "Attila Szegedi" <szegedia@freemail.hu> wrote:

> Sorry for tuning in late, but as a person that's actually responsible for
> some of the Introspector code,

And it's really great!

> I feel I have few thoughts:
> 
> - Velocity has a so-called "dynamic-cast" mechanism in place since 1.2. That
> is, when faced with a non-public class, it will look up a method in a public
> superclass or public implemented interface. This is exactly what
> getAccessibleMethods() does.  Search for "dynamic casting" in velocity-dev
> archives (watch for line breaks):
> http://www.mail-archive.com/cgi-bin/htsearch?method=and&format=short&config=
> velocity-dev_jakarta_apache_org&restrict=&exclude=&words=dynamic+cast
> 
> - Velocity custom introspector currently does *NOT* recognize isXxx methods
> as boolean property getters. I remember mentioning it already here.
> 

And that's easy to add.

> - Beans Introspector will *NOT* do dynamic casting automatically. That is,
> even methods returned in property and method descriptors from beans
> introspector are the inaccessible ones when introspecting non-public
> classes, and you have to look up their public counterpart yourself again.
> So, even with Beans introspection, you still need getAccessibleMethods().
> 
> - I had already coded a transition to Beans Introspector, however Geir
> contacted me in private mail and asked "what problems will it solve?". While
> we had a some correspondence on it, I never really recieved a green light
> for actually submitting the code, despite the fact that it is done and sits
> idle on my hard drive for at least month and a half now.
> So, I feel there's reluctancy from the project management side to make the
> transition to the standard introspector. Just a note.

Because to use it, we have to constrain / limit what methods are accessible,
right?  That was an issue with the beans Introspector.  We don't just
support the bean spec - we offer (or try :) to offer a "more complete"
object binding capability.

I guess the question is it worth the tradeoff to not go with the beans
introspector?  My opinion is yes.

I like the current introspector very much.  We can easily add the isX if
really needed, and work out a solution to the current problem noted by
Michael.

I have a patch I have been working on in a related area (overload method
resolution) which I will finish and commit when I get back (I am away right
now at a client for 5 days...) and can try to nip off the problem Michael
noted then too.

Geir

> 
> 
> Cheers,
> Attila.
> 
> 
> ----- Original Message -----
> From: "Michael McKibben" <mike@hihat.net>
> To: "Velocity Users List" <velocity-user@jakarta.apache.org>
> Sent: 2001. november 13. 4:06
> Subject: Re: Introspection weirdness?
> 
> 
>> I think I may have found the cause of my woes. It is the implementation of
>> 
> org.apache.velocity.util.introspection.ClassMap.getAccessibleMethods(Class).
>> 
>> I have attached a patched version which uses java.beans.Introspector, but
>> perhaps you didn't use this class for a reason? At any rate, it should
>> give you an idea where to start hunting this bug down.
>> 
>> Regards,
>> 
>> --mike
>> 
>> On Mon, 12 Nov 2001, Geir Magnusson Jr. wrote:
>> 
>>> On 11/12/01 1:28 PM, "Michael McKibben" <mike@hihat.net> wrote:
>>> 
>>>> The com.sun.javadoc.* classes are all public interfaces. The actual
>>>> implementation classes are found in com.sun.tools.javadoc.* and are
>>>> declared package private. If it would help, I could send you my code
> and
>>>> example templates. It's at an early stage, but the code is functional.
>>>> 
>>> 
>>> "Barely creaking along" would be sufficient :)
>>> 
>>> I thought we handled this...  Please send - you can send here or to me
>>> privately - gives me something to do at the hotel tonight...
>>> 
>>> 
>>>> Regards,
>>>> 
>>>> --mike
>>>> 
>>>> On Mon, 12 Nov 2001, Geir Magnusson Jr. wrote:
>>>> 
>>>>> Sorry - really tired :)
>>>>> 
>>>>> Didn't read what you wrote - more below...
>>>>> 
>>>>> On 11/12/01 1:05 PM, "Michael McKibben" <mike@hihat.net> wrote:
>>>>> 
>>>>>> 
>>>>>> 
>>>>>>> I assume that isFinal() and isStatic() are public methods?
>>>>>>> 
>>>>>>> Geir
>>>>>>> 
>>>>>>>>>> 
>>>>>>>>>> com.sun.javadoc.ClassDoc classDoc = ...
>>>>>>>>>> velocityContext.put("classDoc", classDoc);
>>>>>>>>>> 
>>>>>>>>>> And then in the VTL I try to call methods on the
ClassDoc
> interface:
>>>>>>>>>> 
>>>>>>>>>> <javadoc:class
>>>>>>>>>> name="$classDoc.qualifiedName()"
>>>>>>>>>> final="$classDoc.isFinal()"
>>>>>>>>>> static="$classDoc.isStatic()">
>>>>>>>>>> ...
>>>>>>>>>> </javadoc:class>
>>>>>>>>>> 
>>>>>>>>>> Here is the weird part. Velocity correctly handles
some of the
> method
>>>>>>>>>> class; however it doesn't find the 'isFinal' and
'isStatic'
> methods! The
>>>>>>>>>> only way I can get my template to work correctly
is if I create
> a
>>>>>>>>>> wrapper
>>>>>>>>>> class and delegate the calls to the ClassDoc methods.
>>>>>>>>>> 
>>>>>>>>>> This suggests to me that Velocity's introspection
is broken.
> Looking at
>>>>>>>>>> the implementation of the com.sun.javadoc.* interfaces,
they are
>>>>>>>>>> declared
>>>>>>>>>> package private. This is a common introspection mistake.
The way
> to
>>>>>>>>>> handle
>>>>>>>>>> this case is to call getInterfaces() and replace
any public
> methods with
>>>>>>>>>> those found in the implemented interfaces.
> java.beans.Introspector
>>>>>>>>>> correctly handles this. Perhaps
>>>>>>>>>> org.apache.velocity.util.introspection.Introspector
should use
> this?
>>>>> 
>>>>> I guess I am really tired, because I didn't see them as package
> private. In
>>>>> 1.4, ClassDoc is public, ProgramElementDoc is public... Where am I
> missing
>>>>> it?
>>>>> 
>>>>> Are you saying we are getting fooled?
>>>>> 
>>>>> --
>>>>> Geir Magnusson Jr.
> geirm@optonline.net
>>>>> System and Software Consulting
>>>>> "They that can give up essential liberty to obtain a little temporary
> safety
>>>>> deserve neither liberty nor safety." - Benjamin Franklin
>>>>> 
>>>>> 
>>>>> 
>>>>> _________________________________________________________
>>>>> Do You Yahoo!?
>>>>> Get your free @yahoo.com address at http://mail.yahoo.com
>>>>> 
>>>>> 
>>>>> --
>>>>> To unsubscribe, e-mail:
>>>>> <mailto:velocity-user-unsubscribe@jakarta.apache.org>
>>>>> For additional commands, e-mail:
>>>>> <mailto:velocity-user-help@jakarta.apache.org>
>>>>> 
>>>> 
>>>> 
>>>> --
>>>> To unsubscribe, e-mail:
>>>> <mailto:velocity-user-unsubscribe@jakarta.apache.org>
>>>> For additional commands, e-mail:
>>>> <mailto:velocity-user-help@jakarta.apache.org>
>>>> 
>>> 
>>> --
>>> Geir Magnusson Jr.
> geirm@optonline.net
>>> System and Software Consulting
>>> "He who throws mud only loses ground." - Fat Albert
>>> 
>>> 
>>> _________________________________________________________
>>> Do You Yahoo!?
>>> Get your free @yahoo.com address at http://mail.yahoo.com
>>> 
>>> 
>>> --
>>> To unsubscribe, e-mail:
> <mailto:velocity-user-unsubscribe@jakarta.apache.org>
>>> For additional commands, e-mail:
> <mailto:velocity-user-help@jakarta.apache.org>
>>> 
>> 
> 
> 
> ----------------------------------------------------------------------------
> ----
> 
> 
>> --
>> To unsubscribe, e-mail:
> <mailto:velocity-user-unsubscribe@jakarta.apache.org>
>> For additional commands, e-mail:
> <mailto:velocity-user-help@jakarta.apache.org>
> 

-- 
Geir Magnusson Jr.                                     geirm@optonline.net
System and Software Consulting
"They that can give up essential liberty to obtain a little temporary safety
deserve neither liberty nor safety." - Benjamin Franklin



_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com


--
To unsubscribe, e-mail:   <mailto:velocity-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:velocity-user-help@jakarta.apache.org>


Mime
View raw message