ConfigBeanImpl.java: split up too-long getValue method

This commit is contained in:
Havoc Pennington 2015-03-02 09:53:13 -05:00
parent e522071442
commit 483f7a87f7

View File

@ -137,6 +137,30 @@ public class ConfigBeanImpl {
} else if (parameterClass == Object.class) {
return config.getAnyRef(configPropName);
} else if (parameterClass == List.class) {
return getListValue(beanClass, parameterType, parameterClass, config, configPropName);
} else if (parameterClass == Map.class) {
// we could do better here, but right now we don't.
Type[] typeArgs = ((ParameterizedType)parameterType).getActualTypeArguments();
if (typeArgs[0] != String.class || typeArgs[1] != Object.class) {
throw new ConfigException.BadBean("Bean property '" + configPropName + "' of class " + beanClass.getName() + " has unsupported Map<" + typeArgs[0] + "," + typeArgs[1] + ">, only Map<String,Object> is supported right now");
}
return config.getObject(configPropName).unwrapped();
} else if (parameterClass == Config.class) {
return config.getConfig(configPropName);
} else if (parameterClass == ConfigObject.class) {
return config.getObject(configPropName);
} else if (parameterClass == ConfigValue.class) {
return config.getValue(configPropName);
} else if (parameterClass == ConfigList.class) {
return config.getList(configPropName);
} else if (hasAtLeastOneBeanProperty(parameterClass)) {
return createInternal(config.getConfig(configPropName), parameterClass);
} else {
throw new ConfigException.BadBean("Bean property " + configPropName + " of class " + beanClass.getName() + " has unsupported type " + parameterType);
}
}
private static Object getListValue(Class beanClass, Type parameterType, Class parameterClass, Config config, String configPropName) {
Type elementType = ((ParameterizedType)parameterType).getActualTypeArguments()[0];
if (elementType == Boolean.class) {
@ -164,26 +188,6 @@ public class ConfigBeanImpl {
} else {
throw new ConfigException.BadBean("Bean property '" + configPropName + "' of class " + beanClass.getName() + " has unsupported list element type " + elementType);
}
} else if (parameterClass == Map.class) {
// we could do better here, but right now we don't.
Type[] typeArgs = ((ParameterizedType)parameterType).getActualTypeArguments();
if (typeArgs[0] != String.class || typeArgs[1] != Object.class) {
throw new ConfigException.BadBean("Bean property '" + configPropName + "' of class " + beanClass.getName() + " has unsupported Map<" + typeArgs[0] + "," + typeArgs[1] + ">, only Map<String,Object> is supported right now");
}
return config.getObject(configPropName).unwrapped();
} else if (parameterClass == Config.class) {
return config.getConfig(configPropName);
} else if (parameterClass == ConfigObject.class) {
return config.getObject(configPropName);
} else if (parameterClass == ConfigValue.class) {
return config.getValue(configPropName);
} else if (parameterClass == ConfigList.class) {
return config.getList(configPropName);
} else if (hasAtLeastOneBeanProperty(parameterClass)) {
return createInternal(config.getConfig(configPropName), parameterClass);
} else {
throw new ConfigException.BadBean("Bean property " + configPropName + " of class " + beanClass.getName() + " has unsupported type " + parameterType);
}
}
// null if we can't easily say; this is heuristic/best-effort