in struts2-uel-plugin/src/main/java/org/apache/struts2/uel/reflection/GenericReflectionProvider.java [672:742]
static void findObjectIndexedPropertyDescriptors(Class targetClass, Map intoMap)
throws ReflectionException {
Map allMethods = getMethods(targetClass, false);
Map pairs = new HashMap(101);
for (Iterator it = allMethods.keySet().iterator(); it.hasNext();) {
String methodName = (String) it.next();
List methods = (List) allMethods.get(methodName);
/*
* Only process set/get where there is exactly one implementation of the method per
* class and those implementations are all the same
*/
if (indexMethodCheck(methods)) {
boolean isGet = false, isSet = false;
Method m = (Method) methods.get(0);
if (((isSet = methodName.startsWith(SET_PREFIX)) || (isGet = methodName.startsWith(GET_PREFIX)))
&& (methodName.length() > 3)) {
String propertyName = Introspector.decapitalize(methodName.substring(3));
Class[] parameterTypes = getParameterTypes(m);
int parameterCount = parameterTypes.length;
if (isGet && (parameterCount == 1) && (m.getReturnType() != Void.TYPE)) {
List pair = (List) pairs.get(propertyName);
if (pair == null) {
pairs.put(propertyName, pair = new ArrayList());
}
pair.add(m);
}
if (isSet && (parameterCount == 2) && (m.getReturnType() == Void.TYPE)) {
List pair = (List) pairs.get(propertyName);
if (pair == null) {
pairs.put(propertyName, pair = new ArrayList());
}
pair.add(m);
}
}
}
}
for (Iterator it = pairs.keySet().iterator(); it.hasNext();) {
String propertyName = (String) it.next();
List methods = (List) pairs.get(propertyName);
if (methods.size() == 2) {
Method method1 = (Method) methods.get(0), method2 = (Method) methods.get(1), setMethod = (method1
.getParameterTypes().length == 2) ? method1 : method2, getMethod = (setMethod == method1) ? method2
: method1;
Class keyType = getMethod.getParameterTypes()[0], propertyType = getMethod.getReturnType();
if (keyType == setMethod.getParameterTypes()[0]) {
if (propertyType == setMethod.getParameterTypes()[1]) {
ObjectIndexedPropertyDescriptor propertyDescriptor;
try {
propertyDescriptor = new ObjectIndexedPropertyDescriptor(propertyName, propertyType,
getMethod, setMethod);
} catch (Exception ex) {
throw new ReflectionException("creating object indexed property descriptor for '" + propertyName
+ "' in " + targetClass, ex);
}
intoMap.put(propertyName, propertyDescriptor);
}
}
}
}
}