forked from StarOpenSource/Engine
Add SubsystemConfiguration interface
This commit is contained in:
parent
7c391ecf8d
commit
5d16c3b862
2 changed files with 84 additions and 52 deletions
|
@ -19,6 +19,7 @@
|
||||||
|
|
||||||
package de.staropensource.sosengine.base;
|
package de.staropensource.sosengine.base;
|
||||||
|
|
||||||
|
import de.staropensource.sosengine.base.classes.SubsystemConfiguration;
|
||||||
import de.staropensource.sosengine.base.logging.Logger;
|
import de.staropensource.sosengine.base.logging.Logger;
|
||||||
import de.staropensource.sosengine.base.types.CodePart;
|
import de.staropensource.sosengine.base.types.CodePart;
|
||||||
import de.staropensource.sosengine.base.types.LogIssuer;
|
import de.staropensource.sosengine.base.types.LogIssuer;
|
||||||
|
@ -37,32 +38,12 @@ import java.util.Properties;
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings({ "unused", "JavadocDeclaration", "JavadocBlankLines" })
|
@SuppressWarnings({ "unused", "JavadocDeclaration", "JavadocBlankLines" })
|
||||||
@Getter
|
@Getter
|
||||||
public final class EngineConfiguration {
|
public final class EngineConfiguration implements SubsystemConfiguration {
|
||||||
/**
|
/** {@inheritDoc} */
|
||||||
* Instance.
|
|
||||||
*
|
|
||||||
* @since 1-alpha0
|
|
||||||
*
|
|
||||||
* -- GETTER --
|
|
||||||
* Returns the {@link EngineConfiguration} instance.
|
|
||||||
*
|
|
||||||
* @return {@link EngineConfiguration} instance
|
|
||||||
* @since 1-alpha0
|
|
||||||
*/
|
|
||||||
@Getter
|
@Getter
|
||||||
private static EngineConfiguration instance;
|
private static EngineConfiguration instance;
|
||||||
|
|
||||||
/**
|
/** {@inheritDoc} */
|
||||||
* 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
|
|
||||||
*/
|
|
||||||
@Getter
|
@Getter
|
||||||
private static final String group = "sosengine.base.";
|
private static final String group = "sosengine.base.";
|
||||||
|
|
||||||
|
@ -191,20 +172,13 @@ public final class EngineConfiguration {
|
||||||
loadDefaultConfiguration();
|
loadDefaultConfiguration();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** {@inheritDoc} */
|
||||||
* 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
|
|
||||||
*/
|
|
||||||
public void loadConfiguration(Properties properties) {
|
public void loadConfiguration(Properties properties) {
|
||||||
// Define variables
|
// Define variables
|
||||||
PropertyParser parser = new PropertyParser(properties);
|
PropertyParser parser = new PropertyParser(properties);
|
||||||
|
|
||||||
for (String property : properties.stringPropertyNames()) {
|
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;
|
if (!property.startsWith(group)) continue;
|
||||||
|
|
||||||
// Skip to important stuff
|
// Skip to important stuff
|
||||||
|
@ -238,24 +212,12 @@ public final class EngineConfiguration {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** {@inheritDoc} */
|
||||||
* Loads the engine configuration from the system properties.
|
|
||||||
*
|
|
||||||
* @see EngineConfiguration#loadConfiguration(Properties)
|
|
||||||
* @see System#getProperties()
|
|
||||||
* @since 1-alpha0
|
|
||||||
*/
|
|
||||||
public void loadConfiguration() {
|
public void loadConfiguration() {
|
||||||
loadConfiguration(System.getProperties());
|
loadConfiguration(System.getProperties());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** {@inheritDoc} */
|
||||||
* Loads the default engine configuration.
|
|
||||||
*
|
|
||||||
* @see EngineConfiguration#loadConfiguration()
|
|
||||||
* @see EngineConfiguration#loadConfiguration(Properties)
|
|
||||||
* @since 1-alpha0
|
|
||||||
*/
|
|
||||||
public void loadDefaultConfiguration() {
|
public void loadDefaultConfiguration() {
|
||||||
debug = false;
|
debug = false;
|
||||||
debugShortcodeConverter = false;
|
debugShortcodeConverter = false;
|
||||||
|
@ -268,12 +230,7 @@ public final class EngineConfiguration {
|
||||||
loggerForceStandardOutput = false;
|
loggerForceStandardOutput = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** {@inheritDoc} */
|
||||||
* Returns a configuration setting.
|
|
||||||
*
|
|
||||||
* @param setting the setting name
|
|
||||||
* @return the setting's value or {@code null} if not found
|
|
||||||
*/
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public Object getSetting(@NotNull String setting) {
|
public Object getSetting(@NotNull String setting) {
|
||||||
switch (setting) {
|
switch (setting) {
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
Loading…
Reference in a new issue