Thus when we extract a property or event name from the middle of an existing Java name, we
normally convert the first character to lower case. However to support the occasional use of
upper-case names, we check if the first two characters of the name are both upper case and
so leave it alone. So for example,
"FooBah" becomes "fooBah"
"Z" becomes "z"
"URL" becomes "URL"
We provide a method Introspector.decapitalize which implements this conversion rule.
Should do something like:
private String convertMethodName(String methodName,int firstCharacter) {
if (methodName.length() >= firstCharacter+2) {
if (! Character.isUpperCase(methodName.charAt(firstCharacter+1))) {
return Character.toLowerCase(methodName.charAt(firstCharacter)) + methodName.substring(firstCharacter+1);
} else {
return methodName.substring(3);
}
} else {
return Character.toLowerCase(methodName.charAt(firstCharacter)) + methodName.substring(firstCharacter+1);
}
}
protected Object doGetter(Method method, Object[] args)
throws Throwable
{
String methodName = method.getName();
String attrName = null;
if (methodName.startsWith("get"))
attrName = convertMethodName(methodName,3);
else if (methodName.startsWith("is"))
attrName = convertMethodName(methodName,2);
else
throw new IllegalAccessError(methodName + " is not a valid getter method.");
return readProperty(attrName);
}
protected Object doSetter(Method method, Object[] args)
throws Throwable
{
String methodName = method.getName();
String attrName = null;
if (methodName.startsWith("set"))
attrName = convertMethodName(methodName,3);
else
throw new IllegalAccessError(methodName + " is not a valid setter method.");
writeProperty(attrName, args[0]);
return null;
}