aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorIvan Martinez <ivanfmartinez@users.noreply.github.com>2018-04-09 21:20:15 -0300
committerIvan Martinez <ivanfmartinez@users.noreply.github.com>2018-04-09 21:20:15 -0300
commit9339c709e5a6d521fd0bdd4b1221b909c0a888d6 (patch)
treed5ffa7b35ba2bbc0036d21128495405877723a00 /src
parent084b8370d98cdad1cae6d9d708582846da50e3b4 (diff)
downloadtraccar-server-9339c709e5a6d521fd0bdd4b1221b909c0a888d6.tar.gz
traccar-server-9339c709e5a6d521fd0bdd4b1221b909c0a888d6.tar.bz2
traccar-server-9339c709e5a6d521fd0bdd4b1221b909c0a888d6.zip
configuration support for notificators
Diffstat (limited to 'src')
-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() {