Browse Source

Rename some config classes.

Change-Id: Ieaa7897a5e0bf1168e5c2b4405585558e108ee52
Reviewed-on: http://gerrit.dmdirc.com/2781
Reviewed-by: Greg Holmes <greg@dmdirc.com>
Automatic-Compile: DMDirc Build Manager
tags/0.8rc1
Chris Smith 10 years ago
parent
commit
0b69247ea1

src/com/dmdirc/config/ConfigSource.java → src/com/dmdirc/config/BaseConfigProvider.java View File

40
 import javax.inject.Provider;
40
 import javax.inject.Provider;
41
 
41
 
42
 /**
42
 /**
43
- * Defines methods to get options from a config source in various forms.
44
- * <p>
45
- * This implementation supports the idea of optional/disabled settings.
43
+ * Defines methods to get options from a config provider in various forms.
44
+ *
45
+ * <p>This implementation supports the idea of optional/disabled settings.
46
  * This is where values may be prefixed with the strings <code>true:</code>
46
  * This is where values may be prefixed with the strings <code>true:</code>
47
  * or <code>false:</code>, where the former has no effect on the value of
47
  * or <code>false:</code>, where the former has no effect on the value of
48
  * the setting, and the latter indicates that the user wishes to disable
48
  * the setting, and the latter indicates that the user wishes to disable
49
  * the setting.
49
  * the setting.
50
- * <p>
51
- * Disabled settings allow for optional settings to have default values; a
50
+ *
51
+ * <p>Disabled settings allow for optional settings to have default values; a
52
  * value can be added with the <code>false:</code> prefix which effectively
52
  * value can be added with the <code>false:</code> prefix which effectively
53
  * disables the default value and makes the setting act as though it does not
53
  * disables the default value and makes the setting act as though it does not
54
  * have a value. Note that for this sort of behaviour to make sense, it requires
54
  * have a value. Note that for this sort of behaviour to make sense, it requires
55
  * an implementation that takes values from multiple sources, such as a
55
  * an implementation that takes values from multiple sources, such as a
56
  * {@link ConfigManager}.
56
  * {@link ConfigManager}.
57
  */
57
  */
