|
|
@ -41,8 +41,8 @@ import static org.springframework.beans.PropertyDescriptorUtils.*; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Decorator for a standard {@link BeanInfo} object, e.g. as created by |
|
|
|
* Decorator for a standard {@link BeanInfo} object, e.g. as created by |
|
|
|
* {@link Introspector#getBeanInfo(Class)}, designed to discover and register non-void |
|
|
|
* {@link Introspector#getBeanInfo(Class)}, designed to discover and register static |
|
|
|
* returning setter methods. For example: |
|
|
|
* and/or non-void returning setter methods. For example: |
|
|
|
* <pre>{@code |
|
|
|
* <pre>{@code |
|
|
|
* public class Bean { |
|
|
|
* public class Bean { |
|
|
|
* private Foo foo; |
|
|
|
* private Foo foo; |
|
|
@ -102,37 +102,40 @@ class ExtendedBeanInfo implements BeanInfo { |
|
|
|
new SimpleNonIndexedPropertyDescriptor(pd)); |
|
|
|
new SimpleNonIndexedPropertyDescriptor(pd)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
for (Method method : findNonVoidWriteMethods(delegate.getMethodDescriptors())) { |
|
|
|
for (Method method : findCandidateWriteMethods(delegate.getMethodDescriptors())) { |
|
|
|
handleNonVoidWriteMethod(method); |
|
|
|
handleCandidateWriteMethod(method); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private List<Method> findNonVoidWriteMethods(MethodDescriptor[] methodDescriptors) { |
|
|
|
private List<Method> findCandidateWriteMethods(MethodDescriptor[] methodDescriptors) { |
|
|
|
List<Method> matches = new ArrayList<Method>(); |
|
|
|
List<Method> matches = new ArrayList<Method>(); |
|
|
|
for (MethodDescriptor methodDescriptor : methodDescriptors) { |
|
|
|
for (MethodDescriptor methodDescriptor : methodDescriptors) { |
|
|
|
Method method = methodDescriptor.getMethod(); |
|
|
|
Method method = methodDescriptor.getMethod(); |
|
|
|
if (isNonVoidWriteMethod(method)) { |
|
|
|
if (isCandidateWriteMethod(method)) { |
|
|
|
matches.add(method); |
|
|
|
matches.add(method); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return matches; |
|
|
|
return matches; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static boolean isNonVoidWriteMethod(Method method) { |
|
|
|
public static boolean isCandidateWriteMethod(Method method) { |
|
|
|
String methodName = method.getName(); |
|
|
|
String methodName = method.getName(); |
|
|
|
Class<?>[] parameterTypes = method.getParameterTypes(); |
|
|
|
Class<?>[] parameterTypes = method.getParameterTypes(); |
|
|
|
int nParams = parameterTypes.length; |
|
|
|
int nParams = parameterTypes.length; |
|
|
|
if (methodName.length() > 3 && methodName.startsWith("set") && |
|
|
|
if (methodName.length() > 3 && methodName.startsWith("set") && |
|
|
|
Modifier.isPublic(method.getModifiers()) && |
|
|
|
Modifier.isPublic(method.getModifiers()) && |
|
|
|
!void.class.isAssignableFrom(method.getReturnType()) && |
|
|
|
( |
|
|
|
|
|
|
|
!void.class.isAssignableFrom(method.getReturnType()) || |
|
|
|
|
|
|
|
Modifier.isStatic(method.getModifiers()) |
|
|
|
|
|
|
|
) && |
|
|
|
(nParams == 1 || (nParams == 2 && parameterTypes[0].equals(int.class)))) { |
|
|
|
(nParams == 1 || (nParams == 2 && parameterTypes[0].equals(int.class)))) { |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void handleNonVoidWriteMethod(Method method) throws IntrospectionException { |
|
|
|
private void handleCandidateWriteMethod(Method method) throws IntrospectionException { |
|
|
|
int nParams = method.getParameterTypes().length; |
|
|
|
int nParams = method.getParameterTypes().length; |
|
|
|
String propertyName = propertyNameFor(method); |
|
|
|
String propertyName = propertyNameFor(method); |
|
|
|
Class<?> propertyType = method.getParameterTypes()[nParams-1]; |
|
|
|
Class<?> propertyType = method.getParameterTypes()[nParams-1]; |
|
|
|