Explorar el Código

Merge pull request #710 from csmith/config-iface

More interface/API work.
pull/712/head
Greg Holmes hace 7 años
padre
commit
c7a7c40b3f

src/main/java/com/dmdirc/config/BasicInvocation.java → api/src/main/java/com/dmdirc/config/BasicInvocation.java Ver fichero


+ 57
- 0
api/src/main/java/com/dmdirc/config/ConfigBinder.java Ver fichero

@@ -0,0 +1,57 @@
1
+/*
2
+ * Copyright (c) 2006-2015 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.config;
24
+
25
+import javax.annotation.Nonnull;
26
+
27
+/**
28
+ * Facilitates automatically binding fields or methods annotated with a {@link ConfigBinding}
29
+ * element to a configuration value.
30
+ */
31
+public interface ConfigBinder {
32
+
33
+    /**
34
+     * Binds all annotated methods and fields of the given instance to this binder's configuration
35
+     * manager.
36
+     *
37
+     * @param instance The instance to be bound
38
+     * @param clazz    The class to read bindings from
39
+     */
40
+    void bind(final Object instance, final Class<?> clazz);
41
+
42
+    /**
43
+     * Unbinds all elements of the given instance that have been bound using this ConfigBinder.
44
+     *
45
+     * @param instance The instance to be unbound
46
+     */
47
+    void unbind(final Object instance);
48
+
49
+    /**
50
+     * Returns a new config binder with the specified default domain.
51
+     *
52
+     * @param domain The default domain to use if one is not specified
53
+     * @return A config binder with the specified default domain.
54
+     */
55
+    ConfigBinder withDefaultDomain(@Nonnull final String domain);
56
+
57
+}

src/main/java/com/dmdirc/config/ConfigBinding.java → api/src/main/java/com/dmdirc/config/ConfigBinding.java Ver fichero


src/main/java/com/dmdirc/config/Invocation.java → api/src/main/java/com/dmdirc/config/Invocation.java Ver fichero


src/main/java/com/dmdirc/interfaces/config/AggregateConfigProvider.java → api/src/main/java/com/dmdirc/interfaces/config/AggregateConfigProvider.java Ver fichero


src/main/java/com/dmdirc/interfaces/config/ConfigProviderMigrator.java → api/src/main/java/com/dmdirc/interfaces/config/ConfigProviderMigrator.java Ver fichero


src/main/java/com/dmdirc/config/ConfigBinder.java → src/main/java/com/dmdirc/config/ConfigBinderImpl.java Ver fichero

@@ -1,25 +1,3 @@
1
-/*
2
- * Copyright (c) 2006-2015 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 1
 package com.dmdirc.config;
24 2
 
25 3
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
@@ -47,7 +25,7 @@ import static com.dmdirc.util.LogUtils.APP_ERROR;
47 25
  * Facilitates automatically binding fields or methods annotated with a {@link ConfigBinding}
48 26
  * element to a configuration value.
49 27
  */
50
-public class ConfigBinder {
28
+class ConfigBinderImpl implements ConfigBinder {
51 29
 
52 30
     private static final Logger LOG = LoggerFactory.getLogger(ConfigBinder.class);
53 31
 
@@ -60,25 +38,19 @@ public class ConfigBinder {
60 38
     /** Retriever to use to get typed config values. */
61 39
     private final ConfigValueRetriever valueRetriever;
62 40
 
63
-    ConfigBinder(final AggregateConfigProvider manager) {
41
+    ConfigBinderImpl(final AggregateConfigProvider manager) {
64 42
         this.manager = manager;
65 43
         this.valueRetriever = new ConfigValueRetriever(manager);
66 44
         this.defaultDomain = Optional.empty();
67 45
     }
68 46
 
69
-    ConfigBinder(final AggregateConfigProvider manager, @Nonnull final String domain) {
47
+    ConfigBinderImpl(final AggregateConfigProvider manager, @Nonnull final String domain) {
70 48
         this.manager = manager;
71 49
         this.valueRetriever = new ConfigValueRetriever(manager);
72 50
         this.defaultDomain = Optional.of(domain);
73 51
     }
74 52
 
75
-    /**
76
-     * Binds all annotated methods and fields of the given instance to this binder's configuration
77
-     * manager.
78
-     *
79
-     * @param instance The instance to be bound
80
-     * @param clazz    The class to read bindings from
81
-     */
53
+    @Override
82 54
     public void bind(final Object instance, final Class<?> clazz) {
83 55
         final Collection<ConfigChangeListener> newListeners = new ArrayList<>();
84 56
         final Collection<AccessibleObject> elements = new ArrayList<>();
@@ -191,11 +163,7 @@ public class ConfigBinder {
191 163
         }
192 164
     }
193 165
 
194
-    /**
195
-     * Unbinds all elements of the given instance that have been bound using this ConfigBinder.
196
-     *
197
-     * @param instance The instance to be unbound
198
-     */
166
+    @Override
199 167
     public void unbind(final Object instance) {
200 168
         synchronized (listeners) {
201 169
             listeners.get(instance).forEach(manager::removeListener);
@@ -203,14 +171,9 @@ public class ConfigBinder {
203 171
         }
204 172
     }
205 173
 
206
-    /**
207
-     * Returns a new config binder with the specified default domain.
208
-     *
209
-     * @param domain The default domain to use if one is not specified
210
-     * @return A config binder with the specified default domain.
211
-     */
174
+    @Override
212 175
     public ConfigBinder withDefaultDomain(@Nonnull final String domain) {
213
-        return new ConfigBinder(manager, domain);
176
+        return new ConfigBinderImpl(manager, domain);
214 177
     }
215 178
 
216 179
 }

+ 1
- 1
src/main/java/com/dmdirc/config/ConfigManager.java Ver fichero

@@ -123,7 +123,7 @@ class ConfigManager implements ConfigChangeListener, ConfigProviderListener,
123 123
         this.server = server;
124 124
         this.channel = chanName;
125 125
 
126
-        binder = new ConfigBinder(this);
126
+        binder = new ConfigBinderImpl(this);
127 127
     }
128 128
 
129 129
     @Override

src/test/java/com/dmdirc/config/ConfigBinderTest.java → src/test/java/com/dmdirc/config/ConfigBinderImplTest.java Ver fichero

@@ -37,14 +37,14 @@ import static org.mockito.Matchers.eq;
37 37
 import static org.mockito.Mockito.when;
38 38
 
39 39
 @RunWith(MockitoJUnitRunner.class)
40
-public class ConfigBinderTest {
40
+public class ConfigBinderImplTest {
41 41
 
42 42
     @Mock private AggregateConfigProvider configProvider;
43 43
     private ConfigBinder binder;
44 44
 
45 45
     @Before
46 46
     public void setup() {
47
-        binder = new ConfigBinder(configProvider);
47
+        binder = new ConfigBinderImpl(configProvider);
48 48
     }
49 49
 
50 50
     @Test

Loading…
Cancelar
Guardar