All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.refcodes.configuration.ext.runtime.RuntimeProperties Maven / Gradle / Ivy

Go to download

Artefact for providing predefined configuration compositions common for everyday application setups.

There is a newer version: 2.0.5
Show newest version
// /////////////////////////////////////////////////////////////////////////////
// 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/LICENSE-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.configuration.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.List;

import org.refcodes.configuration.EnvironmentProperties;
import org.refcodes.configuration.ProfileProperties;
import org.refcodes.configuration.ProfilePropertiesProjection;
import org.refcodes.configuration.Properties;
import org.refcodes.configuration.ResourceProperties;
import org.refcodes.configuration.ResourcePropertiesMixin;
import org.refcodes.configuration.SystemProperties;
import org.refcodes.configuration.TomlPropertiesBuilder;
import org.refcodes.configuration.ext.console.ArgsParserProperties;
import org.refcodes.console.AmbiguousArgsException;
import org.refcodes.console.ArgsParser;
import org.refcodes.console.Condition;
import org.refcodes.console.ParseArgsException;
import org.refcodes.console.RootConditionAccessor.RootConditionBuilder;
import org.refcodes.console.RootConditionAccessor.RootConditionMutator;
import org.refcodes.console.SuperfluousArgsException;
import org.refcodes.console.SyntaxNotation;
import org.refcodes.console.UnknownArgsException;
import org.refcodes.mixin.SecretAccessor.SecretBuilder;
import org.refcodes.mixin.SecretAccessor.SecretMutator;
import org.refcodes.runtime.ConfigLocator;
import org.refcodes.runtime.RuntimeUtility;
import org.refcodes.runtime.SystemContext;
import org.refcodes.textual.Font;

/**
 * {@link RuntimeProperties} are composed of various {@link Properties} flavors
 * such as {@link ArgsParserProperties}, {@link SystemProperties},
 * {@link EnvironmentProperties} and {@link ResourceProperties} with a
 * precedence in this order, encapsulated by a
 * {@link ProfilePropertiesProjection} in order for you, the developer, to
 * conveniently harness the power of the {@link Properties} functionality. You
 * may also add a {@link Properties} instance programmatically to manually
 * provide properties (via {@link #withProperties(Properties)}). The later you
 * add {@link Properties}, the lower their precedence.
 * 
 * After construction the use {@link #withFile(java.io.File)},
 * {@link #withUrl(java.net.URL)} or the like to load the properties from
 * external resources. After construction use {@link #withParseArgs(String[])}
 * or the like to parse the command line arguments (implementations might
 * provide a constructor such as
 * {@link RuntimePropertiesImpl#RuntimePropertiesImpl(String[])} for the command
 * line arguments if you do not require a command syntax notation).
 * 
 * {@link RuntimeProperties} represent a composition of the different
 * {@link Properties} flavors, therefore providing functionality from the
 * {@link ArgsParserProperties} as well as from the {@link ResourceProperties}
 * types.
 */
public interface RuntimeProperties extends RootConditionMutator, RootConditionBuilder, SecretMutator, SecretBuilder, ArgsParserProperties, ResourceProperties, ResourcePropertiesMixin, ProfileProperties {

	static char[] DELIMITERS = TomlPropertiesBuilder.DELIMITERS;

	/**
	 * Specifies the obfuscation mode to be used.
	 * 
	 * @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.
	 */
	void setObfuscationMode( SystemContext aObfuscationMode );

