|
@@ -22,15 +22,41 @@
|
22
|
22
|
|
23
|
23
|
package com.dmdirc.ui.messages;
|
24
|
24
|
|
|
25
|
+import com.dmdirc.DMDircMBassador;
|
|
26
|
+import com.dmdirc.events.UserErrorEvent;
|
|
27
|
+import com.dmdirc.logger.ErrorLevel;
|
|
28
|
+
|
|
29
|
+import java.lang.reflect.Method;
|
|
30
|
+import java.util.Optional;
|
|
31
|
+
|
|
32
|
+import javax.inject.Inject;
|
|
33
|
+
|
25
|
34
|
public class EventPropertyManager {
|
26
|
35
|
|
27
|
|
- public <S, T> T getProperty(final S object, final Class<? extends S> type,
|
|
36
|
+ private final DMDircMBassador eventBus;
|
|
37
|
+
|
|
38
|
+ @Inject
|
|
39
|
+ public EventPropertyManager(final DMDircMBassador eventBus) {
|
|
40
|
+ this.eventBus = eventBus;
|
|
41
|
+ }
|
|
42
|
+
|
|
43
|
+ public <S> Optional<Object> getProperty(final S object, final Class<? extends S> type,
|
28
|
44
|
final String property) {
|
29
|
|
- return null;
|
|
45
|
+ final String methodName = "get" + property.substring(0, 1).toUpperCase()
|
|
46
|
+ + property.substring(1);
|
|
47
|
+ try {
|
|
48
|
+ final Method method = type.getMethod(methodName);
|
|
49
|
+ return Optional.ofNullable(method.invoke(object));
|
|
50
|
+ } catch (ReflectiveOperationException ex) {
|
|
51
|
+ eventBus.publish(new UserErrorEvent(ErrorLevel.MEDIUM, ex,
|
|
52
|
+ "Unable to format event: could not retrieve property " + property,
|
|
53
|
+ ex.getMessage()));
|
|
54
|
+ }
|
|
55
|
+ return Optional.empty();
|
30
|
56
|
}
|
31
|
57
|
|
32
|
|
- public String applyFunction(final String input, final String property) {
|
33
|
|
- return null;
|
|
58
|
+ public Optional<String> applyFunction(final String input, final String function) {
|
|
59
|
+ return Optional.empty();
|
34
|
60
|
}
|
35
|
61
|
|
36
|
62
|
}
|