Bladeren bron

Introduce a factory for actions.

Change-Id: Id4172cf1a062fc6e15230cf7870adea8348c4878
Reviewed-on: http://gerrit.dmdirc.com/2725
Reviewed-by: Greg Holmes <greg@dmdirc.com>
Automatic-Compile: DMDirc Build Manager
tags/0.8rc1
Chris Smith 10 jaren geleden
bovenliggende
commit
f787e83ba2
2 gewijzigde bestanden met toevoegingen van 94 en 0 verwijderingen
  1. 89
    0
      src/com/dmdirc/actions/ActionFactory.java
  2. 5
    0
      src/com/dmdirc/plugins/PluginInjectorInitialiser.java

+ 89
- 0
src/com/dmdirc/actions/ActionFactory.java Bestand weergeven

@@ -0,0 +1,89 @@
1
+/*
2
+ * Copyright (c) 2006-2013 DMDirc Developers
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.actions;
24
+
25
+import com.dmdirc.interfaces.actions.ActionType;
26
+
27
+import java.util.List;
28
+import javax.inject.Inject;
29
+
30
+/**
31
+ * Factory for creating {@link Action}s.
32
+ */
33
+public class ActionFactory {
34
+
35
+    /**
36
+     * Creates a new instance of {@link ActionFactory}.
37
+     */
38
+    @Inject
39
+    public ActionFactory() {
40
+    }
41
+
42
+    /**
43
+     * Creates a new instance of Action. The group and name specified must
44
+     * be the group and name of a valid action already saved to disk.
45
+     *
46
+     * @param group The group the action belongs to
47
+     * @param name The name of the action
48
+     */
49
+    public Action create(final String group, final String name) {
50
+        return new Action(group, name);
51
+    }
52
+
53
+    /**
54
+     * Creates a new instance of Action with the specified properties and saves
55
+     * it to disk.
56
+     *
57
+     * @param group The group the action belongs to
58
+     * @param name The name of the action
59
+     * @param triggers The triggers to use
60
+     * @param response The response to use
61
+     * @param conditions The conditions to use
62
+     * @param newFormat The new formatter to use
63
+     */
64
+    public Action create(final String group, final String name,
65
+            final ActionType[] triggers, final String[] response,
66
+            final List<ActionCondition> conditions, final String newFormat) {
67
+        return new Action(group, name, triggers, response, conditions, newFormat);
68
+    }
69
+
70
+    /**
71
+     * Creates a new instance of Action with the specified properties and saves
72
+     * it to disk.
73
+     *
74
+     * @param group The group the action belongs to
75
+     * @param name The name of the action
76
+     * @param triggers The triggers to use
77
+     * @param response The response to use
78
+     * @param conditions The conditions to use
79
+     * @param conditionTree The condition tree to use
80
+     * @param newFormat The new formatter to use
81
+     */
82
+    public Action create(final String group, final String name,
83
+            final ActionType[] triggers, final String[] response,
84
+            final List<ActionCondition> conditions,
85
+            final ConditionTree conditionTree, final String newFormat) {
86
+        return new Action(group, name, triggers, response, conditions, conditionTree, newFormat);
87
+    }
88
+
89
+}

+ 5
- 0
src/com/dmdirc/plugins/PluginInjectorInitialiser.java Bestand weergeven

@@ -24,6 +24,7 @@ package com.dmdirc.plugins;
24 24
 
25 25
 import com.dmdirc.CorePluginExtractor;
26 26
 import com.dmdirc.ServerManager;
27
+import com.dmdirc.actions.ActionFactory;
27 28
 import com.dmdirc.actions.ActionManager;
28 29
 import com.dmdirc.actions.wrappers.PerformWrapper;
29 30
 import com.dmdirc.commandparser.CommandManager;
@@ -46,6 +47,7 @@ import javax.inject.Inject;
46 47
 public class PluginInjectorInitialiser {
47 48
 
48 49
     private final ActionManager actionManager;
50
+    private final ActionFactory actionFactory;
49 51
     private final PluginManager pluginManager;
50 52
     private final IdentityManager identityManager;
51 53
     private final ServerManager serverManager;
@@ -65,6 +67,7 @@ public class PluginInjectorInitialiser {
65 67
     @Inject
66 68
     public PluginInjectorInitialiser(
67 69
             final ActionManager actionManager,
70
+            final ActionFactory actionFactory,
68 71
             final PluginManager pluginManager,
69 72
             final IdentityManager identityManager,
70 73
             final ServerManager serverManager,
@@ -77,6 +80,7 @@ public class PluginInjectorInitialiser {
77 80
             final LifecycleController lifecycleController,
78 81
             final CorePluginExtractor corePluginExtractor) {
79 82
         this.actionManager = actionManager;
83
+        this.actionFactory = actionFactory;
80 84
         this.pluginManager = pluginManager;
81 85
         this.identityManager = identityManager;
82 86
         this.serverManager = serverManager;
@@ -108,5 +112,6 @@ public class PluginInjectorInitialiser {
108 112
         injector.addParameter(PerformWrapper.class, performWrapper);
109 113
         injector.addParameter(LifecycleController.class, lifecycleController);
110 114
         injector.addParameter(corePluginExtractor);
115
+        injector.addParameter(actionFactory);
111 116
     }
112 117
 }

Laden…
Annuleren
Opslaan