From 5d16c3b86243d3b0d2db48d26e0713ea94dfdf56 Mon Sep 17 00:00:00 2001 From: JeremyStarTM Date: Mon, 10 Jun 2024 18:36:12 +0200 Subject: [PATCH] Add SubsystemConfiguration interface --- .../sosengine/base/EngineConfiguration.java | 61 +++------------ .../base/classes/SubsystemConfiguration.java | 75 +++++++++++++++++++ 2 files changed, 84 insertions(+), 52 deletions(-) create mode 100644 base/src/main/java/de/staropensource/sosengine/base/classes/SubsystemConfiguration.java diff --git a/base/src/main/java/de/staropensource/sosengine/base/EngineConfiguration.java b/base/src/main/java/de/staropensource/sosengine/base/EngineConfiguration.java index 767983c5..3c9b78a3 100644 --- a/base/src/main/java/de/staropensource/sosengine/base/EngineConfiguration.java +++ b/base/src/main/java/de/staropensource/sosengine/base/EngineConfiguration.java @@ -19,6 +19,7 @@ package de.staropensource.sosengine.base; +import de.staropensource.sosengine.base.classes.SubsystemConfiguration; import de.staropensource.sosengine.base.logging.Logger; import de.staropensource.sosengine.base.types.CodePart; import de.staropensource.sosengine.base.types.LogIssuer; @@ -37,32 +38,12 @@ import java.util.Properties; */ @SuppressWarnings({ "unused", "JavadocDeclaration", "JavadocBlankLines" }) @Getter -public final class EngineConfiguration { - /** - * Instance. - * - * @since 1-alpha0 - * - * -- GETTER -- - * Returns the {@link EngineConfiguration} instance. - * - * @return {@link EngineConfiguration} instance - * @since 1-alpha0 - */ +public final class EngineConfiguration implements SubsystemConfiguration { + /** {@inheritDoc} */ @Getter private static EngineConfiguration instance; - /** - * Defines the group every property must start with to be recognized as an engine configuration setting. - * - * @since 1-alpha0 - * - * -- GETTER -- - * Returns the group every property must start with to be recognized as an engine configuration setting. - * - * @return the property group - * @since 1-alpha0 - */ + /** {@inheritDoc} */ @Getter private static final String group = "sosengine.base."; @@ -191,20 +172,13 @@ public final class EngineConfiguration { loadDefaultConfiguration(); } - /** - * Loads the engine configuration from the specified {@link java.util.Properties}.
- * Unless you want to allow configuration overriding, resetting the configuration using {@code loadDefaultConfiguration()} is advised. - * - * @param properties the {@link Properties} object - * @see EngineConfiguration#loadDefaultConfiguration() - * @since 1-alpha0 - */ + /** {@inheritDoc} */ public void loadConfiguration(Properties properties) { // Define variables PropertyParser parser = new PropertyParser(properties); for (String property : properties.stringPropertyNames()) { - // Check if property name starts with "de.staropensource.sosengine.base." + // Check if property name starts with group if (!property.startsWith(group)) continue; // Skip to important stuff @@ -238,24 +212,12 @@ public final class EngineConfiguration { } } - /** - * Loads the engine configuration from the system properties. - * - * @see EngineConfiguration#loadConfiguration(Properties) - * @see System#getProperties() - * @since 1-alpha0 - */ + /** {@inheritDoc} */ public void loadConfiguration() { loadConfiguration(System.getProperties()); } - /** - * Loads the default engine configuration. - * - * @see EngineConfiguration#loadConfiguration() - * @see EngineConfiguration#loadConfiguration(Properties) - * @since 1-alpha0 - */ + /** {@inheritDoc} */ public void loadDefaultConfiguration() { debug = false; debugShortcodeConverter = false; @@ -268,12 +230,7 @@ public final class EngineConfiguration { loggerForceStandardOutput = false; } - /** - * Returns a configuration setting. - * - * @param setting the setting name - * @return the setting's value or {@code null} if not found - */ + /** {@inheritDoc} */ @Nullable public Object getSetting(@NotNull String setting) { switch (setting) { diff --git a/base/src/main/java/de/staropensource/sosengine/base/classes/SubsystemConfiguration.java b/base/src/main/java/de/staropensource/sosengine/base/classes/SubsystemConfiguration.java new file mode 100644 index 00000000..d1aac4d9 --- /dev/null +++ b/base/src/main/java/de/staropensource/sosengine/base/classes/SubsystemConfiguration.java @@ -0,0 +1,75 @@ +package de.staropensource.sosengine.base.classes; + +import org.jetbrains.annotations.NotNull; + +import java.util.Properties; + +/** + * Base class for subsystem configurations. + * + * @since 1-alpha0 + */ +@SuppressWarnings({ "unused", "JavadocDeclaration", "JavadocBlankLines" }) +public interface SubsystemConfiguration { + /** + * Instance. + * + * @since 1-alpha0 + * + * -- GETTER -- + * Returns the {@link SubsystemConfiguration}-extending instance. + * + * @return {@link SubsystemConfiguration}-extending instance + * @since 1-alpha0 + */ + SubsystemConfiguration instance = null; + + /** + * Defines the group every property must start with to be recognized as a subsystem configuration setting. + * + * @since 1-alpha0 + * + * -- GETTER -- + * Returns the group every property must start with to be recognized as a subsystem configuration setting. + * + * @return the property group + * @since 1-alpha0 + */ + String group = "sosengine."; + + /** + * Loads the subsystem configuration from the specified {@link Properties}.
+ * Unless you want to allow configuration overriding, resetting the configuration using {@code loadDefaultConfiguration()} is advised. + * + * @param properties the {@link Properties} object + * @see SubsystemConfiguration#loadDefaultConfiguration() + * @since 1-alpha0 + */ + void loadConfiguration(Properties properties); + + /** + * Loads the subsystem configuration from the system properties. + * + * @see SubsystemConfiguration#loadConfiguration(Properties) + * @see System#getProperties() + * @since 1-alpha0 + */ + void loadConfiguration(); + + /** + * Loads the default subsystem configuration. + * + * @see SubsystemConfiguration#loadConfiguration() + * @see SubsystemConfiguration#loadConfiguration(Properties) + * @since 1-alpha0 + */ + void loadDefaultConfiguration(); + + /** + * Returns a configuration setting. + * + * @param setting the setting name + * @return the setting's value or {@code null} if not found + */ + Object getSetting(@NotNull String setting); +}