org.refcodes.properties.ext.runtime.RuntimePropertiesImpl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of refcodes-properties-ext-runtime Show documentation
Show all versions of refcodes-properties-ext-runtime Show documentation
Artifact for providing predefined configuration compositions common for
everyday application setups.
// /////////////////////////////////////////////////////////////////////////////
// REFCODES.ORG
// /////////////////////////////////////////////////////////////////////////////
// This code is copyright (c) by Siegfried Steiner, Munich, Germany and licensed
// under the following (see "http://en.wikipedia.org/wiki/Multi-licensing")
// licenses:
// -----------------------------------------------------------------------------
// GNU General Public License, v3.0 ("http://www.gnu.org/licenses/gpl-3.0.html")
// -----------------------------------------------------------------------------
// Apache License, v2.0 ("http://www.apache.org/licenses/TEXT-2.0")
// -----------------------------------------------------------------------------
// Please contact the copyright holding author(s) of the software artifacts in
// question for licensing issues not being covered by the above listed licenses,
// also regarding commercial licensing models or regarding the compatibility
// with other open source licenses.
// /////////////////////////////////////////////////////////////////////////////
package org.refcodes.properties.ext.runtime;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintStream;
import java.net.URL;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Set;
import org.refcodes.cli.AmbiguousArgsException;
import org.refcodes.cli.ArgsSyntax;
import org.refcodes.cli.Example;
import org.refcodes.cli.Operand;
import org.refcodes.cli.Option;
import org.refcodes.cli.OptionCondition;
import org.refcodes.cli.ParseArgsException;
import org.refcodes.cli.SuperfluousArgsException;
import org.refcodes.cli.SyntaxNotation;
import org.refcodes.cli.UnknownArgsException;
import org.refcodes.exception.BugException;
import org.refcodes.properties.AbstractPropertiesDecorator;
import org.refcodes.properties.EnvironmentProperties;
import org.refcodes.properties.PolyglotPropertiesBuilder.PolyglotPropertiesBuilderFactory;
import org.refcodes.properties.ProfilePropertiesProjection;
import org.refcodes.properties.Properties;
import org.refcodes.properties.PropertiesBuilderImpl;
import org.refcodes.properties.PropertiesPrecedence.PropertiesPrecedenceBuilder;
import org.refcodes.properties.PropertiesPrecedenceBuilderComposite;
import org.refcodes.properties.PropertiesPrecedenceComposite;
import org.refcodes.properties.ReloadMode;
import org.refcodes.properties.ResourceProperties;
import org.refcodes.properties.SystemProperties;
import org.refcodes.properties.ext.cli.ArgsParserProperties;
import org.refcodes.properties.ext.cli.ArgsParserPropertiesImpl;
import org.refcodes.properties.ext.obfuscation.ObfuscationProperties;
import org.refcodes.properties.ext.obfuscation.ObfuscationProperties.ObfuscationPropertiesBuilder;
import org.refcodes.properties.ext.obfuscation.ObfuscationPropertiesDecorator;
import org.refcodes.properties.ext.obfuscation.ObfuscationResourceProperties.ObfuscationResourcePropertiesBuilder;
import org.refcodes.properties.ext.obfuscation.ObfuscationResourcePropertiesBuilderDecorator;
import org.refcodes.runtime.ConfigLocator;
import org.refcodes.runtime.SystemContext;
import org.refcodes.security.DecryptionException;
import org.refcodes.security.EncryptionException;
import org.refcodes.security.alt.chaos.ChaosKey;
import org.refcodes.security.alt.chaos.ChaosTextDecrypter;
import org.refcodes.security.alt.chaos.ChaosTextEncrypter;
import org.refcodes.textual.Font;
import org.refcodes.textual.TextBoxGrid;
/**
* The {@link RuntimePropertiesImpl} composite represent command line
* properties, system properties as well as environment variables (in that
* order) and resource properties. The {@link RuntimePropertiesImpl} are
* actually constructed from {@link ArgsParserProperties},
* {@link SystemProperties}, {@link EnvironmentProperties} and
* {@link ResourceProperties} instances (in that precedence). Add the
* {@link ResourceProperties} via the following methods {@link #withFile(File)},
* {@link #withFilePath(String)}, {@link #withUrl(URL)} or
* {@link #withInputStream(InputStream)}. Obfuscation may be applied to the
* properties as of the {@link ObfuscationProperties} and
* {@link ObfuscationPropertiesBuilder} types.
*/
public class RuntimePropertiesImpl extends AbstractPropertiesDecorator implements RuntimeProperties {
// /////////////////////////////////////////////////////////////////////////
// STATICS:
// /////////////////////////////////////////////////////////////////////////
// /////////////////////////////////////////////////////////////////////////
// CONSTANTS:
// /////////////////////////////////////////////////////////////////////////
// /////////////////////////////////////////////////////////////////////////
// VARIABLES:
// /////////////////////////////////////////////////////////////////////////
private SystemProperties _systemProperties = new SystemProperties();
private EnvironmentProperties _environmentProperties = new EnvironmentProperties();
private ArgsParserProperties _argsParserProperties = null;
private List _resourceProperties = new ArrayList<>();
private PropertiesPrecedenceBuilder _propertiesPrecedence = new PropertiesPrecedenceBuilderComposite();
private String _secret;
private boolean _isPostConstructed = false;
private PolyglotPropertiesBuilderFactory _factory;
// /////////////////////////////////////////////////////////////////////////
// CONSTRUCTORS:
// /////////////////////////////////////////////////////////////////////////
/**
* Constructs a {@link RuntimeProperties} instance with no
* {@link ArgsSyntax} for parsing command line arguments. As no syntax
* notation is required by the constructor (no root {@link ArgsSyntax}), no
* syntax validation is done. Therefore the properties are heuristically
* determined from the provided command line arguments when invoking
* {@link #withEvalArgs(String[])}.
*/
public RuntimePropertiesImpl() {
this( new PolyglotPropertiesBuilderFactory() );
}
/**
* Constructs a {@link RuntimeProperties} instance with no
* {@link ArgsSyntax} for parsing command line arguments: As no syntax
* notation is required by the constructor (no root {@link ArgsSyntax}), no
* syntax validation is done. Therefore the properties are heuristically
* determined from the provided command line arguments.
*
* @param aArgs The command line arguments to be evaluated.
*/
public RuntimePropertiesImpl( String[] aArgs ) {
this( new PolyglotPropertiesBuilderFactory(), aArgs );
}
/**
* Constructs a {@link RuntimeProperties} instance with the given
* {@link ArgsSyntax} used to parse command line arguments.
*
* @param aRootArgsSyntax The root condition being the node from which
* parsing the command line arguments starts. Parse the command line
* arguments via {@link #evalArgs(String[])}.
*/
public RuntimePropertiesImpl( ArgsSyntax aRootArgsSyntax ) {
this( new PolyglotPropertiesBuilderFactory(), aRootArgsSyntax );
}
/**
* Constructs a {@link RuntimeProperties} instance with the given
* {@link Option} used to parse command line arguments.
*
* @param aRootOption The root option being the node from which parsing the
* command line arguments starts. Parse the command line arguments
* via {@link #evalArgs(String[])}.
*/
public RuntimePropertiesImpl( Option> aRootOption ) {
this( new PolyglotPropertiesBuilderFactory(), aRootOption );
}
/**
* Constructs the {@link RuntimeProperties} with the given obfuscation mode
*
* @param aObfuscationMode The {@link SystemContext} specifies which level
* of obfuscation is to be used when encountering upon obfuscated
* properties: E.g. obfuscation may be bound to the host, the
* "secret" used for obfuscation being the same for all applications
* on the same host or obfuscation may be bound to the application,
* being different for different applications on the same host.
*/
public RuntimePropertiesImpl( SystemContext aObfuscationMode ) {
this( new PolyglotPropertiesBuilderFactory(), aObfuscationMode );
}
/**
* Constructs a {@link RuntimeProperties} instance with no
* {@link ArgsSyntax} for parsing command line arguments: As no syntax
* notation is required by the constructor (no root {@link ArgsSyntax}), no
* syntax validation is done. Therefore the properties are heuristically
* determined from the provided command line arguments. Also constructs the
* {@link RuntimeProperties} with the given obfuscation mode
*
* @param aArgs The command line arguments to be evaluated.
* @param aObfuscationMode The {@link SystemContext} specifies which level
* of obfuscation is to be used when encountering upon obfuscated
* properties: E.g. obfuscation may be bound to the host, the
* "secret" used for obfuscation being the same for all applications
* on the same host or obfuscation may be bound to the application,
* being different for different applications on the same host.
*/
public RuntimePropertiesImpl( String[] aArgs, SystemContext aObfuscationMode ) {
this( new PolyglotPropertiesBuilderFactory(), aArgs, aObfuscationMode );
}
/**
* Constructs a {@link RuntimeProperties} instance with the given
* {@link ArgsSyntax} used to parse command line arguments. Also constructs
* the {@link RuntimeProperties} with the given obfuscation mode.
*
* @param aRootArgsSyntax The root condition being the node from which
* parsing the command line arguments starts. Parse the command line
* arguments via {@link #evalArgs(String[])}.
* @param aObfuscationMode The {@link SystemContext} specifies which level
* of obfuscation is to be used when encountering upon obfuscated
* properties: E.g. obfuscation may be bound to the host, the
* "secret" used for obfuscation being the same for all applications
* on the same host or obfuscation may be bound to the application,
* being different for different applications on the same host.
*/
public RuntimePropertiesImpl( ArgsSyntax aRootArgsSyntax, SystemContext aObfuscationMode ) {
this( new PolyglotPropertiesBuilderFactory(), aRootArgsSyntax, aObfuscationMode );
}
/**
* Constructs a {@link RuntimeProperties} instance with the given
* {@link Option} used to parse command line arguments. Also constructs the
* {@link RuntimeProperties} with the given obfuscation mode.
*
* @param aRootOption The root option being the node from which parsing the
* command line arguments starts. Parse the command line arguments
* via {@link #evalArgs(String[])}.
* @param aObfuscationMode The {@link SystemContext} specifies which level
* of obfuscation is to be used when encountering upon obfuscated
* properties: E.g. obfuscation may be bound to the host, the
* "secret" used for obfuscation being the same for all applications
* on the same host or obfuscation may be bound to the application,
* being different for different applications on the same host.
*/
public RuntimePropertiesImpl( Option> aRootOption, SystemContext aObfuscationMode ) {
this( new PolyglotPropertiesBuilderFactory(), aRootOption, aObfuscationMode );
}
/**
* Constructs a {@link RuntimeProperties} instance with a custom secret for
* obfuscation.
*
* @param aSecret The secret to be used when encountering upon obfuscated
* properties.
*/
public RuntimePropertiesImpl( String aSecret ) {
this( new PolyglotPropertiesBuilderFactory(), aSecret );
}
/**
* Constructs a {@link RuntimeProperties} instance with no
* {@link ArgsSyntax} for parsing command line arguments: As no syntax
* notation is required by the constructor (no root {@link ArgsSyntax}), no
* syntax validation is done. Therefore the properties are heuristically
* determined from the provided command line arguments. Also constructs a
* {@link RuntimeProperties} instance with a custom secret for obfuscation.
*
* @param aArgs The command line arguments to be evaluated.
* @param aSecret The secret to be used when encountering upon obfuscated
* properties.
*/
public RuntimePropertiesImpl( String[] aArgs, String aSecret ) {
this( new PolyglotPropertiesBuilderFactory(), aArgs, aSecret );
}
/**
* Constructs a {@link RuntimeProperties} instance with the given
* {@link ArgsSyntax} used to parse command line arguments. Also constructs
* a {@link RuntimeProperties} instance with a custom secret for
* obfuscation.
*
* @param aRootArgsSyntax The root condition being the node from which
* parsing the command line arguments starts. Parse the command line
* arguments via {@link #evalArgs(String[])}.
* @param aSecret The secret to be used when encountering upon obfuscated
* properties.
*/
public RuntimePropertiesImpl( ArgsSyntax aRootArgsSyntax, String aSecret ) {
this( new PolyglotPropertiesBuilderFactory(), aRootArgsSyntax, aSecret );
}
/**
* Constructs a {@link RuntimeProperties} instance with the given
* {@link Option} used to parse command line arguments. Also constructs a
* {@link RuntimeProperties} instance with a custom secret for obfuscation.
*
* @param aRootOption The root option being the node from which parsing the
* command line arguments starts. Parse the command line arguments
* via {@link #evalArgs(String[])}.
* @param aSecret The secret to be used when encountering upon obfuscated
* properties.
*/
public RuntimePropertiesImpl( Option> aRootOption, String aSecret ) {
this( new PolyglotPropertiesBuilderFactory(), aRootOption, aSecret );
}
// -------------------------------------------------------------------------
/**
* Constructs a {@link RuntimeProperties} instance with no
* {@link ArgsSyntax} for parsing command line arguments. As no syntax
* notation is required by the constructor (no root {@link ArgsSyntax}), no
* syntax validation is done. Therefore the properties are heuristically
* determined from the provided command line arguments when invoking
* {@link #withEvalArgs(String[])}.
*
* @param aPropertiesBuilderFactory The factory to use when constructing
* {@link ResourceProperties} instances.
*/
public RuntimePropertiesImpl( PolyglotPropertiesBuilderFactory aPropertiesBuilderFactory ) {
_argsParserProperties = new ArgsParserPropertiesImpl();
_factory = aPropertiesBuilderFactory;
_secret = toEncrypted( SystemContext.HOST.toContextSequence() );
}
/**
* Constructs a {@link RuntimeProperties} instance with no
* {@link ArgsSyntax} for parsing command line arguments: As no syntax
* notation is required by the constructor (no root {@link ArgsSyntax}), no
* syntax validation is done. Therefore the properties are heuristically
* determined from the provided command line arguments.
*
* @param aPropertiesBuilderFactory The factory to use when constructing
* {@link ResourceProperties} instances.
* @param aArgs The command line arguments to be evaluated.
*/
public RuntimePropertiesImpl( PolyglotPropertiesBuilderFactory aPropertiesBuilderFactory, String[] aArgs ) {
_argsParserProperties = new ArgsParserPropertiesImpl( aArgs );
_factory = aPropertiesBuilderFactory;
_secret = toEncrypted( SystemContext.HOST.toContextSequence() );
}
/**
* Constructs a {@link RuntimeProperties} instance with the given
* {@link ArgsSyntax} used to parse command line arguments.
*
* @param aPropertiesBuilderFactory The factory to use when constructing
* {@link ResourceProperties} instances.
* @param aRootOption The root condition being the node from which parsing
* the command line arguments starts. Parse the command line
* arguments via {@link #evalArgs(String[])}.
*/
public RuntimePropertiesImpl( PolyglotPropertiesBuilderFactory aPropertiesBuilderFactory, Option> aRootOption ) {
this( aPropertiesBuilderFactory, new OptionCondition( aRootOption ) );
}
/**
* Constructs a {@link RuntimeProperties} instance with the given
* {@link ArgsSyntax} used to parse command line arguments.
*
* @param aPropertiesBuilderFactory The factory to use when constructing
* {@link ResourceProperties} instances.
* @param aRootArgsSyntax The root condition being the node from which
* parsing the command line arguments starts. Parse the command line
* arguments via {@link #evalArgs(String[])}.
*/
public RuntimePropertiesImpl( PolyglotPropertiesBuilderFactory aPropertiesBuilderFactory, ArgsSyntax aRootArgsSyntax ) {
_argsParserProperties = new ArgsParserPropertiesImpl( aRootArgsSyntax );
_factory = aPropertiesBuilderFactory;
_secret = toEncrypted( SystemContext.HOST.toContextSequence() );
}
/**
* Constructs the {@link RuntimeProperties} with the given obfuscation mode
*
* @param aPropertiesBuilderFactory The factory to use when constructing
* {@link ResourceProperties} instances.
* @param aObfuscationMode The {@link SystemContext} specifies which level
* of obfuscation is to be used when encountering upon obfuscated
* properties: E.g. obfuscation may be bound to the host, the
* "secret" used for obfuscation being the same for all applications
* on the same host or obfuscation may be bound to the application,
* being different for different applications on the same host.
*/
public RuntimePropertiesImpl( PolyglotPropertiesBuilderFactory aPropertiesBuilderFactory, SystemContext aObfuscationMode ) {
_argsParserProperties = new ArgsParserPropertiesImpl();
_secret = toEncrypted( aObfuscationMode.toContextSequence() );
_factory = aPropertiesBuilderFactory;
}
/**
* Constructs a {@link RuntimeProperties} instance with no
* {@link ArgsSyntax} for parsing command line arguments: As no syntax
* notation is required by the constructor (no root {@link ArgsSyntax}), no
* syntax validation is done. Therefore the properties are heuristically
* determined from the provided command line arguments. Also constructs the
* {@link RuntimeProperties} with the given obfuscation mode
*
* @param aPropertiesBuilderFactory The factory to use when constructing
* {@link ResourceProperties} instances.
* @param aArgs The command line arguments to be evaluated.
* @param aObfuscationMode The {@link SystemContext} specifies which level
* of obfuscation is to be used when encountering upon obfuscated
* properties: E.g. obfuscation may be bound to the host, the
* "secret" used for obfuscation being the same for all applications
* on the same host or obfuscation may be bound to the application,
* being different for different applications on the same host.
*/
public RuntimePropertiesImpl( PolyglotPropertiesBuilderFactory aPropertiesBuilderFactory, String[] aArgs, SystemContext aObfuscationMode ) {
_argsParserProperties = new ArgsParserPropertiesImpl( aArgs );
_secret = toEncrypted( aObfuscationMode.toContextSequence() );
_factory = aPropertiesBuilderFactory;
}
/**
* Constructs a {@link RuntimeProperties} instance with the given
* {@link Option} used to parse command line arguments. Also constructs the
* {@link RuntimeProperties} with the given obfuscation mode.
*
* @param aPropertiesBuilderFactory The factory to use when constructing
* {@link ResourceProperties} instances.
* @param aRootOption The root option being the node from which parsing the
* command line arguments starts. Parse the command line arguments
* via {@link #evalArgs(String[])}.
* @param aObfuscationMode The {@link SystemContext} specifies which level
* of obfuscation is to be used when encountering upon obfuscated
* properties: E.g. obfuscation may be bound to the host, the
* "secret" used for obfuscation being the same for all applications
* on the same host or obfuscation may be bound to the application,
* being different for different applications on the same host.
*/
public RuntimePropertiesImpl( PolyglotPropertiesBuilderFactory aPropertiesBuilderFactory, Option> aRootOption, SystemContext aObfuscationMode ) {
this( aPropertiesBuilderFactory, new OptionCondition( aRootOption ), aObfuscationMode );
}
/**
* Constructs a {@link RuntimeProperties} instance with the given
* {@link ArgsSyntax} used to parse command line arguments. Also constructs
* the {@link RuntimeProperties} with the given obfuscation mode.
*
* @param aPropertiesBuilderFactory The factory to use when constructing
* {@link ResourceProperties} instances.
* @param aRootArgsSyntax The root condition being the node from which
* parsing the command line arguments starts. Parse the command line
* arguments via {@link #evalArgs(String[])}.
* @param aObfuscationMode The {@link SystemContext} specifies which level
* of obfuscation is to be used when encountering upon obfuscated
* properties: E.g. obfuscation may be bound to the host, the
* "secret" used for obfuscation being the same for all applications
* on the same host or obfuscation may be bound to the application,
* being different for different applications on the same host.
*/
public RuntimePropertiesImpl( PolyglotPropertiesBuilderFactory aPropertiesBuilderFactory, ArgsSyntax aRootArgsSyntax, SystemContext aObfuscationMode ) {
_argsParserProperties = new ArgsParserPropertiesImpl( aRootArgsSyntax );
_secret = toEncrypted( aObfuscationMode.toContextSequence() );
_factory = aPropertiesBuilderFactory;
}
/**
* Constructs a {@link RuntimeProperties} instance with a custom secret for
* obfuscation.
*
* @param aPropertiesBuilderFactory The factory to use when constructing
* {@link ResourceProperties} instances.
* @param aSecret The secret to be used when encountering upon obfuscated
* properties.
*/
public RuntimePropertiesImpl( PolyglotPropertiesBuilderFactory aPropertiesBuilderFactory, String aSecret ) {
_argsParserProperties = new ArgsParserPropertiesImpl();
_secret = toEncrypted( aSecret );
_factory = aPropertiesBuilderFactory;
}
/**
* Constructs a {@link RuntimeProperties} instance with no
* {@link ArgsSyntax} for parsing command line arguments: As no syntax
* notation is required by the constructor (no root {@link ArgsSyntax}), no
* syntax validation is done. Therefore the properties are heuristically
* determined from the provided command line arguments. Also constructs a
* {@link RuntimeProperties} instance with a custom secret for obfuscation.
*
* @param aPropertiesBuilderFactory The factory to use when constructing
* {@link ResourceProperties} instances.
* @param aArgs The command line arguments to be evaluated.
* @param aSecret The secret to be used when encountering upon obfuscated
* properties.
*/
public RuntimePropertiesImpl( PolyglotPropertiesBuilderFactory aPropertiesBuilderFactory, String[] aArgs, String aSecret ) {
_argsParserProperties = new ArgsParserPropertiesImpl( aArgs );
_secret = toEncrypted( aSecret );
_factory = aPropertiesBuilderFactory;
}
/**
* Constructs a {@link RuntimeProperties} instance with the given
* {@link ArgsSyntax} used to parse command line arguments. Also constructs
* a {@link RuntimeProperties} instance with a custom secret for
* obfuscation.
*
* @param aPropertiesBuilderFactory The factory to use when constructing
* {@link ResourceProperties} instances.
* @param aRootOption The root condition being the node from which parsing
* the command line arguments starts. Parse the command line
* arguments via {@link #evalArgs(String[])}.
* @param aSecret The secret to be used when encountering upon obfuscated
* properties.
*/
public RuntimePropertiesImpl( PolyglotPropertiesBuilderFactory aPropertiesBuilderFactory, Option> aRootOption, String aSecret ) {
this( aPropertiesBuilderFactory, new OptionCondition( aRootOption ), aSecret );
}
/**
* Constructs a {@link RuntimeProperties} instance with the given
* {@link ArgsSyntax} used to parse command line arguments. Also constructs
* a {@link RuntimeProperties} instance with a custom secret for
* obfuscation.
*
* @param aPropertiesBuilderFactory The factory to use when constructing
* {@link ResourceProperties} instances.
* @param aRootArgsSyntax The root condition being the node from which
* parsing the command line arguments starts. Parse the command line
* arguments via {@link #evalArgs(String[])}.
* @param aSecret The secret to be used when encountering upon obfuscated
* properties.
*/
public RuntimePropertiesImpl( PolyglotPropertiesBuilderFactory aPropertiesBuilderFactory, ArgsSyntax aRootArgsSyntax, String aSecret ) {
_argsParserProperties = new ArgsParserPropertiesImpl( aRootArgsSyntax );
_secret = toEncrypted( aSecret );
_factory = aPropertiesBuilderFactory;
}
// -------------------------------------------------------------------------
/**
* After constructor execution do a post construct.
*/
private void postConstruct() {
if ( !_isPostConstructed ) {
synchronized ( this ) {
if ( !_isPostConstructed ) {
_propertiesPrecedence.prependProperties( toObfuscationProperties( _environmentProperties ) );
_propertiesPrecedence.prependProperties( toObfuscationProperties( _systemProperties ) );
_propertiesPrecedence.prependProperties( toObfuscationProperties( _argsParserProperties ) );
for ( ResourceProperties eProperties : _resourceProperties ) {
if ( !_propertiesPrecedence.containsProperties( eProperties ) ) {
_propertiesPrecedence.appendProperties( new ObfuscationPropertiesDecorator( eProperties, toDecrypted( _secret ) ) );
}
}
setProperties( new ProfilePropertiesProjection( _propertiesPrecedence ) );
_isPostConstructed = true;
}
}
}
}
// /////////////////////////////////////////////////////////////////////////
// METHODS:
// /////////////////////////////////////////////////////////////////////////
/**
* {@inheritDoc}
*/
@Override
public List getExamples() {
return _argsParserProperties.getExamples();
}
/**
* {@inheritDoc}
*/
@Override
public void addExample( Example aExampleUsage ) {
_argsParserProperties.addExample( aExampleUsage );
}
/**
* {@inheritDoc}
*/
@Override
public void printExamples() {
_argsParserProperties.printExamples();
}
/**
* {@inheritDoc}
*/
@Override
public String getLineSeparatorEscapeCode() {
return _argsParserProperties.getLineSeparatorEscapeCode();
}
/**
* {@inheritDoc}
*/
@Override
public void setLineSeparatorEscapeCode( String aLineSeparatorEscCode ) {
_argsParserProperties.setLineSeparatorEscapeCode( aLineSeparatorEscCode );
}
/**
* {@inheritDoc}
*/
@Override
public String getBannerEscapeCode() {
return _argsParserProperties.getBannerEscapeCode();
}
/**
* {@inheritDoc}
*/
@Override
public String getBannerBorderEscapeCode() {
return _argsParserProperties.getBannerBorderEscapeCode();
}
/**
* {@inheritDoc}
*/
@Override
public void setBannerEscapeCode( String aBannerEscCode ) {
_argsParserProperties.setBannerEscapeCode( aBannerEscCode );
}
/**
* {@inheritDoc}
*/
@Override
public void setBannerBorderEscapeCode( String aBannerBorderEscCode ) {
_argsParserProperties.setBannerBorderEscapeCode( aBannerBorderEscCode );
}
/**
* {@inheritDoc}
*/
@Override
public String getDescriptionEscapeCode() {
return _argsParserProperties.getDescriptionEscapeCode();
}
/**
* {@inheritDoc}
*/
@Override
public void setDescriptionEscapeCode( String aParamDescriptionEscCode ) {
_argsParserProperties.setDescriptionEscapeCode( aParamDescriptionEscCode );
}
/**
* {@inheritDoc}
*/
@Override
public String getCommandEscapeCode() {
return _argsParserProperties.getCommandEscapeCode();
}
/**
* {@inheritDoc}
*/
@Override
public void setCommandEscapeCode( String aCommandEscCode ) {
_argsParserProperties.setCommandEscapeCode( aCommandEscCode );
}
/**
* {@inheritDoc}
*/
@Override
public boolean isEscapeCodesEnabled() {
return _argsParserProperties.isEscapeCodesEnabled();
}
/**
* {@inheritDoc}
*/
@Override
public void setEscapeCodesEnabled( boolean isEscCodeEnabled ) {
_argsParserProperties.setEscapeCodesEnabled( isEscCodeEnabled );
}
/**
* {@inheritDoc}
*/
@Override
public String getResetEscapeCode() {
return _argsParserProperties.getResetEscapeCode();
}
/**
* {@inheritDoc}
*/
@Override
public void setResetEscapeCode( String aResetEscCode ) {
_argsParserProperties.setResetEscapeCode( aResetEscCode );
}
/**
* {@inheritDoc}
*/
@Override
public String getParamEscapeCode() {
return _argsParserProperties.getParamEscapeCode();
}
/**
* {@inheritDoc}
*/
@Override
public void setParamEscapeCode( String aParamEscCode ) {
_argsParserProperties.setParamEscapeCode( aParamEscCode );
}
/**
* {@inheritDoc}
*/
@Override
public String getOptionEscapeCode() {
return _argsParserProperties.getOptionEscapeCode();
}
/**
* {@inheritDoc}
*/
@Override
public void setOptionEscapeCode( String aOptEscCode ) {
_argsParserProperties.setOptionEscapeCode( aOptEscCode );
}
/**
* {@inheritDoc}
*/
@Override
public String getCopyrightNote() {
return _argsParserProperties.getCopyrightNote();
}
/**
* {@inheritDoc}
*/
@Override
public String getDescription() {
return _argsParserProperties.getDescription();
}
/**
* {@inheritDoc}
*/
@Override
public String getLicenseNote() {
return _argsParserProperties.getLicenseNote();
}
/**
* {@inheritDoc}
*/
@Override
public void setRootArgsSyntax( ArgsSyntax aRootArgsSyntax ) {
if ( _isPostConstructed ) {
throw new IllegalStateException( "The runtime properties have already been post-constructed as the properties have already been accessed, you must call this method before first accessing any property!" );
}
_argsParserProperties = new ArgsParserPropertiesImpl( aRootArgsSyntax );
}
/**
* {@inheritDoc}
*/
@Override
public void setRootOption( Option> aRootOption ) {
if ( _isPostConstructed ) {
throw new IllegalStateException( "The runtime properties have already been post-constructed as the properties have already been accessed, you must call this method before first accessing any property!" );
}
_argsParserProperties = new ArgsParserPropertiesImpl( aRootOption );
}
/**
* {@inheritDoc}
*/
@Override
public void setSecret( String aSecret ) {
if ( _isPostConstructed ) {
throw new IllegalStateException( "The runtime properties have already been post-constructed as the properties have already been accessed, you must call this method before first accessing any property!" );
}
_secret = toEncrypted( aSecret );
}
/**
* {@inheritDoc}
*/
@Override
public void setObfuscationMode( SystemContext aObfuscationMode ) {
if ( _isPostConstructed ) {
throw new IllegalStateException( "The runtime properties have already been post-constructed as the properties have already been accessed, you must call this method before first accessing any property!" );
}
_secret = toEncrypted( aObfuscationMode.toContextSequence() );
}
/**
* {@inheritDoc}
*/
@Override
public char getSeparatorLnChar() {
return _argsParserProperties.getSeparatorLnChar();
}
/**
* {@inheritDoc}
*/
@Override
public TextBoxGrid getTextBoxGrid() {
return _argsParserProperties.getTextBoxGrid();
}
/**
* {@inheritDoc}
*/
@Override
public void setTextBoxGrid( TextBoxGrid aTextBoxGrid ) {
_argsParserProperties.setTextBoxGrid( aTextBoxGrid );
}
/**
* {@inheritDoc}
*/
@Override
public RuntimeProperties withProperties( Properties aProperties ) {
addProperties( aProperties );
return this;
}
protected void addProperties( Properties aProperties ) {
if ( aProperties instanceof ResourcePropertiesBuilder ) {
try {
ObfuscationResourcePropertiesBuilder theObfuscation = new ObfuscationResourcePropertiesBuilderDecorator( (ResourcePropertiesBuilder) aProperties, toDecrypted( _secret ) );
_resourceProperties.add( theObfuscation );
_propertiesPrecedence.appendProperties( theObfuscation );
}
catch ( IOException e ) {
_resourceProperties.add( (ResourceProperties) aProperties );
_propertiesPrecedence.appendProperties( aProperties );
}
}
else if ( aProperties instanceof ResourceProperties ) {
ObfuscationProperties theObfuscation = new ObfuscationPropertiesDecorator( (ResourceProperties) aProperties, toDecrypted( _secret ) );
_resourceProperties.add( (ResourceProperties) aProperties );
_propertiesPrecedence.appendProperties( theObfuscation );
}
}
/**
* {@inheritDoc}
*/
@Override
public RuntimeProperties withFile( File aFile, ConfigLocator aConfigLocator, char... aDelimiters ) throws IOException, ParseException {
addProperties( aFile, aConfigLocator, aDelimiters );
return this;
}
/**
* {@inheritDoc}
*/
@Override
public RuntimeProperties withInputStream( InputStream aInputStream, char... aDelimiters ) throws IOException, ParseException {
addProperties( aInputStream, aDelimiters );
return this;
}
/**
* {@inheritDoc}
*/
@Override
public RuntimeProperties withFilePath( Class> aResourceClass, String aFilePath, ConfigLocator aConfigLocator, char... aDelimiters ) throws IOException, ParseException {
addProperties( aResourceClass, aFilePath, aConfigLocator, aDelimiters );
return this;
}
/**
* {@inheritDoc}
*/
@Override
public RuntimeProperties withUrl( URL aUrl, char... aDelimiters ) throws IOException, ParseException {
addProperties( aUrl, aDelimiters );
return this;
}
/**
* {@inheritDoc}
*/
@Override
public RuntimeProperties withEvalArgs( String[] aArgs ) throws UnknownArgsException, AmbiguousArgsException, SuperfluousArgsException, ParseArgsException {
evalArgs( aArgs );
return this;
}
/**
* {@inheritDoc}
*/
@Override
public void errorLn( String aLine ) {
_argsParserProperties.errorLn( aLine );
}
/**
* {@inheritDoc}
*/
@Override
public List extends Operand>> evalArgs( List aArgs ) throws UnknownArgsException, AmbiguousArgsException, SuperfluousArgsException, ParseArgsException {
return _argsParserProperties.evalArgs( aArgs );
}
/**
* {@inheritDoc}
*/
@Override
public List extends Operand>> evalArgs( String aToPath, List aArgs ) throws UnknownArgsException, AmbiguousArgsException, SuperfluousArgsException, ParseArgsException {
return _argsParserProperties.evalArgs( aToPath, aArgs );
}
/**
* {@inheritDoc}
*/
@Override
public List extends Operand>> evalArgs( String aToPath, String[] aArgs ) throws UnknownArgsException, AmbiguousArgsException, SuperfluousArgsException, ParseArgsException {
return _argsParserProperties.evalArgs( aToPath, aArgs );
}
/**
* {@inheritDoc}
*/
@Override
public List extends Operand>> evalArgs( String[] aArgs ) throws UnknownArgsException, AmbiguousArgsException, SuperfluousArgsException, ParseArgsException {
return _argsParserProperties.evalArgs( aArgs );
}
/**
* {@inheritDoc}
*/
@Override
public ArgsSyntax getRootArgsSyntax() {
return _argsParserProperties.getRootArgsSyntax();
}
/**
* {@inheritDoc}
*/
@Override
public void printBanner() {
_argsParserProperties.printBanner();
}
/**
* {@inheritDoc}
*/
@Override
public void printCopyrightNote() {
_argsParserProperties.printCopyrightNote();
}
/**
* {@inheritDoc}
*/
@Override
public void printDescription() {
_argsParserProperties.printDescription();
}
/**
* {@inheritDoc}
*/
@Override
public void printHelp() {
_argsParserProperties.printHelp();
}
/**
* {@inheritDoc}
*/
@Override
public void printLicenseNote() {
_argsParserProperties.printLicenseNote();
}
/**
* {@inheritDoc}
*/
@Override
public void printLn() {
_argsParserProperties.printLn();
}
/**
* {@inheritDoc}
*/
@Override
public void printLn( String aLine ) {
_argsParserProperties.printLn( aLine );
}
/**
* {@inheritDoc}
*/
@Override
public void printOptions() {
_argsParserProperties.printOptions();
}
/**
* {@inheritDoc}
*/
@Override
public void printSeparatorLn() {
_argsParserProperties.printSeparatorLn();
}
/**
* {@inheritDoc}
*/
@Override
public void printSynopsis() {
_argsParserProperties.printSynopsis();
}
/**
* {@inheritDoc}
*/
@Override
public void reset() {
_argsParserProperties.reset();
}
/**
* {@inheritDoc}
*/
@Override
public void setBannerFont( Font aBannerFont ) {
_argsParserProperties.setBannerFont( aBannerFont );
}
/**
* {@inheritDoc}
*/
@Override
public void setBannerFontPalette( char[] aColorPalette ) {
_argsParserProperties.setBannerFontPalette( aColorPalette );
}
/**
* {@inheritDoc}
*/
@Override
public void setConsoleWidth( int aConsoleWidth ) {
_argsParserProperties.setConsoleWidth( aConsoleWidth );
}
/**
* {@inheritDoc}
*/
@Override
public void setCopyrightNote( String aCopyrightNote ) {
_argsParserProperties.setCopyrightNote( aCopyrightNote );
}
/**
* {@inheritDoc}
*/
@Override
public void setDescription( String aDescription ) {
_argsParserProperties.setDescription( aDescription );
}
/**
* {@inheritDoc}
*/
@Override
public void setErrorOut( PrintStream aErrorOut ) {
_argsParserProperties.setErrorOut( aErrorOut );
}
/**
* {@inheritDoc}
*/
@Override
public void setLicenseNote( String aLicenseNote ) {
_argsParserProperties.setLicenseNote( aLicenseNote );
}
/**
* {@inheritDoc}
*/
@Override
public void setLineBreak( String aLineBreak ) {
_argsParserProperties.setLineBreak( aLineBreak );
}
/**
* {@inheritDoc}
*/
@Override
public void setMaxConsoleWidth( int aMaxConsoleWidth ) {
_argsParserProperties.setMaxConsoleWidth( aMaxConsoleWidth );
}
/**
* {@inheritDoc}
*/
@Override
public void setName( String aName ) {
_argsParserProperties.setName( aName );
}
/**
* {@inheritDoc}
*/
@Override
public void setSeparatorLnChar( char aSeparatorChar ) {
_argsParserProperties.setSeparatorLnChar( aSeparatorChar );
}
/**
* {@inheritDoc}
*/
@Override
public void setStandardOut( PrintStream aStandardOut ) {
_argsParserProperties.setStandardOut( aStandardOut );
}
/**
* {@inheritDoc}
*/
@Override
public void setSyntaxNotation( SyntaxNotation aSyntaxNotation ) {
_argsParserProperties.setSyntaxNotation( aSyntaxNotation );
}
/**
* {@inheritDoc}
*/
@Override
public void setTitle( String aTitle ) {
_argsParserProperties.setTitle( aTitle );
}
/**
* {@inheritDoc}
*/
@Override
public Properties reload() throws IOException, IllegalStateException, ParseException {
PropertiesBuilder theProperties = new PropertiesBuilderImpl();
for ( int i = _resourceProperties.size() - 1; i >= 0; i-- ) {
theProperties.insert( _resourceProperties.get( i ).reload() );
}
return theProperties;
}
/**
* {@inheritDoc}
*/
@Override
public Properties reload( ReloadMode aReloadMode ) throws IOException, IllegalStateException, ParseException {
PropertiesBuilder theProperties = new PropertiesBuilderImpl();
for ( int i = _resourceProperties.size() - 1; i >= 0; i-- ) {
theProperties.insert( _resourceProperties.get( i ).reload( aReloadMode ) );
}
return theProperties;
}
/**
* {@inheritDoc}
*/
@Override
public char getDelimiter() {
if ( getProperties() == null ) {
throw new IllegalStateException( "You must properly construct and then initialize your instance via #postConstruct() !" );
}
return super.getDelimiter();
}
/**
* {@inheritDoc}
*/
@Override
public int size() {
if ( getProperties() == null ) {
throw new IllegalStateException( "You must properly construct and then initialize your instance via #postConstruct() !" );
}
return super.size();
}
/**
* {@inheritDoc}
*/
@Override
public boolean containsKey( Object aKey ) {
if ( getProperties() == null ) {
throw new IllegalStateException( "You must properly construct and then initialize your instance via #postConstruct() !" );
}
return super.containsKey( aKey );
}
/**
* {@inheritDoc}
*/
@Override
public boolean isEmpty() {
if ( getProperties() == null ) {
throw new IllegalStateException( "You must properly construct and then initialize your instance via #postConstruct() !" );
}
return super.isEmpty();
}
/**
* {@inheritDoc}
*/
@Override
public String get( Object aKey ) {
if ( getProperties() == null ) {
throw new IllegalStateException( "You must properly construct and then initialize your instance via #postConstruct() !" );
}
return super.get( aKey );
}
/**
* {@inheritDoc}
*/
@Override
public Set keySet() {
if ( getProperties() == null ) {
throw new IllegalStateException( "You must properly construct and then initialize your instance via #postConstruct() !" );
}
return super.keySet();
}
/**
* {@inheritDoc}
*/
@Override
public Collection values() {
if ( getProperties() == null ) {
throw new IllegalStateException( "You must properly construct and then initialize your instance via #postConstruct() !" );
}
return super.values();
}
/**
* {@inheritDoc}
*/
@Override
public Properties retrieveFrom( String aFromPath ) {
if ( getProperties() == null ) {
throw new IllegalStateException( "You must properly construct and then initialize your instance via #postConstruct() !" );
}
return super.retrieveFrom( aFromPath );
}
/**
* {@inheritDoc}
*/
@Override
public Properties retrieveTo( String aToPath ) {
if ( getProperties() == null ) {
throw new IllegalStateException( "You must properly construct and then initialize your instance via #postConstruct() !" );
}
return super.retrieveTo( aToPath );
}
/**
* {@inheritDoc}
*/
@Override
public String getTitle() {
return _argsParserProperties.getTitle();
}
/**
* {@inheritDoc}
*/
@Override
public String getName() {
return _argsParserProperties.getName();
}
/**
* {@inheritDoc}
*/
@Override
public Object toDataStructure( String aFromPath ) {
if ( getProperties() == null ) {
throw new IllegalStateException( "You must properly construct and then initialize your instance via #postConstruct() !" );
}
return super.toDataStructure( aFromPath );
}
/**
* Returns the serialized format as of the {@link ResourcePropertiesBuilder}
* instance being produced upon invocation of the
* {@link PolyglotPropertiesBuilderFactory#toProperties(Properties)} method.
* {@inheritDoc}
*/
@Override
public String toSerialized() {
return _factory.toProperties( this ).toSerialized();
}
/**
* Returns the serialized format as of the {@link ResourcePropertiesBuilder}
* instance being produced upon invocation of the
* {@link PolyglotPropertiesBuilderFactory#toProperties(Properties)} method.
* {@inheritDoc}
*/
@Override
public String toSerialized( char aDelimiter ) {
return _factory.toProperties( this ).toSerialized( aDelimiter );
}
/**
* Returns the serialized format as of the {@link ResourcePropertiesBuilder}
* instance being produced upon invocation of the
* {@link PolyglotPropertiesBuilderFactory#toProperties(Properties)} method.
* {@inheritDoc}
*/
@Override
public String toSerialized( String aComment, char aDelimiter ) {
return _factory.toProperties( this ).toSerialized( aComment, aDelimiter );
}
/**
* {@inheritDoc}
*/
@Override
public Properties toRuntimeProfile( String... aProfiles ) {
Properties theSysProperties = (toObfuscationProperties( _systemProperties ));
Properties theEnvProperties = (toObfuscationProperties( _environmentProperties ));
Properties theArgsProperties = (toObfuscationProperties( _argsParserProperties ));
return new PropertiesPrecedenceComposite( theSysProperties, theEnvProperties, theArgsProperties, RuntimeProperties.super.toRuntimeProfile( aProfiles ) );
}
// /////////////////////////////////////////////////////////////////////////
// HOOKS:
// /////////////////////////////////////////////////////////////////////////
@Override
protected Properties getProperties() {
if ( !_isPostConstructed ) {
postConstruct();
}
return super.getProperties();
}
// /////////////////////////////////////////////////////////////////////////
// HELPER:
// /////////////////////////////////////////////////////////////////////////
private ObfuscationPropertiesDecorator toObfuscationProperties( Properties aProperties ) {
return new ObfuscationPropertiesDecorator( aProperties, toDecrypted( _secret ) );
}
private String toEncrypted( String aValue ) {
try {
return new ChaosTextEncrypter( new ChaosKey( SystemContext.HOST_USER_APPLICATION_SESSION.toContextSequence() ) ).toEncrypted( aValue );
}
catch ( EncryptionException e ) {
throw new BugException( e.getMessage(), e );
}
}
private String toDecrypted( String aValue ) {
try {
return new ChaosTextDecrypter( new ChaosKey( SystemContext.HOST_USER_APPLICATION_SESSION.toContextSequence() ) ).toDecrypted( aValue );
}
catch ( DecryptionException e ) {
throw new BugException( e.getMessage(), e );
}
}
/**
* Reads the {@link ResourcePropertiesBuilder} from the given data sink.
*
* @param aFile The data sink from which to read the
* {@link ResourcePropertiesBuilder}.
* @param aConfigLocator The {@link ConfigLocator} specifying where to seek
* for properties.
* @param aDelimiters The delimiters in the properties file to identity a
* path delimiter.
*
* @throws IOException Thrown in case there were problems reading the data
* sink.
* @throws ParseException Thrown in case there were problems parsing the
* data from the data sink.
*/
protected void addProperties( File aFile, ConfigLocator aConfigLocator, char... aDelimiters ) throws IOException, ParseException {
ResourcePropertiesBuilder theProperties = _factory.toProperties( aFile, aConfigLocator, aDelimiters );
try {
theProperties = new ObfuscationResourcePropertiesBuilderDecorator( theProperties, toDecrypted( _secret ) );
}
catch ( IOException ignore ) {}
_resourceProperties.add( theProperties );
_propertiesPrecedence.appendProperties( new ObfuscationPropertiesDecorator( theProperties, toDecrypted( _secret ) ) );
}
/**
* Reads the {@link ResourceProperties} from the given data sink.
*
* @param aInputStream The data sink from which to read the
* {@link ResourceProperties}.
* @param aDelimiters The delimiters in the properties file to identity a
* path delimiter.
*
* @throws IOException Thrown in case there were problems reading the data
* sink.
* @throws ParseException Thrown in case there were problems parsing the
* data from the data sink.
*/
protected void addProperties( InputStream aInputStream, char[] aDelimiters ) throws IOException, ParseException {
ResourceProperties theProperties = _factory.toProperties( aInputStream, aDelimiters );
_resourceProperties.add( theProperties );
_propertiesPrecedence.appendProperties( new ObfuscationPropertiesDecorator( theProperties, toDecrypted( _secret ) ) );
}
/**
* Reads the {@link ResourcePropertiesBuilder} from the given data sink.
*
* @param aResourceClass The class which's class loader is to take care of
* loading the properties (from inside a JAR).
* @param aFilePath The data sink from which to read the
* {@link ResourcePropertiesBuilder}.
* @param aConfigLocator The {@link ConfigLocator} specifying where to seek
* for properties.
* @param aDelimiters The delimiters in the properties file to identity a
* path delimiter.
*
* @throws IOException Thrown in case there were problems reading the data
* sink.
* @throws ParseException Thrown in case there were problems parsing the
* data from the data sink.
*/
protected void addProperties( Class> aResourceClass, String aFilePath, ConfigLocator aConfigLocator, char... aDelimiters ) throws IOException, ParseException {
ResourcePropertiesBuilder theProperties = _factory.toProperties( aResourceClass, aFilePath, aConfigLocator, aDelimiters );
try {
theProperties = new ObfuscationResourcePropertiesBuilderDecorator( theProperties, toDecrypted( _secret ) );
}
catch ( IOException ignore ) {}
_resourceProperties.add( theProperties );
_propertiesPrecedence.appendProperties( new ObfuscationPropertiesDecorator( theProperties, toDecrypted( _secret ) ) );
}
/**
* Reads the {@link ResourceProperties} from the given data sink.
*
* @param aUrl The data sink from which to read the
* {@link ResourceProperties}.
* @param aDelimiters The delimiters in the properties file to identity a
* path delimiter.
*
* @throws IOException Thrown in case there were problems reading the data
* sink.
* @throws ParseException Thrown in case there were problems parsing the
* data from the data sink.
*/
protected void addProperties( URL aUrl, char... aDelimiters ) throws IOException, ParseException {
ResourceProperties theProperties = _factory.toProperties( aUrl, aDelimiters );
_resourceProperties.add( theProperties );
_propertiesPrecedence.appendProperties( new ObfuscationPropertiesDecorator( theProperties, toDecrypted( _secret ) ) );
}
// /////////////////////////////////////////////////////////////////////////
// INNER CLASSES:
// /////////////////////////////////////////////////////////////////////////
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy