|
@@ -51,40 +51,43 @@ import java.util.Map;
|
51
|
51
|
*/
|
52
|
52
|
public final class ActionManager {
|
53
|
53
|
|
|
54
|
+ /** A singleton instance of the ActionManager. */
|
|
55
|
+ private static final ActionManager INSTANCE = new ActionManager();
|
|
56
|
+
|
54
|
57
|
/** A list of registered action types. */
|
55
|
|
- private static final List<ActionType> ACTION_TYPES
|
|
58
|
+ private final List<ActionType> types
|
56
|
59
|
= new ArrayList<ActionType>();
|
57
|
60
|
|
58
|
61
|
/** A list of registered action components. */
|
59
|
|
- private static final List<ActionComponent> ACTION_COMPONENTS
|
|
62
|
+ private final List<ActionComponent> components
|
60
|
63
|
= new ArrayList<ActionComponent>();
|
61
|
64
|
|
62
|
65
|
/** A list of registered action comparisons. */
|
63
|
|
- private static final List<ActionComparison> ACTION_COMPARISON
|
|
66
|
+ private final List<ActionComparison> comparisons
|
64
|
67
|
= new ArrayList<ActionComparison>();
|
65
|
68
|
|
66
|
69
|
/** A map linking types and a list of actions that're registered for them. */
|
67
|
|
- private static final MapList<ActionType, Action> ACTIONS
|
|
70
|
+ private final MapList<ActionType, Action> actions
|
68
|
71
|
= new MapList<ActionType, Action>();
|
69
|
72
|
|
70
|
73
|
/** A map linking groups and a list of actions that're in them. */
|
71
|
|
- private static final Map<String, ActionGroup> GROUPS
|
|
74
|
+ private final Map<String, ActionGroup> groups
|
72
|
75
|
= new HashMap<String, ActionGroup>();
|
73
|
76
|
|
74
|
77
|
/** A map of objects to synchronise on for concurrency groups. */
|
75
|
|
- private static final Map<String, Object> LOCKS
|
|
78
|
+ private final Map<String, Object> locks
|
76
|
79
|
= new HashMap<String, Object>();
|
77
|
80
|
|
78
|
81
|
/** A map of the action type groups to the action types within. */
|
79
|
|
- private static final MapList<String, ActionType> ACTIONTYPE_GROUPS
|
|
82
|
+ private final MapList<String, ActionType> typeGroups
|
80
|
83
|
= new MapList<String, ActionType>();
|
81
|
84
|
|
82
|
85
|
/** The listeners that we have registered. */
|
83
|
|
- private static final MapList<ActionType, ActionListener> LISTENERS
|
|
86
|
+ private final MapList<ActionType, ActionListener> listeners
|
84
|
87
|
= new MapList<ActionType, ActionListener>();
|
85
|
88
|
|
86
|
89
|
/** Indicates whether or not user actions should be killed (not processed). */
|
87
|
|
- private static boolean killSwitch
|
|
90
|
+ private boolean killSwitch
|
88
|
91
|
= IdentityManager.getGlobalConfig().getOptionBool("actions", "killswitch");
|
89
|
92
|
|
90
|
93
|
/** Creates a new instance of ActionManager. */
|
|
@@ -92,10 +95,28 @@ public final class ActionManager {
|
92
|
95
|
// Shouldn't be instansiated
|
93
|
96
|
}
|
94
|
97
|
|
|
98
|
+ /**
|
|
99
|
+ * Returns a singleton instance of the Action Manager.
|
|
100
|
+ *
|
|
101
|
+ * @return A singleton ActionManager instance
|
|
102
|
+ */
|
|
103
|
+ public static ActionManager getActionManager() {
|
|
104
|
+ return INSTANCE;
|
|
105
|
+ }
|
|
106
|
+
|
95
|
107
|
/**
|
96
|
108
|
* Initialises the action manager.
|
|
109
|
+ * @deprecated Use {@link #getActionManager()} and non-static methods
|
97
|
110
|
*/
|
|
111
|
+ @Deprecated
|
98
|
112
|
public static void init() {
|
|
113
|
+ INSTANCE.initialise();
|
|
114
|
+ }
|
|
115
|
+
|
|
116
|
+ /**
|
|
117
|
+ * Initialises the action manager.
|
|
118
|
+ */
|
|
119
|
+ public void initialise() {
|
99
|
120
|
registerActionTypes(CoreActionType.values());
|
100
|
121
|
registerActionComparisons(CoreActionComparison.values());
|
101
|
122
|
registerActionComponents(CoreActionComponent.values());
|
|
@@ -129,9 +150,18 @@ public final class ActionManager {
|
129
|
150
|
|
130
|
151
|
/**
|
131
|
152
|
* Saves all actions.
|
|
153
|
+ * @deprecated Use {@link #getActionManager()} and non-static methods
|
132
|
154
|
*/
|
|
155
|
+ @Deprecated
|
133
|
156
|
public static void saveActions() {
|
134
|
|
- for (ActionGroup group : GROUPS.values()) {
|
|
157
|
+ INSTANCE.saveAllActions();
|
|
158
|
+ }
|
|
159
|
+
|
|
160
|
+ /**
|
|
161
|
+ * Saves all actions.
|
|
162
|
+ */
|
|
163
|
+ public void saveAllActions() {
|
|
164
|
+ for (ActionGroup group : groups.values()) {
|
135
|
165
|
for (Action action : group) {
|
136
|
166
|
action.save();
|
137
|
167
|
}
|
|
@@ -143,8 +173,20 @@ public final class ActionManager {
|
143
|
173
|
*
|
144
|
174
|
* @param name The name of the setting to be registered
|
145
|
175
|
* @param value The default value for the setting
|
|
176
|
+ * @deprecated Use {@link #getActionManager()} and non-static methods
|
146
|
177
|
*/
|
|
178
|
+ @Deprecated
|
147
|
179
|
public static void registerDefault(final String name, final String value) {
|
|
180
|
+ INSTANCE.registerSetting(name, value);
|
|
181
|
+ }
|
|
182
|
+
|
|
183
|
+ /**
|
|
184
|
+ * Registers the specified default setting for actions.
|
|
185
|
+ *
|
|
186
|
+ * @param name The name of the setting to be registered
|
|
187
|
+ * @param value The default value for the setting
|
|
188
|
+ */
|
|
189
|
+ public void registerSetting(final String name, final String value) {
|
148
|
190
|
IdentityManager.getAddonIdentity().setOption("actions", name, value);
|
149
|
191
|
}
|
150
|
192
|
|
|
@@ -152,24 +194,47 @@ public final class ActionManager {
|
152
|
194
|
* Registers the specified group of actions with the manager.
|
153
|
195
|
*
|
154
|
196
|
* @param group The group of actions to be registered
|
|
197
|
+ * @deprecated Use {@link #getActionManager()} and non-static methods
|
155
|
198
|
*/
|
|
199
|
+ @Deprecated
|
156
|
200
|
public static void registerGroup(final ActionGroup group) {
|
157
|
|
- GROUPS.put(group.getName(), group);
|
|
201
|
+ INSTANCE.addGroup(group);
|
|
202
|
+ }
|
|
203
|
+
|
|
204
|
+ /**
|
|
205
|
+ * Registers the specified group of actions with the manager.
|
|
206
|
+ *
|
|
207
|
+ * @param group The group of actions to be registered
|
|
208
|
+ */
|
|
209
|
+ public void addGroup(final ActionGroup group) {
|
|
210
|
+ groups.put(group.getName(), group);
|
158
|
211
|
}
|
159
|
212
|
|
160
|
213
|
/**
|
161
|
214
|
* Registers a set of actiontypes with the manager.
|
162
|
215
|
*
|
163
|
216
|
* @param types An array of ActionTypes to be registered
|
|
217
|
+ * @deprecated Use {@link #getActionManager()} and non-static methods
|
164
|
218
|
*/
|
|
219
|
+ @Deprecated
|
165
|
220
|
@Precondition("None of the specified ActionTypes are null")
|
166
|
221
|
public static void registerActionTypes(final ActionType[] types) {
|
167
|
|
- for (ActionType type : types) {
|
|
222
|
+ INSTANCE.registerTypes(types);
|
|
223
|
+ }
|
|
224
|
+
|
|
225
|
+ /**
|
|
226
|
+ * Registers a set of actiontypes with the manager.
|
|
227
|
+ *
|
|
228
|
+ * @param newTypes An array of ActionTypes to be registered
|
|
229
|
+ */
|
|
230
|
+ @Precondition("None of the specified ActionTypes are null")
|
|
231
|
+ public void registerTypes(final ActionType[] newTypes) {
|
|
232
|
+ for (ActionType type : newTypes) {
|
168
|
233
|
Logger.assertTrue(type != null);
|
169
|
234
|
|
170
|
|
- if(!ACTION_TYPES.contains(type)) {
|
171
|
|
- ACTION_TYPES.add(type);
|
172
|
|
- ACTIONTYPE_GROUPS.add(type.getType().getGroup(), type);
|
|
235
|
+ if(!types.contains(type)) {
|
|
236
|
+ types.add(type);
|
|
237
|
+ typeGroups.add(type.getType().getGroup(), type);
|
173
|
238
|
}
|
174
|
239
|
}
|
175
|
240
|
}
|
|
@@ -178,13 +243,25 @@ public final class ActionManager {
|
178
|
243
|
* Registers a set of action components with the manager.
|
179
|
244
|
*
|
180
|
245
|
* @param comps An array of ActionComponents to be registered
|
|
246
|
+ * @deprecated Use {@link #getActionManager()} and non-static methods
|
181
|
247
|
*/
|
|
248
|
+ @Deprecated
|
182
|
249
|
@Precondition("None of the specified ActionComponents are null")
|
183
|
250
|
public static void registerActionComponents(final ActionComponent[] comps) {
|
|
251
|
+ INSTANCE.registerComponents(comps);
|
|
252
|
+ }
|
|
253
|
+
|
|
254
|
+ /**
|
|
255
|
+ * Registers a set of action components with the manager.
|
|
256
|
+ *
|
|
257
|
+ * @param comps An array of ActionComponents to be registered
|
|
258
|
+ */
|
|
259
|
+ @Precondition("None of the specified ActionComponents are null")
|
|
260
|
+ public void registerComponents(final ActionComponent[] comps) {
|
184
|
261
|
for (ActionComponent comp : comps) {
|
185
|
262
|
Logger.assertTrue(comp != null);
|
186
|
263
|
|
187
|
|
- ACTION_COMPONENTS.add(comp);
|
|
264
|
+ components.add(comp);
|
188
|
265
|
}
|
189
|
266
|
}
|
190
|
267
|
|
|
@@ -192,13 +269,25 @@ public final class ActionManager {
|
192
|
269
|
* Registers a set of action comparisons with the manager.
|
193
|
270
|
*
|
194
|
271
|
* @param comps An array of ActionComparisons to be registered
|
|
272
|
+ * @deprecated Use {@link #getActionManager()} and non-static methods
|
195
|
273
|
*/
|
|
274
|
+ @Deprecated
|
196
|
275
|
@Precondition("None of the specified ActionComparisons are null")
|
197
|
276
|
public static void registerActionComparisons(final ActionComparison[] comps) {
|
|
277
|
+ INSTANCE.registerComparisons(comps);
|
|
278
|
+ }
|
|
279
|
+
|
|
280
|
+ /**
|
|
281
|
+ * Registers a set of action comparisons with the manager.
|
|
282
|
+ *
|
|
283
|
+ * @param comps An array of ActionComparisons to be registered
|
|
284
|
+ */
|
|
285
|
+ @Precondition("None of the specified ActionComparisons are null")
|
|
286
|
+ public void registerComparisons(final ActionComparison[] comps) {
|
198
|
287
|
for (ActionComparison comp : comps) {
|
199
|
288
|
Logger.assertTrue(comp != null);
|
200
|
289
|
|
201
|
|
- ACTION_COMPARISON.add(comp);
|
|
290
|
+ comparisons.add(comp);
|
202
|
291
|
}
|
203
|
292
|
}
|
204
|
293
|
|
|
@@ -206,27 +295,58 @@ public final class ActionManager {
|
206
|
295
|
* Returns a map of groups to action lists.
|
207
|
296
|
*
|
208
|
297
|
* @return a map of groups to action lists
|
|
298
|
+ * @deprecated Use {@link #getActionManager()} and non-static methods
|
209
|
299
|
*/
|
|
300
|
+ @Deprecated
|
210
|
301
|
public static Map<String, ActionGroup> getGroups() {
|
211
|
|
- return GROUPS;
|
|
302
|
+ return INSTANCE.getGroupsMap();
|
|
303
|
+ }
|
|
304
|
+
|
|
305
|
+ /**
|
|
306
|
+ * Returns a map of groups to action lists.
|
|
307
|
+ *
|
|
308
|
+ * @return a map of groups to action lists
|
|
309
|
+ */
|
|
310
|
+ public Map<String, ActionGroup> getGroupsMap() {
|
|
311
|
+ return groups;
|
212
|
312
|
}
|
213
|
313
|
|
214
|
314
|
/**
|
215
|
315
|
* Returns a map of type groups to types.
|
216
|
316
|
*
|
217
|
317
|
* @return A map of type groups to types
|
|
318
|
+ * @deprecated Use {@link #getActionManager()} and non-static methods
|
218
|
319
|
*/
|
|
320
|
+ @Deprecated
|
219
|
321
|
public static MapList<String, ActionType> getTypeGroups() {
|
220
|
|
- return ACTIONTYPE_GROUPS;
|
|
322
|
+ return INSTANCE.getGroupedTypes();
|
|
323
|
+ }
|
|
324
|
+
|
|
325
|
+ /**
|
|
326
|
+ * Returns a map of type groups to types.
|
|
327
|
+ *
|
|
328
|
+ * @return A map of type groups to types
|
|
329
|
+ */
|
|
330
|
+ public MapList<String, ActionType> getGroupedTypes() {
|
|
331
|
+ return typeGroups;
|
221
|
332
|
}
|
222
|
333
|
|
223
|
334
|
/**
|
224
|
335
|
* Loads actions from the user's directory.
|
|
336
|
+ * @deprecated Use {@link #getActionManager()} and non-static methods
|
225
|
337
|
*/
|
|
338
|
+ @Deprecated
|
226
|
339
|
public static void loadActions() {
|
227
|
|
- ACTIONS.clear();
|
|
340
|
+ INSTANCE.loadUserActions();
|
|
341
|
+ }
|
|
342
|
+
|
|
343
|
+ /**
|
|
344
|
+ * Loads actions from the user's directory.
|
|
345
|
+ */
|
|
346
|
+ public void loadUserActions() {
|
|
347
|
+ actions.clear();
|
228
|
348
|
|
229
|
|
- for (ActionGroup group : GROUPS.values()) {
|
|
349
|
+ for (ActionGroup group : groups.values()) {
|
230
|
350
|
group.clear();
|
231
|
351
|
}
|
232
|
352
|
|
|
@@ -258,8 +378,8 @@ public final class ActionManager {
|
258
|
378
|
/**
|
259
|
379
|
* Creates new ActionGroupComponents for each action group.
|
260
|
380
|
*/
|
261
|
|
- private static void registerComponents() {
|
262
|
|
- for (ActionGroup group : GROUPS.values()) {
|
|
381
|
+ private void registerComponents() {
|
|
382
|
+ for (ActionGroup group : groups.values()) {
|
263
|
383
|
new ActionGroupComponent(group);
|
264
|
384
|
}
|
265
|
385
|
}
|
|
@@ -270,12 +390,12 @@ public final class ActionManager {
|
270
|
390
|
* @param dir The directory to scan.
|
271
|
391
|
*/
|
272
|
392
|
@Precondition("The specified File is not null and represents a directory")
|
273
|
|
- private static void loadActions(final File dir) {
|
|
393
|
+ private void loadActions(final File dir) {
|
274
|
394
|
Logger.assertTrue(dir != null);
|
275
|
395
|
Logger.assertTrue(dir.isDirectory());
|
276
|
396
|
|
277
|
|
- if (!GROUPS.containsKey(dir.getName())) {
|
278
|
|
- GROUPS.put(dir.getName(), new ActionGroup(dir.getName()));
|
|
397
|
+ if (!groups.containsKey(dir.getName())) {
|
|
398
|
+ groups.put(dir.getName(), new ActionGroup(dir.getName()));
|
279
|
399
|
}
|
280
|
400
|
|
281
|
401
|
for (File file : dir.listFiles()) {
|
|
@@ -287,13 +407,25 @@ public final class ActionManager {
|
287
|
407
|
* Registers an action with the manager.
|
288
|
408
|
*
|
289
|
409
|
* @param action The action to be registered
|
|
410
|
+ * @deprecated Use {@link #getActionManager()} and non-static methods
|
290
|
411
|
*/
|
|
412
|
+ @Deprecated
|
291
|
413
|
@Precondition("The specified action is not null")
|
292
|
414
|
public static void registerAction(final Action action) {
|
|
415
|
+ INSTANCE.addAction(action);
|
|
416
|
+ }
|
|
417
|
+
|
|
418
|
+ /**
|
|
419
|
+ * Registers an action with the manager.
|
|
420
|
+ *
|
|
421
|
+ * @param action The action to be registered
|
|
422
|
+ */
|
|
423
|
+ @Precondition("The specified action is not null")
|
|
424
|
+ public void addAction(final Action action) {
|
293
|
425
|
Logger.assertTrue(action != null);
|
294
|
426
|
|
295
|
427
|
for (ActionType trigger : action.getTriggers()) {
|
296
|
|
- ACTIONS.add(trigger, action);
|
|
428
|
+ actions.add(trigger, action);
|
297
|
429
|
}
|
298
|
430
|
|
299
|
431
|
getGroup(action.getGroup()).add(action);
|
|
@@ -305,25 +437,50 @@ public final class ActionManager {
|
305
|
437
|
*
|
306
|
438
|
* @param name The name of the group to retrieve
|
307
|
439
|
* @return The corresponding ActionGroup
|
|
440
|
+ * @deprecated Use {@link #getActionManager()} and non-static methods
|
308
|
441
|
*/
|
|
442
|
+ @Deprecated
|
309
|
443
|
public static ActionGroup getGroup(final String name) {
|
310
|
|
- if (!GROUPS.containsKey(name)) {
|
311
|
|
- GROUPS.put(name, new ActionGroup(name));
|
|
444
|
+ return INSTANCE.getOrCreateGroup(name);
|
|
445
|
+ }
|
|
446
|
+
|
|
447
|
+ /**
|
|
448
|
+ * Retrieves the action group with the specified name. A new group is
|
|
449
|
+ * created if it doesn't already exist.
|
|
450
|
+ *
|
|
451
|
+ * @param name The name of the group to retrieve
|
|
452
|
+ * @return The corresponding ActionGroup
|
|
453
|
+ */
|
|
454
|
+ public ActionGroup getOrCreateGroup(final String name) {
|
|
455
|
+ if (!groups.containsKey(name)) {
|
|
456
|
+ groups.put(name, new ActionGroup(name));
|
312
|
457
|
}
|
313
|
458
|
|
314
|
|
- return GROUPS.get(name);
|
|
459
|
+ return groups.get(name);
|
315
|
460
|
}
|
316
|
461
|
|
317
|
462
|
/**
|
318
|
463
|
* Unregisters an action with the manager.
|
319
|
464
|
*
|
320
|
465
|
* @param action The action to be unregistered
|
|
466
|
+ * @deprecated Use {@link #getActionManager()} and non-static methods
|
321
|
467
|
*/
|
|
468
|
+ @Deprecated
|
322
|
469
|
@Precondition("The specified action is not null")
|
323
|
470
|
public static void unregisterAction(final Action action) {
|
|
471
|
+ INSTANCE.removeAction(action);
|
|
472
|
+ }
|
|
473
|
+
|
|
474
|
+ /**
|
|
475
|
+ * Unregisters an action with the manager.
|
|
476
|
+ *
|
|
477
|
+ * @param action The action to be unregistered
|
|
478
|
+ */
|
|
479
|
+ @Precondition("The specified action is not null")
|
|
480
|
+ public void removeAction(final Action action) {
|
324
|
481
|
Logger.assertTrue(action != null);
|
325
|
482
|
|
326
|
|
- ACTIONS.removeFromAll(action);
|
|
483
|
+ actions.removeFromAll(action);
|
327
|
484
|
getGroup(action.getGroup()).remove(action);
|
328
|
485
|
}
|
329
|
486
|
|
|
@@ -332,7 +489,9 @@ public final class ActionManager {
|
332
|
489
|
* triggers change.
|
333
|
490
|
*
|
334
|
491
|
* @param action The action to be reregistered
|
|
492
|
+ * @deprecated Use {@link #getActionManager()} and non-static methods
|
335
|
493
|
*/
|
|
494
|
+ @Deprecated
|
336
|
495
|
public static void reregisterAction(final Action action) {
|
337
|
496
|
unregisterAction(action);
|
338
|
497
|
registerAction(action);
|
|
@@ -363,7 +522,9 @@ public final class ActionManager {
|
363
|
522
|
* @param arguments The arguments for the event
|
364
|
523
|
* @return True if the event should be processed, or false if an action
|
365
|
524
|
* listener has requested the event be skipped.
|
|
525
|
+ * @deprecated Use {@link #getActionManager()} and non-static methods
|
366
|
526
|
*/
|
|
527
|
+ @Deprecated
|
367
|
528
|
@Precondition({
|
368
|
529
|
"The specified ActionType is not null",
|
369
|
530
|
"The specified ActionType has a valid ActionMetaType",
|
|
@@ -371,15 +532,35 @@ public final class ActionManager {
|
371
|
532
|
})
|
372
|
533
|
public static boolean processEvent(final ActionType type,
|
373
|
534
|
final StringBuffer format, final Object ... arguments) {
|
|
535
|
+ return INSTANCE.triggerEvent(type, format, arguments);
|
|
536
|
+ }
|
|
537
|
+
|
|
538
|
+ /**
|
|
539
|
+ * Processes an event of the specified type.
|
|
540
|
+ *
|
|
541
|
+ * @param type The type of the event to process
|
|
542
|
+ * @param format The format of the message that's going to be displayed for
|
|
543
|
+ * the event. Actions may change this format.
|
|
544
|
+ * @param arguments The arguments for the event
|
|
545
|
+ * @return True if the event should be processed, or false if an action
|
|
546
|
+ * listener has requested the event be skipped.
|
|
547
|
+ */
|
|
548
|
+ @Precondition({
|
|
549
|
+ "The specified ActionType is not null",
|
|
550
|
+ "The specified ActionType has a valid ActionMetaType",
|
|
551
|
+ "The length of the arguments array equals the arity of the ActionType's ActionMetaType"
|
|
552
|
+ })
|
|
553
|
+ public boolean triggerEvent(final ActionType type,
|
|
554
|
+ final StringBuffer format, final Object ... arguments) {
|
374
|
555
|
Logger.assertTrue(type != null);
|
375
|
556
|
Logger.assertTrue(type.getType() != null);
|
376
|
557
|
Logger.assertTrue(type.getType().getArity() == arguments.length);
|
377
|
558
|
|
378
|
559
|
boolean res = false;
|
379
|
560
|
|
380
|
|
- if (LISTENERS.containsKey(type)) {
|
|
561
|
+ if (listeners.containsKey(type)) {
|
381
|
562
|
for (ActionListener listener
|
382
|
|
- : new ArrayList<ActionListener>(LISTENERS.get(type))) {
|
|
563
|
+ : new ArrayList<ActionListener>(listeners.get(type))) {
|
383
|
564
|
try {
|
384
|
565
|
listener.processEvent(type, format, arguments);
|
385
|
566
|
} catch (Exception e) {
|
|
@@ -406,25 +587,25 @@ public final class ActionManager {
|
406
|
587
|
* @return True if the event should be skipped, or false if it can continue
|
407
|
588
|
*/
|
408
|
589
|
@Precondition("The specified ActionType is not null")
|
409
|
|
- private static boolean triggerActions(final ActionType type,
|
|
590
|
+ private boolean triggerActions(final ActionType type,
|
410
|
591
|
final StringBuffer format, final Object ... arguments) {
|
411
|
592
|
Logger.assertTrue(type != null);
|
412
|
593
|
|
413
|
594
|
boolean res = false;
|
414
|
595
|
|
415
|
|
- if (ACTIONS.containsKey(type)) {
|
416
|
|
- for (Action action : new ArrayList<Action>(ACTIONS.get(type))) {
|
|
596
|
+ if (actions.containsKey(type)) {
|
|
597
|
+ for (Action action : new ArrayList<Action>(actions.get(type))) {
|
417
|
598
|
try {
|
418
|
599
|
if (action.getConcurrencyGroup() == null) {
|
419
|
600
|
res |= action.trigger(format, arguments);
|
420
|
601
|
} else {
|
421
|
|
- synchronized (LOCKS) {
|
422
|
|
- if (!LOCKS.containsKey(action.getConcurrencyGroup())) {
|
423
|
|
- LOCKS.put(action.getConcurrencyGroup(), new Object());
|
|
602
|
+ synchronized (locks) {
|
|
603
|
+ if (!locks.containsKey(action.getConcurrencyGroup())) {
|
|
604
|
+ locks.put(action.getConcurrencyGroup(), new Object());
|
424
|
605
|
}
|
425
|
606
|
}
|
426
|
607
|
|
427
|
|
- synchronized (LOCKS.get(action.getConcurrencyGroup())) {
|
|
608
|
+ synchronized (locks.get(action.getConcurrencyGroup())) {
|
428
|
609
|
res |= action.trigger(format, arguments);
|
429
|
610
|
}
|
430
|
611
|
}
|
|
@@ -456,20 +637,37 @@ public final class ActionManager {
|
456
|
637
|
* @param group The group to be created
|
457
|
638
|
*
|
458
|
639
|
* @return The newly created group
|
|
640
|
+ * @deprecated Use {@link #getActionManager()} and non-static methods
|
459
|
641
|
*/
|
|
642
|
+ @Deprecated
|
460
|
643
|
@Precondition({
|
461
|
644
|
"The specified group is non-null and not empty",
|
462
|
645
|
"The specified group is not an existing group"
|
463
|
646
|
})
|
464
|
647
|
public static ActionGroup makeGroup(final String group) {
|
|
648
|
+ return INSTANCE.createGroup(group);
|
|
649
|
+ }
|
|
650
|
+
|
|
651
|
+ /**
|
|
652
|
+ * Creates a new group with the specified name.
|
|
653
|
+ *
|
|
654
|
+ * @param group The group to be created
|
|
655
|
+ *
|
|
656
|
+ * @return The newly created group
|
|
657
|
+ */
|
|
658
|
+ @Precondition({
|
|
659
|
+ "The specified group is non-null and not empty",
|
|
660
|
+ "The specified group is not an existing group"
|
|
661
|
+ })
|
|
662
|
+ public ActionGroup createGroup(final String group) {
|
465
|
663
|
Logger.assertTrue(group != null);
|
466
|
664
|
Logger.assertTrue(!group.isEmpty());
|
467
|
|
- Logger.assertTrue(!GROUPS.containsKey(group));
|
|
665
|
+ Logger.assertTrue(!groups.containsKey(group));
|
468
|
666
|
|
469
|
667
|
final File file = new File(getDirectory() + group);
|
470
|
668
|
if (file.isDirectory() || file.mkdir()) {
|
471
|
669
|
final ActionGroup actionGroup = new ActionGroup(group);
|
472
|
|
- GROUPS.put(group, actionGroup);
|
|
670
|
+ groups.put(group, actionGroup);
|
473
|
671
|
return actionGroup;
|
474
|
672
|
} else {
|
475
|
673
|
throw new IllegalArgumentException("Unable to create action group directory"
|
|
@@ -481,17 +679,32 @@ public final class ActionManager {
|
481
|
679
|
* Removes the group with the specified name.
|
482
|
680
|
*
|
483
|
681
|
* @param group The group to be removed
|
|
682
|
+ * @deprecated Use {@link #getActionManager()} and non-static methods
|
484
|
683
|
*/
|
|
684
|
+ @Deprecated
|
485
|
685
|
@Precondition({
|
486
|
686
|
"The specified group is non-null and not empty",
|
487
|
687
|
"The specified group is an existing group"
|
488
|
688
|
})
|
489
|
689
|
public static void removeGroup(final String group) {
|
|
690
|
+ INSTANCE.deleteGroup(group);
|
|
691
|
+ }
|
|
692
|
+
|
|
693
|
+ /**
|
|
694
|
+ * Removes the group with the specified name.
|
|
695
|
+ *
|
|
696
|
+ * @param group The group to be removed
|
|
697
|
+ */
|
|
698
|
+ @Precondition({
|
|
699
|
+ "The specified group is non-null and not empty",
|
|
700
|
+ "The specified group is an existing group"
|
|
701
|
+ })
|
|
702
|
+ public void deleteGroup(final String group) {
|
490
|
703
|
Logger.assertTrue(group != null);
|
491
|
704
|
Logger.assertTrue(!group.isEmpty());
|
492
|
|
- Logger.assertTrue(GROUPS.containsKey(group));
|
|
705
|
+ Logger.assertTrue(groups.containsKey(group));
|
493
|
706
|
|
494
|
|
- for (Action action : GROUPS.get(group).getActions()) {
|
|
707
|
+ for (Action action : groups.get(group).getActions()) {
|
495
|
708
|
unregisterAction(action);
|
496
|
709
|
}
|
497
|
710
|
|
|
@@ -513,7 +726,7 @@ public final class ActionManager {
|
513
|
726
|
return;
|
514
|
727
|
}
|
515
|
728
|
|
516
|
|
- GROUPS.remove(group);
|
|
729
|
+ groups.remove(group);
|
517
|
730
|
}
|
518
|
731
|
|
519
|
732
|
/**
|
|
@@ -521,7 +734,9 @@ public final class ActionManager {
|
521
|
734
|
*
|
522
|
735
|
* @param oldName The old name of the group
|
523
|
736
|
* @param newName The new name of the group
|
|
737
|
+ * @deprecated Use {@link #getActionManager()} and non-static methods
|
524
|
738
|
*/
|
|
739
|
+ @Deprecated
|
525
|
740
|
@Precondition({
|
526
|
741
|
"The old name is non-null and not empty",
|
527
|
742
|
"The old name is an existing group",
|
|
@@ -530,17 +745,34 @@ public final class ActionManager {
|
530
|
745
|
"The old name does not equal the new name"
|
531
|
746
|
})
|
532
|
747
|
public static void renameGroup(final String oldName, final String newName) {
|
|
748
|
+ INSTANCE.changeGroupName(oldName, newName);
|
|
749
|
+ }
|
|
750
|
+
|
|
751
|
+ /**
|
|
752
|
+ * Renames the specified group.
|
|
753
|
+ *
|
|
754
|
+ * @param oldName The old name of the group
|
|
755
|
+ * @param newName The new name of the group
|
|
756
|
+ */
|
|
757
|
+ @Precondition({
|
|
758
|
+ "The old name is non-null and not empty",
|
|
759
|
+ "The old name is an existing group",
|
|
760
|
+ "The new name is non-null and not empty",
|
|
761
|
+ "The new name is not an existing group",
|
|
762
|
+ "The old name does not equal the new name"
|
|
763
|
+ })
|
|
764
|
+ public void changeGroupName(final String oldName, final String newName) {
|
533
|
765
|
Logger.assertTrue(oldName != null);
|
534
|
766
|
Logger.assertTrue(!oldName.isEmpty());
|
535
|
767
|
Logger.assertTrue(newName != null);
|
536
|
768
|
Logger.assertTrue(!newName.isEmpty());
|
537
|
|
- Logger.assertTrue(GROUPS.containsKey(oldName));
|
538
|
|
- Logger.assertTrue(!GROUPS.containsKey(newName));
|
|
769
|
+ Logger.assertTrue(groups.containsKey(oldName));
|
|
770
|
+ Logger.assertTrue(!groups.containsKey(newName));
|
539
|
771
|
Logger.assertTrue(!newName.equals(oldName));
|
540
|
772
|
|
541
|
773
|
makeGroup(newName);
|
542
|
774
|
|
543
|
|
- for (Action action : GROUPS.get(oldName).getActions()) {
|
|
775
|
+ for (Action action : groups.get(oldName).getActions()) {
|
544
|
776
|
action.setGroup(newName);
|
545
|
777
|
getGroup(oldName).remove(action);
|
546
|
778
|
getGroup(newName).add(action);
|
|
@@ -554,14 +786,27 @@ public final class ActionManager {
|
554
|
786
|
* doesn't match a valid registered action comparison.
|
555
|
787
|
*
|
556
|
788
|
* @param type The name of the action comparison to try and find
|
557
|
|
- * @return The actioncomparison with the specified name, or null on failure
|
|
789
|
+ * @return The type with the specified name, or null on failure
|
|
790
|
+ * @deprecated Use {@link #getActionManager()} and non-static methods
|
558
|
791
|
*/
|
|
792
|
+ @Deprecated
|
559
|
793
|
public static ActionType getActionType(final String type) {
|
|
794
|
+ return INSTANCE.getType(type);
|
|
795
|
+ }
|
|
796
|
+
|
|
797
|
+ /**
|
|
798
|
+ * Returns the action comparison specified by the given string, or null if it
|
|
799
|
+ * doesn't match a valid registered action comparison.
|
|
800
|
+ *
|
|
801
|
+ * @param type The name of the action comparison to try and find
|
|
802
|
+ * @return The type with the specified name, or null on failure
|
|
803
|
+ */
|
|
804
|
+ public ActionType getType(final String type) {
|
560
|
805
|
if (type == null || type.isEmpty()) {
|
561
|
806
|
return null;
|
562
|
807
|
}
|
563
|
808
|
|
564
|
|
- for (ActionType target : ACTION_TYPES) {
|
|
809
|
+ for (ActionType target : types) {
|
565
|
810
|
if (target.name().equals(type)) {
|
566
|
811
|
return target;
|
567
|
812
|
}
|
|
@@ -576,13 +821,27 @@ public final class ActionManager {
|
576
|
821
|
*
|
577
|
822
|
* @param type The type to be checked against
|
578
|
823
|
* @return A list of compatible action types
|
|
824
|
+ * @deprecated Use {@link #getActionManager()} and non-static methods
|
579
|
825
|
*/
|
|
826
|
+ @Deprecated
|
580
|
827
|
@Precondition("The specified type is not null")
|
581
|
828
|
public static List<ActionType> getCompatibleTypes(final ActionType type) {
|
|
829
|
+ return INSTANCE.findCompatibleTypes(type);
|
|
830
|
+ }
|
|
831
|
+
|
|
832
|
+ /**
|
|
833
|
+ * Returns a list of action types that are compatible with the one
|
|
834
|
+ * specified.
|
|
835
|
+ *
|
|
836
|
+ * @param type The type to be checked against
|
|
837
|
+ * @return A list of compatible action types
|
|
838
|
+ */
|
|
839
|
+ @Precondition("The specified type is not null")
|
|
840
|
+ public List<ActionType> findCompatibleTypes(final ActionType type) {
|
582
|
841
|
Logger.assertTrue(type != null);
|
583
|
842
|
|
584
|
843
|
final List<ActionType> res = new ArrayList<ActionType>();
|
585
|
|
- for (ActionType target : ACTION_TYPES) {
|
|
844
|
+ for (ActionType target : types) {
|
586
|
845
|
if (!target.equals(type) && target.getType().equals(type.getType())) {
|
587
|
846
|
res.add(target);
|
588
|
847
|
}
|
|
@@ -597,13 +856,27 @@ public final class ActionManager {
|
597
|
856
|
*
|
598
|
857
|
* @param target The class to be tested
|
599
|
858
|
* @return A list of compatible action components
|
|
859
|
+ * @deprecated Use {@link #getActionManager()} and non-static methods
|
600
|
860
|
*/
|
|
861
|
+ @Deprecated
|
601
|
862
|
@Precondition("The specified target is not null")
|
602
|
863
|
public static List<ActionComponent> getCompatibleComponents(final Class<?> target) {
|
|
864
|
+ return INSTANCE.findCompatibleComponents(target);
|
|
865
|
+ }
|
|
866
|
+
|
|
867
|
+ /**
|
|
868
|
+ * Returns a list of action components that are compatible with the
|
|
869
|
+ * specified class.
|
|
870
|
+ *
|
|
871
|
+ * @param target The class to be tested
|
|
872
|
+ * @return A list of compatible action components
|
|
873
|
+ */
|
|
874
|
+ @Precondition("The specified target is not null")
|
|
875
|
+ public List<ActionComponent> findCompatibleComponents(final Class<?> target) {
|
603
|
876
|
Logger.assertTrue(target != null);
|
604
|
877
|
|
605
|
878
|
final List<ActionComponent> res = new ArrayList<ActionComponent>();
|
606
|
|
- for (ActionComponent subject : ACTION_COMPONENTS) {
|
|
879
|
+ for (ActionComponent subject : components) {
|
607
|
880
|
if (subject.appliesTo().equals(target)) {
|
608
|
881
|
res.add(subject);
|
609
|
882
|
}
|
|
@@ -618,13 +891,27 @@ public final class ActionManager {
|
618
|
891
|
*
|
619
|
892
|
* @param target The class to be tested
|
620
|
893
|
* @return A list of compatible action comparisons
|
|
894
|
+ * @deprecated Use {@link #getActionManager()} and non-static methods
|
621
|
895
|
*/
|
|
896
|
+ @Deprecated
|
622
|
897
|
@Precondition("The specified target is not null")
|
623
|
898
|
public static List<ActionComparison> getCompatibleComparisons(final Class<?> target) {
|
|
899
|
+ return INSTANCE.findCompatibleComparisons(target);
|
|
900
|
+ }
|
|
901
|
+
|
|
902
|
+ /**
|
|
903
|
+ * Returns a list of action comparisons that are compatible with the
|
|
904
|
+ * specified class.
|
|
905
|
+ *
|
|
906
|
+ * @param target The class to be tested
|
|
907
|
+ * @return A list of compatible action comparisons
|
|
908
|
+ */
|
|
909
|
+ @Precondition("The specified target is not null")
|
|
910
|
+ public List<ActionComparison> findCompatibleComparisons(final Class<?> target) {
|
624
|
911
|
Logger.assertTrue(target != null);
|
625
|
912
|
|
626
|
913
|
final List<ActionComparison> res = new ArrayList<ActionComparison>();
|
627
|
|
- for (ActionComparison subject : ACTION_COMPARISON) {
|
|
914
|
+ for (ActionComparison subject : comparisons) {
|
628
|
915
|
if (subject.appliesTo().equals(target)) {
|
629
|
916
|
res.add(subject);
|
630
|
917
|
}
|
|
@@ -637,18 +924,40 @@ public final class ActionManager {
|
637
|
924
|
* Returns a list of all the action types registered by this manager.
|
638
|
925
|
*
|
639
|
926
|
* @return A list of registered action types
|
|
927
|
+ * @deprecated Use {@link #getActionManager()} and non-static methods
|
640
|
928
|
*/
|
|
929
|
+ @Deprecated
|
641
|
930
|
public static List<ActionType> getTypes() {
|
642
|
|
- return ACTION_TYPES;
|
|
931
|
+ return INSTANCE.getAllTypes();
|
|
932
|
+ }
|
|
933
|
+
|
|
934
|
+ /**
|
|
935
|
+ * Returns a list of all the action types registered by this manager.
|
|
936
|
+ *
|
|
937
|
+ * @return A list of registered action types
|
|
938
|
+ */
|
|
939
|
+ public List<ActionType> getAllTypes() {
|
|
940
|
+ return types;
|
643
|
941
|
}
|
644
|
942
|
|
645
|
943
|
/**
|
646
|
944
|
* Returns a list of all the action types registered by this manager.
|
647
|
945
|
*
|
648
|
946
|
* @return A list of registered action comparisons
|
|
947
|
+ * @deprecated Use {@link #getActionManager()} and non-static methods
|
649
|
948
|
*/
|
|
949
|
+ @Deprecated
|
650
|
950
|
public static List<ActionComparison> getComparisons() {
|
651
|
|
- return ACTION_COMPARISON;
|
|
951
|
+ return INSTANCE.getAllComparisons();
|
|
952
|
+ }
|
|
953
|
+
|
|
954
|
+ /**
|
|
955
|
+ * Returns a list of all the action types registered by this manager.
|
|
956
|
+ *
|
|
957
|
+ * @return A list of registered action comparisons
|
|
958
|
+ */
|
|
959
|
+ public List<ActionComparison> getAllComparisons() {
|
|
960
|
+ return comparisons;
|
652
|
961
|
}
|
653
|
962
|
|
654
|
963
|
/**
|
|
@@ -657,13 +966,27 @@ public final class ActionManager {
|
657
|
966
|
*
|
658
|
967
|
* @param type The name of the action component to try and find
|
659
|
968
|
* @return The actioncomponent with the specified name, or null on failure
|
|
969
|
+ * @deprecated Use {@link #getActionManager()} and non-static methods
|
660
|
970
|
*/
|
|
971
|
+ @Deprecated
|
661
|
972
|
@Precondition("The specified type is non-null and not empty")
|
662
|
973
|
public static ActionComponent getActionComponent(final String type) {
|
|
974
|
+ return INSTANCE.getComponent(type);
|
|
975
|
+ }
|
|
976
|
+
|
|
977
|
+ /**
|
|
978
|
+ * Returns the action component specified by the given string, or null if it
|
|
979
|
+ * doesn't match a valid registered action component.
|
|
980
|
+ *
|
|
981
|
+ * @param type The name of the action component to try and find
|
|
982
|
+ * @return The actioncomponent with the specified name, or null on failure
|
|
983
|
+ */
|
|
984
|
+ @Precondition("The specified type is non-null and not empty")
|
|
985
|
+ public ActionComponent getComponent(final String type) {
|
663
|
986
|
Logger.assertTrue(type != null);
|
664
|
987
|
Logger.assertTrue(!type.isEmpty());
|
665
|
988
|
|
666
|
|
- for (ActionComponent target : ACTION_COMPONENTS) {
|
|
989
|
+ for (ActionComponent target : components) {
|
667
|
990
|
if (target.name().equals(type)) {
|
668
|
991
|
return target;
|
669
|
992
|
}
|
|
@@ -678,13 +1001,27 @@ public final class ActionManager {
|
678
|
1001
|
*
|
679
|
1002
|
* @param type The name of the action type to try and find
|
680
|
1003
|
* @return The actiontype with the specified name, or null on failure
|
|
1004
|
+ * @deprecated Use {@link #getActionManager()} and non-static methods
|
681
|
1005
|
*/
|
|
1006
|
+ @Deprecated
|
682
|
1007
|
@Precondition("The specified type is non-null and not empty")
|
683
|
1008
|
public static ActionComparison getActionComparison(final String type) {
|
|
1009
|
+ return INSTANCE.getComparison(type);
|
|
1010
|
+ }
|
|
1011
|
+
|
|
1012
|
+ /**
|
|
1013
|
+ * Returns the action type specified by the given string, or null if it
|
|
1014
|
+ * doesn't match a valid registered action type.
|
|
1015
|
+ *
|
|
1016
|
+ * @param type The name of the action type to try and find
|
|
1017
|
+ * @return The actiontype with the specified name, or null on failure
|
|
1018
|
+ */
|
|
1019
|
+ @Precondition("The specified type is non-null and not empty")
|
|
1020
|
+ public ActionComparison getComparison(final String type) {
|
684
|
1021
|
Logger.assertTrue(type != null);
|
685
|
1022
|
Logger.assertTrue(!type.isEmpty());
|
686
|
1023
|
|
687
|
|
- for (ActionComparison target : ACTION_COMPARISON) {
|
|
1024
|
+ for (ActionComparison target : comparisons) {
|
688
|
1025
|
if (target.name().equals(type)) {
|
689
|
1026
|
return target;
|
690
|
1027
|
}
|
|
@@ -714,10 +1051,22 @@ public final class ActionManager {
|
714
|
1051
|
*
|
715
|
1052
|
* @param types The action types that are to be listened for
|
716
|
1053
|
* @param listener The listener to be added
|
|
1054
|
+ * @deprecated Use {@link #getActionManager()} and non-static methods
|
717
|
1055
|
*/
|
|
1056
|
+ @Deprecated
|
718
|
1057
|
public static void addListener(final ActionListener listener, final ActionType ... types) {
|
|
1058
|
+ INSTANCE.registerListener(listener, types);
|
|
1059
|
+ }
|
|
1060
|
+
|
|
1061
|
+ /**
|
|
1062
|
+ * Adds a new listener for the specified action type.
|
|
1063
|
+ *
|
|
1064
|
+ * @param types The action types that are to be listened for
|
|
1065
|
+ * @param listener The listener to be added
|
|
1066
|
+ */
|
|
1067
|
+ public void registerListener(final ActionListener listener, final ActionType ... types) {
|
719
|
1068
|
for (ActionType type : types) {
|
720
|
|
- LISTENERS.add(type, listener);
|
|
1069
|
+ listeners.add(type, listener);
|
721
|
1070
|
}
|
722
|
1071
|
}
|
723
|
1072
|
|
|
@@ -726,10 +1075,22 @@ public final class ActionManager {
|
726
|
1075
|
*
|
727
|
1076
|
* @param types The action types that were being listened for
|
728
|
1077
|
* @param listener The listener to be removed
|
|
1078
|
+ * @deprecated Use {@link #getActionManager()} and non-static methods
|
729
|
1079
|
*/
|
|
1080
|
+ @Deprecated
|
730
|
1081
|
public static void removeListener(final ActionListener listener, final ActionType ... types) {
|
|
1082
|
+ INSTANCE.unregisterListener(listener, types);
|
|
1083
|
+ }
|
|
1084
|
+
|
|
1085
|
+ /**
|
|
1086
|
+ * Removes a listener for the specified action type.
|
|
1087
|
+ *
|
|
1088
|
+ * @param types The action types that were being listened for
|
|
1089
|
+ * @param listener The listener to be removed
|
|
1090
|
+ */
|
|
1091
|
+ public void unregisterListener(final ActionListener listener, final ActionType ... types) {
|
731
|
1092
|
for (ActionType type : types) {
|
732
|
|
- LISTENERS.remove(type, listener);
|
|
1093
|
+ listeners.remove(type, listener);
|
733
|
1094
|
}
|
734
|
1095
|
}
|
735
|
1096
|
|
|
@@ -737,8 +1098,19 @@ public final class ActionManager {
|
737
|
1098
|
* Removes a listener for all action types.
|
738
|
1099
|
*
|
739
|
1100
|
* @param listener The listener to be removed
|
|
1101
|
+ * @deprecated Use {@link #getActionManager()} and non-static methods
|
740
|
1102
|
*/
|
|
1103
|
+ @Deprecated
|
741
|
1104
|
public static void removeListener(final ActionListener listener) {
|
742
|
|
- LISTENERS.removeFromAll(listener);
|
|
1105
|
+ INSTANCE.unregisterListener(listener);
|
|
1106
|
+ }
|
|
1107
|
+
|
|
1108
|
+ /**
|
|
1109
|
+ * Removes a listener for all action types.
|
|
1110
|
+ *
|
|
1111
|
+ * @param listener The listener to be removed
|
|
1112
|
+ */
|
|
1113
|
+ public void unregisterListener(final ActionListener listener) {
|
|
1114
|
+ listeners.removeFromAll(listener);
|
743
|
1115
|
}
|
744
|
1116
|
}
|