3030import java .beans .IntrospectionException ;
3131import java .beans .PropertyDescriptor ;
3232import java .beans .SimpleBeanInfo ;
33+ import java .lang .reflect .Method ;
3334import java .util .Arrays ;
3435import java .util .List ;
3536
@@ -94,23 +95,26 @@ public PropertyDescriptor[] getPropertyDescriptors() {
9495 synchronized (AbstractBeanInfo .class ) {
9596 if (propertyDescriptorCache == null ) {
9697 final PropertyInfo [] propInfo = getProperties ();
97- final List <PropertyInfo > hiddenProps = Arrays
98- .asList (getHiddenProperties ());
99- final List <PropertyInfo > preferredProps = Arrays
100- .asList (getPreferredProperties ());
101- final List <PropertyInfo > expertProps = Arrays
102- .asList (getExpertProperties ());
98+ final List <PropertyInfo > hiddenProps = Arrays .asList (getHiddenProperties ());
99+ final List <PropertyInfo > preferredProps = Arrays .asList (getPreferredProperties ());
100+ final List <PropertyInfo > expertProps = Arrays .asList (getExpertProperties ());
103101 propertyDescriptorCache = new PropertyDescriptor [propInfo .length ];
104102
105103 try {
106104 for (int i = 0 ; i < propertyDescriptorCache .length ; ++i ) {
107105 final PropertyDescriptor prop ;
108106
109- prop = new PropertyDescriptor (propInfo [i ].name (),
110- getBeanClass ());
107+ Class <?> beanClass = getBeanClass ();
108+ String propName = propInfo [i ].name ();
109+ propName = propName .substring (0 , 1 ).toUpperCase () + propName .substring (1 );
110+
111+ String readMethodName = getReadMethodName (beanClass , propName );
112+ String writeMethodName = getWriteMethodName (beanClass , propName );
113+
114+ prop = new PropertyDescriptor (propInfo [i ].name (), getBeanClass (), readMethodName ,
115+ writeMethodName );
111116 prop .setDisplayName (getDisplayName (propInfo [i ]));
112- prop
113- .setShortDescription (getShortDescription (propInfo [i ]));
117+ prop .setShortDescription (getShortDescription (propInfo [i ]));
114118 if (hiddenProps .contains (propInfo [i ])) {
115119 prop .setHidden (true );
116120 }
@@ -132,6 +136,34 @@ public PropertyDescriptor[] getPropertyDescriptors() {
132136 return propertyDescriptorCache ;
133137 }
134138
139+ private String getReadMethodName (Class <?> beanClass , String propName ) {
140+
141+ try {
142+ return beanClass .getMethod ("get" + propName ).getName ();
143+ } catch (NoSuchMethodException ignored ) {
144+ try {
145+ return beanClass .getMethod ("is" + propName ).getName ();
146+ } catch (NoSuchMethodException ex ) {
147+ return null ;
148+ }
149+ }
150+ }
151+
152+ private String getWriteMethodName (Class <?> beanClass , String propName ) {
153+
154+ String name = "set" + propName ;
155+
156+ Method [] declaredMethods = beanClass .getDeclaredMethods ();
157+ for ( Method method : declaredMethods ) {
158+ if ( name .equals (method .getName ())) {
159+ return name ;
160+ }
161+ }
162+
163+ return null ;
164+ }
165+
166+
135167 /**
136168 * Gibt die Liste der Properties zurück der Java Bean zurück.
137169 *
0 commit comments