Новый API: Получение параметров из BundleContext со значением по-умолчанию
Во-первых, так случалось, что при попытке получить не существующий параметр возникало исключение NullPointerException. А по логике, если параметр не найден, то надо бы и вернуть null, а не "ругаться в консоль". Во-вторых, в стандартном OSGi API не предусмотрено возвращение значения по-умолчанию. Эти две проблемы обновленный ASys API и решает.
This commit is contained in:
@@ -21,6 +21,20 @@ public class ASysUtils {
|
|||||||
getCommandListByAnnotationMethods(scope, commnadsObject.getClass()));
|
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) {
|
private static Dictionary<String, Object> getCommandListByAnnotationMethods(String scope, Class<?> clazz) {
|
||||||
List<String> listCommand = new Vector<>();
|
List<String> listCommand = new Vector<>();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user