|
@@ -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
|
}
|