[ 
http://issues.apache.org/jira/browse/BEEHIVE-149?page=comments#action_57213 ]
     
Kyle Marvin commented on BEEHIVE-149:
-------------------------------------

Unfortunately, the fix isn't as simple as I'd like... Apparently, the java 
beans introspection code *requires* that the arg type of the setter and the 
return type of the getter must match up, or you'll get an exception like:

java.beans.IntrospectionException: type mismatch between read and write methods
        at 
java.beans.PropertyDescriptor.findPropertyType(PropertyDescriptor.java:603)
        at 
java.beans.PropertyDescriptor.setWriteMethod(PropertyDescriptor.java:270)
        at java.beans.PropertyDescriptor.<init>(PropertyDescriptor.java:117)

even if you explicitly give it the read/write methods in the PropertyDescriptor 
constructor.

The implication is that annotation type-valued property setters or getters must 
either a) use a PropertyMap as both the return and set value types, or b) use 
the original annotation type as the return and set value types.

I'm leaning towards b) because it provides better typed accessors (you just 
call the anotation type member methods), at least for the property reading 
cases.   It also means standards dot-style defering to access property values 
will work for annotation-typed properties, which seems like a very key use case.

This means I'll also have to provide a mechanism to go from a PropertyMap to a 
typed proxy instance, so setting an annotation valued property value would look 
something like:

         PropertyMap<AnnotType> propMap = new BeanPropertyMap<AnnotType>();
         propMap.setProperty(...);
         bean.setAnnotProperty(propMap.getProperty());

where PropertyMap.getProperty returns a PropertySetProxy instance that wraps 
the original map.  Doing this cleanly also adds a need for using generic formal 
type parameters on the PropertyMap interface and some of the associated impl 
classes.

> Bean introspection fails for annotation-valued properties
> ---------------------------------------------------------
>
>          Key: BEEHIVE-149
>          URL: http://issues.apache.org/jira/browse/BEEHIVE-149
>      Project: Beehive
>         Type: Bug
>   Components: Controls
>     Versions: V1Alpha
>     Reporter: Kyle Marvin
>     Assignee: Kyle Marvin
>     Priority: Minor
>      Fix For: V1Beta

>
> BeanInfo introspection of a Control type that has a property that is based 
> upon a JSR-175 annotation type will fail w/ an Introspection exception.   The 
> following is a sample exception, based upon the 
> org.apache.beehive.controls.test.controls.basic.Hello test control included 
> in the checkin tests:
> Caused by: java.beans.IntrospectionException: Method not found: setGender
>         at java.beans.PropertyDescriptor.<init>(PropertyDescriptor.java:93)
>         at java.beans.PropertyDescriptor.<init>(PropertyDescriptor.java:53)
>         at 
> org.apache.beehive.controls.test.controls.basic.HelloBeanBeanInfo.initPropertyDescriptors(HelloBeanBeanInfo.java:137)
>         at 
> org.apache.beehive.controls.test.controls.basic.HelloBeanBeanInfo.getPropertyDescriptors(HelloBeanBeanInfo.java:149)
>         at 
> java.beans.Introspector.getTargetPropertyInfo(Introspector.java:475)
>         at java.beans.Introspector.getBeanInfo(Introspector.java:385)
>         at java.beans.Introspector.getBeanInfo(Introspector.java:155)
> The rub is that the java.beans.PropertyDescriptor class expects to find a 
> method with the following signature:
>         public void setGender(Gender gender);
> while bean exposes the following instead:
>         public void setGender(PropertyMap genderMap);
> This is because it is impossible to 'new' a JSR-175 annotation type and 
> initialize its values, so the PropertyMap interface (and the corresponsing 
> concrete impl, BeanPropertyMap) exists to abstract a collection of annotation 
> type property values.  You can create a BeanPropertyMap, push values into it, 
> and then use it to set the (annotation-typed) property.
> The fix is to modify the BeanInfo codegen to use the 
> java.beans.PropertyDescriptor constructor that takes actual 
> java.lang.reflect.Methods as arguments, to explicitly specify the specific 
> setter method on the bean class instead of allowing PropertyDescriptor to use 
> the default algorithm.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
If you want more information on JIRA, or have a bug to report see:
   http://www.atlassian.com/software/jira

Reply via email to