58
-public abstract class ConfigSource implements ReadOnlyConfigProvider {
58
+public abstract class BaseConfigProvider implements ReadOnlyConfigProvider {
59
 
59
 
60
     /** A permissive validator to use when callers don't specify one. */
60
     /** A permissive validator to use when callers don't specify one. */
61
     private static final Validator<String> PERMISSIVE_VALIDATOR
61
     private static final Validator<String> PERMISSIVE_VALIDATOR
77
      *
77
      *
78
      * @param colourManager The colour manager to use to convert colours.
78
      * @param colourManager The colour manager to use to convert colours.
79
      */
79
      */
80
-    public ConfigSource(final Provider<ColourManager> colourManager) {
80
+    public BaseConfigProvider(final Provider<ColourManager> colourManager) {
81
         this.colourManager = colourManager;
81
         this.colourManager = colourManager;
82
     }
82
     }
83
 
83
 
88
      * @deprecated Should pass in a {@link ColourManager}.
88
      * @deprecated Should pass in a {@link ColourManager}.
89
      */
89
      */
90
     @Deprecated
90
     @Deprecated
91
-    public ConfigSource() {
91
+    public BaseConfigProvider() {
92
         this(ColourManager.getColourManagerProvider());
92
         this(ColourManager.getColourManagerProvider());
93
     }
93
     }
94
 
94
 

src/com/dmdirc/config/Identity.java → src/com/dmdirc/config/ConfigFileBackedConfigProvider.java View File

45
 import lombok.extern.slf4j.Slf4j;
45
 import lombok.extern.slf4j.Slf4j;
46
 
46
 
47
 /**
47
 /**
48
- * An identity is a group of settings that are applied to a connection, server,
49
- * network or channel. Identities may be automatically applied in certain
50
- * cases, or the user may manually apply them.
51
- * <p>
52
- * Note: this class has a natural ordering that is inconsistent with equals.
48
+ * Provides configuration settings from a {@link ConfigFile}.
53
  */
49
  */
54
 @Slf4j
50
 @Slf4j
55
-public class Identity extends ConfigSource implements ConfigProvider {
51
+public class ConfigFileBackedConfigProvider extends BaseConfigProvider implements ConfigProvider {
56
 
52
 
57
     /** The domain used for identity settings. */
53
     /** The domain used for identity settings. */
58
     private static final String DOMAIN = "identity";
54
     private static final String DOMAIN = "identity";
84
      * @throws InvalidIdentityFileException Missing required properties
80
      * @throws InvalidIdentityFileException Missing required properties
85
      * @throws IOException Input/output exception
81
      * @throws IOException Input/output exception
86
      */
82
      */
87
-    public Identity(final File file, final boolean forceDefault) throws IOException,
83
+    public ConfigFileBackedConfigProvider(final File file, final boolean forceDefault) throws IOException,
88
             InvalidIdentityFileException {
84
             InvalidIdentityFileException {
89
         super();
85
         super();
90
 
86
 
107
      * @throws InvalidIdentityFileException Missing required properties
103
      * @throws InvalidIdentityFileException Missing required properties
108
      * @throws IOException Input/output exception
104
      * @throws IOException Input/output exception
109
      */
105
      */
110
-    public Identity(final InputStream stream, final boolean forceDefault) throws IOException,
106
+    public ConfigFileBackedConfigProvider(final InputStream stream, final boolean forceDefault) throws IOException,
111
             InvalidIdentityFileException {
107
             InvalidIdentityFileException {
112
         super();
108
         super();
113
 
109
 
127
      * @param configFile The config file to use
123
      * @param configFile The config file to use
128
      * @param target The target of this identity
124
      * @param target The target of this identity
129
      */
125
      */
130
-    public Identity(final ConfigFile configFile, final ConfigTarget target) {
126
+    public ConfigFileBackedConfigProvider(final ConfigFile configFile, final ConfigTarget target) {
131
         super();
127
         super();
132
 
128
 
133
         this.file = configFile;
129
         this.file = configFile;
546
     /** {@inheritDoc} */
542
     /** {@inheritDoc} */
547
     @Override
543
     @Override
548
     public boolean equals(final Object obj) {
544
     public boolean equals(final Object obj) {
549
-        return obj instanceof Identity
550
-                && getName().equals(((Identity) obj).getName())
551
-                && getTarget() == ((Identity) obj).getTarget();
545
+        return obj instanceof ConfigFileBackedConfigProvider
546
+                && getName().equals(((ConfigFileBackedConfigProvider) obj).getName())
547
+                && getTarget() == ((ConfigFileBackedConfigProvider) obj).getTarget();
552
     }
548
     }
553
 
549
 
554
 }
550
 }

+ 1
- 1
src/com/dmdirc/config/ConfigManager.java View File

46
  */
46
  */
47
 @Slf4j
47
 @Slf4j
48
 @SuppressWarnings("PMD.UnusedPrivateField")
48
 @SuppressWarnings("PMD.UnusedPrivateField")
49
-public class ConfigManager extends ConfigSource implements ConfigChangeListener,
49
+public class ConfigManager extends BaseConfigProvider implements ConfigChangeListener,
50
         ConfigProviderListener, AggregateConfigProvider {
50
         ConfigProviderListener, AggregateConfigProvider {
51
 
51
 
52
     /** Temporary map for lookup stats. */
52
     /** Temporary map for lookup stats. */

+ 7
- 7
src/com/dmdirc/config/IdentityManager.java View File

143
         addonSettings.put("name", "Addon defaults");
143
         addonSettings.put("name", "Addon defaults");
144
         addonConfigFile.addDomain("identity", addonSettings);
144
         addonConfigFile.addDomain("identity", addonSettings);
145
 
145
 
146
-        addonConfig = new Identity(addonConfigFile, target);
146
+        addonConfig = new ConfigFileBackedConfigProvider(addonConfigFile, target);
147
         addConfigProvider(addonConfig);
147
         addConfigProvider(addonConfig);
148
 
148
 
149
         if (!getGlobalConfiguration().hasOptionString("identity", "defaultsversion")) {
149
         if (!getGlobalConfiguration().hasOptionString("identity", "defaultsversion")) {
294
     private void loadIdentity(final File file) {
294
     private void loadIdentity(final File file) {
295
         synchronized (identities) {
295
         synchronized (identities) {
296
             for (ConfigProvider identity : getAllIdentities()) {
296
             for (ConfigProvider identity : getAllIdentities()) {
297
-                if ((identity instanceof Identity) && ((Identity) identity).isFile(file)) {
297
+                if ((identity instanceof ConfigFileBackedConfigProvider) && ((ConfigFileBackedConfigProvider) identity).isFile(file)) {
298
                     // TODO: This manager should keep a list of files->identities instead of
298
                     // TODO: This manager should keep a list of files->identities instead of
299
                     //       relying on the identities remembering.
299
                     //       relying on the identities remembering.
300
                     try {
300
                     try {
313
         }
313
         }
314
 
314
 
315
         try {
315
         try {
316
-            addConfigProvider(new Identity(file, false));
316
+            addConfigProvider(new ConfigFileBackedConfigProvider(file, false));
317
         } catch (InvalidIdentityFileException ex) {
317
         } catch (InvalidIdentityFileException ex) {
318
             Logger.userError(ErrorLevel.MEDIUM,
318
             Logger.userError(ErrorLevel.MEDIUM,
319
                     "Invalid identity file: " + file.getAbsolutePath()
319
                     "Invalid identity file: " + file.getAbsolutePath()
359
     @Override
359
     @Override
360
     public void loadVersionIdentity() {
360
     public void loadVersionIdentity() {
361
         try {
361
         try {
362
-            versionConfig = new Identity(IdentityManager.class.getResourceAsStream("/com/dmdirc/version.config"), false);
362
+            versionConfig = new ConfigFileBackedConfigProvider(IdentityManager.class.getResourceAsStream("/com/dmdirc/version.config"), false);
363
             addConfigProvider(versionConfig);
363
             addConfigProvider(versionConfig);
364
         } catch (IOException | InvalidIdentityFileException ex) {
364
         } catch (IOException | InvalidIdentityFileException ex) {
365
             Logger.appError(ErrorLevel.FATAL, "Unable to load version information", ex);
365
             Logger.appError(ErrorLevel.FATAL, "Unable to load version information", ex);
380
                 file.createNewFile();
380
                 file.createNewFile();
381
             }
381
             }
382
 
382
 
383
-            config = new Identity(file, true);
383
+            config = new ConfigFileBackedConfigProvider(file, true);
384
             config.setOption("identity", "name", "Global config");
384
             config.setOption("identity", "name", "Global config");
385
             addConfigProvider(config);
385
             addConfigProvider(config);
386
         } catch (IOException ex) {
386
         } catch (IOException ex) {
670
      * @throws InvalidIdentityFileException If the settings are invalid
670
      * @throws InvalidIdentityFileException If the settings are invalid
671
      * @since 0.6.3m1
671
      * @since 0.6.3m1
672
      */
672
      */
673
-    protected Identity createIdentity(final Map<String, Map<String, String>> settings)
673
+    protected ConfigFileBackedConfigProvider createIdentity(final Map<String, Map<String, String>> settings)
674
             throws IOException, InvalidIdentityFileException {
674
             throws IOException, InvalidIdentityFileException {
675
         if (!settings.containsKey(IDENTITY_DOMAIN) || !settings.get(IDENTITY_DOMAIN).containsKey("name")
675
         if (!settings.containsKey(IDENTITY_DOMAIN) || !settings.get(IDENTITY_DOMAIN).containsKey("name")
676
                 || settings.get(IDENTITY_DOMAIN).get("name").isEmpty()) {
676
                 || settings.get(IDENTITY_DOMAIN).get("name").isEmpty()) {
697
 
697
 
698
         configFile.write();
698
         configFile.write();
699
 
699
 
700
-        final Identity identity = new Identity(file, false);
700
+        final ConfigFileBackedConfigProvider identity = new ConfigFileBackedConfigProvider(file, false);
701
         addConfigProvider(identity);
701
         addConfigProvider(identity);
702
 
702
 
703
         return identity;
703
         return identity;

+ 2
- 2
src/com/dmdirc/plugins/PluginInfo.java View File

24
 
24
 
25
 import com.dmdirc.actions.ActionManager;
25
 import com.dmdirc.actions.ActionManager;
26
 import com.dmdirc.actions.CoreActionType;
26
 import com.dmdirc.actions.CoreActionType;
27
-import com.dmdirc.config.Identity;
27
+import com.dmdirc.config.ConfigFileBackedConfigProvider;
28
 import com.dmdirc.config.IdentityManager;
28
 import com.dmdirc.config.IdentityManager;
29
 import com.dmdirc.config.InvalidIdentityFileException;
29
 import com.dmdirc.config.InvalidIdentityFileException;
30
 import com.dmdirc.interfaces.config.ConfigProvider;
30
 import com.dmdirc.interfaces.config.ConfigProvider;
243
 
243
 
244
                 synchronized (configProviders) {
244
                 synchronized (configProviders) {
245
                     try {
245
                     try {
246
-                        final ConfigProvider configProvider = new Identity(stream, false);
246
+                        final ConfigProvider configProvider = new ConfigFileBackedConfigProvider(stream, false);
247
                         IdentityManager.getIdentityManager().addConfigProvider(configProvider);
247
                         IdentityManager.getIdentityManager().addConfigProvider(configProvider);
248
                         configProviders.add(configProvider);
248
                         configProviders.add(configProvider);
249
                     } catch (final InvalidIdentityFileException ex) {
249
                     } catch (final InvalidIdentityFileException ex) {

+ 2
- 2
src/com/dmdirc/ui/themes/ThemeIdentity.java View File

22
 
22
 
23
 package com.dmdirc.ui.themes;
23
 package com.dmdirc.ui.themes;
24
 
24
 
25
-import com.dmdirc.config.Identity;
25
+import com.dmdirc.config.ConfigFileBackedConfigProvider;
26
 import com.dmdirc.config.InvalidIdentityFileException;
26
 import com.dmdirc.config.InvalidIdentityFileException;
27
 import com.dmdirc.util.validators.Validator;
27
 import com.dmdirc.util.validators.Validator;
28
 
28
 
33
  * An identity that only claims to know about settings under the UI domain,
33
  * An identity that only claims to know about settings under the UI domain,
34
  * for use with themes.
34
  * for use with themes.
35
  */
35
  */
36
-public class ThemeIdentity extends Identity {
36
+public class ThemeIdentity extends ConfigFileBackedConfigProvider {
37
 
37
 
38
     /**
38
     /**
39
      * A version number for this class. It should be changed whenever the class
39
      * A version number for this class. It should be changed whenever the class

+ 6
- 6
test/com/dmdirc/config/IdentityTest.java View File

38
 
38
 
39
 public class IdentityTest {
39
 public class IdentityTest {
40
 
40
 
41
-    private Identity myIdent;
41
+    private ConfigFileBackedConfigProvider myIdent;
42
     private ConfigTarget target;
42
     private ConfigTarget target;
43
 
43
 
44
     @Before
44
     @Before
46
         target = new ConfigTarget();
46
         target = new ConfigTarget();
47
         target.setChannel("#unittest@unittest");
47
         target.setChannel("#unittest@unittest");
48
 
48
 
49
-        myIdent = new Identity(new ConfigFile(getClass().getResourceAsStream("identity2")), target);
49
+        myIdent = new ConfigFileBackedConfigProvider(new ConfigFile(getClass().getResourceAsStream("identity2")), target);
50
     }
50
     }
51
 
51
 
52
     @Test
52
     @Test
134
 
134
 
135
         myIdent.save();
135
         myIdent.save();
136
 
136
 
137
-        myIdent = new Identity(myIdent.file.getFile(), false);
137
+        myIdent = new ConfigFileBackedConfigProvider(myIdent.file.getFile(), false);
138
 
138
 
139
         assertEquals("baz!", myIdent.getOption("foo", "bar"));
139
         assertEquals("baz!", myIdent.getOption("foo", "bar"));
140
     }
140
     }
147
 
147
 
148
     @Test(expected=InvalidIdentityFileException.class)
148
     @Test(expected=InvalidIdentityFileException.class)
149
     public void testNoName() throws IOException, InvalidIdentityFileException {
149
     public void testNoName() throws IOException, InvalidIdentityFileException {
150
-        new Identity(getClass().getResourceAsStream("identity1"), false);
150
+        new ConfigFileBackedConfigProvider(getClass().getResourceAsStream("identity1"), false);
151
     }
151
     }
152
 
152
 
153
     @Test(expected=InvalidIdentityFileException.class)
153
     @Test(expected=InvalidIdentityFileException.class)
154
     public void testNoTarget() throws IOException, InvalidIdentityFileException {
154
     public void testNoTarget() throws IOException, InvalidIdentityFileException {
155
-        new Identity(getClass().getResourceAsStream("identity2"), false);
155
+        new ConfigFileBackedConfigProvider(getClass().getResourceAsStream("identity2"), false);
156
     }
156
     }
157
 
157
 
158
     @Test
158
     @Test
159
     public void testMigrate() throws IOException, InvalidIdentityFileException {
159
     public void testMigrate() throws IOException, InvalidIdentityFileException {
160
-        final Identity id = new Identity(getClass().getResourceAsStream("identity3"), false);
160
+        final ConfigFileBackedConfigProvider id = new ConfigFileBackedConfigProvider(getClass().getResourceAsStream("identity3"), false);
161
 
161
 
162
         assertTrue(id.file.isKeyDomain("identity"));
162
         assertTrue(id.file.isKeyDomain("identity"));
163
         assertTrue(id.file.isKeyDomain("meep"));
163
         assertTrue(id.file.isKeyDomain("meep"));

+ 2
- 2
test/com/dmdirc/harness/TestConfigSource.java View File

22
 
22
 
23
 package com.dmdirc.harness;
23
 package com.dmdirc.harness;
24
 
24
 
25
-import com.dmdirc.config.ConfigSource;
25
+import com.dmdirc.config.BaseConfigProvider;
26
 import com.dmdirc.util.validators.Validator;
26
 import com.dmdirc.util.validators.Validator;
27
 
27
 
28
 import java.util.Map;
28
 import java.util.Map;
29
 
29
 
30
-public class TestConfigSource extends ConfigSource {
30
+public class TestConfigSource extends BaseConfigProvider {
31
 
31
 
32
     @Override
32
     @Override
33
     public boolean hasOption(String domain, String option, Validator<String> validator) {
33
     public boolean hasOption(String domain, String option, Validator<String> validator) {

Loading…
Cancel
Save