in examples-trunk/dynamic-proxy-to-access-mbean/src/main/java/org/superbiz/dynamic/mbean/DynamicMBeanHandler.java [86:116]
private String attributeName(MBeanInfo infos, String methodName, Class<?> type) {
String found = null;
String foundBackUp = null; // without checking the type
final String attributeName = methodName.substring(3, methodName.length());
final String lowerName = Character.toLowerCase(methodName.charAt(3)) + methodName.substring(4, methodName.length());
for (MBeanAttributeInfo attribute : infos.getAttributes()) {
final String name = attribute.getName();
if (attributeName.equals(name)) {
foundBackUp = attributeName;
if (attribute.getType().equals(type.getName())) {
found = name;
}
} else if (found == null && ((lowerName.equals(name) && !attributeName.equals(name))
|| lowerName.equalsIgnoreCase(name))) {
foundBackUp = name;
if (attribute.getType().equals(type.getName())) {
found = name;
}
}
}
if (found == null && foundBackUp == null) {
throw new UnsupportedOperationException("cannot find attribute " + attributeName);
}
if (found != null) {
return found;
}
return foundBackUp;
}