* @param configurable An Object
* @return A default Configuration with properties of the object, based on reflection of the
* object's getters and setters.
*/
public static ConfigurationImpl defaultConfiguration(Object configurable) {
ConfigurationImpl result = new ConfigurationImpl(configurable);
Method[] methods = configurable.getClass().getMethods();
for (int i = 0; i < methods.length; i++) {
Class<?> returnType = methods[i].getReturnType();
String propName = getPropertyName(methods[i]);
if (isSingleValueGetter(methods[i])
&& !methods[i].getName().equals("getClass")
&& !methods[i].getName().equals("getConfiguration")
&& !isCounter(methods[i])) {
result.defineSingleValuedProperty(propName, returnType, false);
} else if (isIndexedGetter(methods[i]) && !result.getPropertyNames().contains(propName)) {
Property p = ListPropertyImpl.getListProperty(result, propName, returnType);
if (p != null) {
result.defineProperty(p);
}
} else if (isNamedGetter(methods[i]) && !result.getPropertyNames().contains(propName)) {
Property p = NamedValuePropertyImpl.getNamedValueProperty(result, propName, returnType);
if (p != null) {
result.defineProperty(p);
}
}
}
//look for additional array, list, and map getters
for (int i = 0; i < methods.length; i++) {
Type returnType = methods[i].getGenericReturnType();
String propName = getPropertyName(methods[i]);
if (isGetter(methods[i]) && !isNamesGetter(methods[i]) && !result.getPropertyNames().contains(propName)
&& !result.getPropertyNames().contains(stripSuffix(propName, "s"))
&& !result.getPropertyNames().contains(stripSuffix(propName, "es"))) {
Property p = null;
if (returnType instanceof Class<?> && MainHandler.getInstance().canHandle((Class<?>) returnType)) {
p = SingleValuedPropertyImpl.getSingleValuedProperty(result, propName, (Class<?>) returnType);
} else if (returnType instanceof Class<?> && ((Class<?>) returnType).isArray()) {
p = ListPropertyImpl.getListProperty(result, propName, ((Class<?>) returnType).getComponentType());
} else if (returnType instanceof ParameterizedType) {
Type rawType = ((ParameterizedType) returnType).getRawType();
Type[] typeArgs = ((ParameterizedType) returnType).getActualTypeArguments();
if (rawType instanceof Class<?> && List.class.isAssignableFrom((Class<?>) rawType)
&& typeArgs[0] instanceof Class<?>) {
p = ListPropertyImpl.getListProperty(result, propName, (Class<?>) typeArgs[0]);
} else if (rawType instanceof Class<?> && Map.class.isAssignableFrom((Class<?>) rawType)
&& typeArgs[0] instanceof Class<?> && typeArgs[1] instanceof Class<?>) {
p = NamedValuePropertyImpl.getNamedValueProperty(result, propName, (Class<?>) typeArgs[1]);
}
}
if (p != null) {
result.defineProperty(p);
}
}
}
return result;