aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar
diff options
context:
space:
mode:
Diffstat (limited to 'src/org/traccar')
-rw-r--r--src/org/traccar/notification/NotificatorManager.java41
1 files changed, 28 insertions, 13 deletions
diff --git a/src/org/traccar/notification/NotificatorManager.java b/src/org/traccar/notification/NotificatorManager.java
index 1aa76beff..4353b7914 100644
--- a/src/org/traccar/notification/NotificatorManager.java
+++ b/src/org/traccar/notification/NotificatorManager.java
@@ -16,30 +16,45 @@
*/
package org.traccar.notification;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.Map;
import org.traccar.Context;
+import org.traccar.helper.Log;
-public class NotificatorManager {
+public final class NotificatorManager {
- protected NotificatorManager() {
- //not called
- }
-
- private static final Map<String, Notificator> NOTIFICATORS = new HashMap<>();
- private static final Notificator NULL_NOTIFICATOR = new NotificationNull();
+ private static final NotificatorManager INSTANCE = new NotificatorManager();
- static {
- if (Context.getSmsManager() != null) {
- NOTIFICATORS.put("sms", new NotificationSms());
+ private NotificatorManager() {
+ final String[] types = Context.getConfig().getString("notificator.types", "").split(",");
+ for (String type : types) {
+ final String className = Context.getConfig().getString("notificator." + type + ".class", "");
+ if (className.length() > 0) {
+ try {
+ final Class<Notificator> c = (Class<Notificator>) Class.forName(className);
+ try {
+ final Constructor<Notificator> constructor = c.getConstructor(new Class[]{String.class});
+ notificators.put(type, constructor.newInstance(type));
+ } catch (NoSuchMethodException e) {
+ // No constructor with String argument
+ notificators.put(type, c.newInstance());
+ }
+ } catch (ClassNotFoundException | InstantiationException
+ | IllegalAccessException | InvocationTargetException e) {
+ Log.error("Unable to load notificator class for " + type + " " + className + " " + e.getMessage());
+ }
+ }
}
- NOTIFICATORS.put("mail", new NotificationMail());
- NOTIFICATORS.put("web", new NotificationWeb());
}
+ private final Map<String, Notificator> notificators = new HashMap<>();
+ private static final Notificator NULL_NOTIFICATOR = new NotificationNull();
+
public static Notificator getNotificator(String type) {
- return NOTIFICATORS.getOrDefault(type, NULL_NOTIFICATOR);
+ return INSTANCE.notificators.getOrDefault(type, NULL_NOTIFICATOR);
}
public static Notificator getSms() {