Archived
0

Новый API: Получение параметров из BundleContext со значением по-умолчанию

Во-первых, так случалось, что при попытке получить не существующий параметр возникало исключение NullPointerException. А по логике, если параметр не найден, то надо бы и вернуть null, а не "ругаться в консоль".
 Во-вторых, в стандартном OSGi API не предусмотрено возвращение значения по-умолчанию.
 Эти две проблемы обновленный ASys API и решает.
This commit is contained in:
2016-08-15 12:36:48 +03:00
parent 15f1da3dac
commit 16e3c8a673

View File

@@ -21,6 +21,20 @@ public class ASysUtils {
getCommandListByAnnotationMethods(scope, commnadsObject.getClass()));
}
public static String GetProperty(BundleContext bundleContext, String name) {
return GetProperty(bundleContext, name, null);
}
public static String GetProperty(BundleContext bundleContext, String name, String defaultValue) {
try {
String result = bundleContext.getProperty(name);
if (result == null) return defaultValue;
else return result;
} catch (NullPointerException e) {
return defaultValue;
}
}
private static Dictionary<String, Object> getCommandListByAnnotationMethods(String scope, Class<?> clazz) {
List<String> listCommand = new Vector<>();