	/**
	 * Builder method for the obfuscation mode property returning the builder
	 * for applying multiple build operations.
	 * 
	 * @param aObfuscationMode The obfuscation mode as of
	 *        {@link #setObfuscationMode(SystemContext)}.
	 * 
	 * @return The builder for applying multiple build operations.
	 */
	default RuntimeProperties withObfuscationMode( SystemContext aObfuscationMode ) {
		setObfuscationMode( aObfuscationMode );
		return this;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	default RuntimeProperties withRootCondition( Condition aRootCondition ) {
		setRootCondition( aRootCondition );
		return this;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	default RuntimeProperties withSecret( String aSecret ) {
		setSecret( aSecret );
		return this;
	}

	/**
	 * A hook for you to provide {@link Properties} programmatically. The later
	 * you add {@link Properties}, the lower their precedence.
	 * 
	 * @param aProperties The {@link Properties} to be added.
	 * 
	 * @return This instance as of the builder pattern to apply method chaining.
	 */
	RuntimeProperties withProperties( Properties aProperties );

	/**
	 * {@inheritDoc}
	 */
	@Override
	RuntimeProperties withParseArgs( String[] aArgs ) throws UnknownArgsException, AmbiguousArgsException, SuperfluousArgsException, ParseArgsException;

	/**
	 * {@inheritDoc}
	 */
	@Override
	default RuntimeProperties withFile( File aFile ) throws IOException, ParseException {
		return withFile( aFile, DELIMITERS );
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	default RuntimeProperties withFilePath( String aFilePath ) throws IOException, ParseException {
		return withFilePath( RuntimeUtility.getMainClass(), aFilePath, DELIMITERS );
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	default RuntimeProperties withFilePath( Class aResourceClass, String aFilePath ) throws IOException, ParseException {
		return withFilePath( aResourceClass, aFilePath, ConfigLocator.ALL, DELIMITERS );
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	default RuntimeProperties withUrl( URL aUrl ) throws IOException, ParseException {
		return withUrl( aUrl, DELIMITERS );
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	default RuntimeProperties withFile( File aFile, ConfigLocator aConfigLocator ) throws IOException, ParseException {
		return withFile( aFile, aConfigLocator, DELIMITERS );
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	default RuntimeProperties withInputStream( InputStream aInputStream ) throws IOException, ParseException {
		return withInputStream( aInputStream, DELIMITERS );
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	default RuntimeProperties withParseArgs( List aArgs ) throws UnknownArgsException, AmbiguousArgsException, SuperfluousArgsException, ParseArgsException {
		return withParseArgs( aArgs.toArray( new String[aArgs.size()] ) );
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	default RuntimeProperties withTitle( String aTitle ) {
		setTitle( aTitle );
		return this;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	default ArgsParser withUsageLabel( String aUsageLabel ) {
		setUsageLabel( aUsageLabel );
		return this;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	default RuntimeProperties withBannerFont( Font aBannerFont ) {
		setBannerFont( aBannerFont );
		return this;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	default RuntimeProperties withBannerFontPalette( char[] aColorPalette ) {
		setBannerFontPalette( aColorPalette );
		return this;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	default RuntimeProperties withConsoleWidth( int aConsoleWidth ) {
		setConsoleWidth( aConsoleWidth );
		return this;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	default RuntimeProperties withCopyrightNote( String aCopyrightNote ) {
		setCopyrightNote( aCopyrightNote );
		return this;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	default RuntimeProperties withDescription( String aDescription ) {
		setDescription( aDescription );
		return this;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	default RuntimeProperties withErrorOut( PrintStream aErrorOut ) {
		setErrorOut( aErrorOut );
		return this;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	default RuntimeProperties withEvalArgs( List aArgs ) throws UnknownArgsException, AmbiguousArgsException, SuperfluousArgsException, ParseArgsException {
		evalArgs( aArgs );
		return this;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	default RuntimeProperties withEvalArgs( String aToPath, List aArgs ) throws UnknownArgsException, AmbiguousArgsException, SuperfluousArgsException, ParseArgsException {
		evalArgs( aToPath, aArgs );
		return this;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	default RuntimeProperties withEvalArgs( String aToPath, String[] aArgs ) throws UnknownArgsException, AmbiguousArgsException, SuperfluousArgsException, ParseArgsException {
		evalArgs( aToPath, aArgs );
		return this;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	default RuntimeProperties withEvalArgs( String[] aArgs ) throws UnknownArgsException, AmbiguousArgsException, SuperfluousArgsException, ParseArgsException {
		evalArgs( aArgs );
		return this;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	default RuntimeProperties withLicenseNote( String aLicenseNote ) {
		setLicenseNote( aLicenseNote );
		return this;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	default RuntimeProperties withLineBreak( String aLineBreak ) {
		setLineBreak( aLineBreak );
		return this;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	default RuntimeProperties withMaxConsoleWidth( int aMaxConsoleWidth ) {
		setMaxConsoleWidth( aMaxConsoleWidth );
		return this;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	default RuntimeProperties withName( String aName ) {
		setName( aName );
		return this;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	default RuntimeProperties withSeparatorChar( char aSeparatorChar ) {
		setSeparatorChar( aSeparatorChar );
		return this;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	default RuntimeProperties withStandardOut( PrintStream aStandardOut ) {
		setStandardOut( aStandardOut );
		return this;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	default RuntimeProperties withSyntaxNotation( SyntaxNotation aSyntaxNotation ) {
		setSyntaxNotation( aSyntaxNotation );
		return this;
	}

	/**
	 * The behavior of this method is implementation specific. See the javadoc
	 * of the implementation in question (such as
	 * {@link RuntimePropertiesImpl#toSerialized()}) for implementation details.
	 * 
	 * {@inheritDoc}
	 */
	@Override
	String toSerialized();

	/**
	 * The behavior of this method is implementation specific. See the javadoc
	 * of the implementation in question (such as
	 * {@link RuntimePropertiesImpl#toSerialized()}) for implementation details.
	 * 
	 * {@inheritDoc}
	 */
	@Override
	String toSerialized( char aDelimiter );
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy