Add SubsystemConfiguration interface

This commit is contained in:
JeremyStar™ 2024-06-10 18:36:12 +02:00
parent 7c391ecf8d
commit 5d16c3b862
Signed by: JeremyStarTM
GPG key ID: E366BAEF67E4704D
2 changed files with 84 additions and 52 deletions

View file

@ -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}.<br/>
* 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) {

View file

@ -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}.<br/>
* 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);
}