in apm-commons/apm-util/src/main/java/org/apache/skywalking/apm/util/ConfigInitializer.java [49:106]
private static void initNextLevel(Properties properties, Class<?> recentConfigType,
ConfigDesc parentDesc) throws IllegalArgumentException, IllegalAccessException {
for (Field field : recentConfigType.getFields()) {
if (Modifier.isPublic(field.getModifiers()) && Modifier.isStatic(field.getModifiers())) {
String configKey = (parentDesc + "." + field.getName()).toLowerCase();
Class<?> type = field.getType();
if (Map.class.isAssignableFrom(type)) {
/*
* Map config format is, config_key[map_key]=map_value, such as plugin.opgroup.resttemplate.rule[abc]=/url/path
* "config_key[]=" will generate an empty Map , user could use this mechanism to set an empty Map
*/
ParameterizedType genericType = (ParameterizedType) field.getGenericType();
Type[] argumentTypes = genericType.getActualTypeArguments();
Type keyType = argumentTypes[0];
Type valueType = argumentTypes[1];
// A chance to set an empty map
if (properties.containsKey(configKey + "[]")) {
Map currentValue = (Map) field.get(null);
if (currentValue != null && !currentValue.isEmpty()) {
field.set(null, initEmptyMap(type));
}
} else {
// Set the map from config key and properties
Map map = readMapType(type, configKey, properties, keyType, valueType);
if (map.size() != 0) {
field.set(null, map);
}
}
} else if (properties.containsKey(configKey)) {
//In order to guarantee the default value could be reset as empty , we parse the value even if it's blank
String propertyValue = properties.getProperty(configKey, "");
if (Collection.class.isAssignableFrom(type)) {
ParameterizedType genericType = (ParameterizedType) field.getGenericType();
Type argumentType = genericType.getActualTypeArguments()[0];
Collection collection = convertToCollection(argumentType, type, propertyValue);
field.set(null, collection);
} else {
// Convert the value into real type
final Length lengthDefine = field.getAnnotation(Length.class);
if (lengthDefine != null && propertyValue.length() > lengthDefine.value()) {
StringUtil.cut(propertyValue, lengthDefine.value());
System.err.printf("The config value will be truncated , because the length max than %d : %s -> %s%n", lengthDefine.value(), configKey, propertyValue);
}
Object convertedValue = convertToTypicalType(type, propertyValue);
if (convertedValue != null) {
field.set(null, convertedValue);
}
}
}
}
}
for (Class<?> innerConfiguration : recentConfigType.getClasses()) {
parentDesc.append(innerConfiguration.getSimpleName());
initNextLevel(properties, innerConfiguration, parentDesc);
parentDesc.removeLastDesc();
}
}