Package de.mid.innovator.ui
Class PropertyProviderDefault
java.lang.Object
de.mid.innovator.ui.PropertyProviderDefault
- All Implemented Interfaces:
PropertyProvider
The class is a default implementation of the
PropertyProvider
interface which can be used to unify command line arguments and system
properties. It also helps to configure and transform the property values at
runtime. It checks the configured properties against the given command line
arguments and provides the user with default values.- Author:
- borschet
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionThe default constructor which creates an empty property provider. -
Method Summary
Modifier and TypeMethodDescriptionvoidDisables stringent validation of the configuration.voidEnables stringent validation of the configuration.booleangetBooleanProperty(String key) A property getter for Boolean properties.Class<?>[]Gets a list of classes from a given string property.Class<?> getClassProperty(String key) A property getter for class properties.<T extends Enum<T>>
TgetEnumProperty(Class<T> cls, String key) A property getter for enumeration type.File[]Gets a list of files given with a string property value.getFileProperty(String key) A property getter forFileproperties.intgetIntegerProperty(String key) A property getter for integer properties.booleanInvokesgetBooleanProperty(String)Class<?>[]getOptionalClassListProperty(String key, Class<?>[] defaultValue) InvokesgetClassListProperty()Class<?> InvokesgetClassProperty(String)<T extends Enum<T>>
TgetOptionalEnumProperty(Class<T> cls, String key) InvokesgetEnumProperty(Class, String)File[]getOptionalFileListProperty(String key, File[] defaultValue) InvokesgetFileListProperty()InvokesgetFileProperty(String)intInvokesgetIntegerProperty()InvokesgetStringProperty()getStringProperty(String key) A property getter for string properties.voidInitWithCommandLineArguments(String[] commandLineArguments) Initializes the property provider with a wide array of command line argument strings, checks the given values against the configuration and prepares the values for use with the typed getter methods.booleanisPropertySet(String key) Returns true if the property with the given key is existing and set, else returns false.voidAdds precisely one property that can be used at runtime.voidprovidePropertyList(List<Property> validProps) Configures a list of valid properties to be used at runtime.voidsetProperty(String key, String value) Set the value for an existing property.
-
Constructor Details
-
PropertyProviderDefault
public PropertyProviderDefault()The default constructor which creates an empty property provider.
-
-
Method Details
-
providePropertyList
Configures a list of valid properties to be used at runtime.- Specified by:
providePropertyListin interfacePropertyProvider
-
provideProperty
Adds precisely one property that can be used at runtime.- Specified by:
providePropertyin interfacePropertyProvider
-
enableValidateConfig
public void enableValidateConfig()Enables stringent validation of the configuration.- Specified by:
enableValidateConfigin interfacePropertyProvider- See Also:
-
disableValidateConfig
public void disableValidateConfig()Disables stringent validation of the configuration.- Specified by:
disableValidateConfigin interfacePropertyProvider- See Also:
-
getAllValidProperties
- Specified by:
getAllValidPropertiesin interfacePropertyProvider- Returns:
- all previously configured properties
-
InitWithCommandLineArguments
public void InitWithCommandLineArguments(String[] commandLineArguments) throws UnknownArgumentException Initializes the property provider with a wide array of command line argument strings, checks the given values against the configuration and prepares the values for use with the typed getter methods. This means that the command line arguments are parsed according to the format "<key>=<value>". The property provider checks every given string argument so that they correspond with a valid configured property. If no such property can be found, an exception is raised. This behavior can be prevented by callingdisableValidateConfig()before the property provider is initialized.- Specified by:
InitWithCommandLineArgumentsin interfacePropertyProvider- Throws:
UnknownArgumentException- If the list of command line arguments contains a property that was not previously configured and this check is not disabled.
-
getOptionalBooleanProperty
InvokesgetBooleanProperty(String)- Specified by:
getOptionalBooleanPropertyin interfacePropertyProvider- Parameters:
key- the argument key value- Returns:
- true if the property's string value is "true", otherwise false
-
getOptionalClassProperty
InvokesgetClassProperty(String)- Specified by:
getOptionalClassPropertyin interfacePropertyProvider- Parameters:
key- the argument key value- Returns:
- the given value, otherwise the configured default value
- Throws:
InvalidArgumentException- If the given string cannot be converted into a valid class.
-
getOptionalEnumProperty
public <T extends Enum<T>> T getOptionalEnumProperty(Class<T> cls, String key) throws InvalidArgumentException InvokesgetEnumProperty(Class, String)- Specified by:
getOptionalEnumPropertyin interfacePropertyProvider- Parameters:
cls- the enumeration type of the propertykey- the key value- Returns:
- the given value, otherwise the configured default value
- Throws:
InvalidArgumentException- If the conversion from the value to a valid member of the given enumeration fails.
-
getOptionalFileProperty
InvokesgetFileProperty(String)- Specified by:
getOptionalFilePropertyin interfacePropertyProvider- Returns:
- the given value, otherwise the configured default value
-
getOptionalIntegerProperty
InvokesgetIntegerProperty()- Specified by:
getOptionalIntegerPropertyin interfacePropertyProvider- Returns:
- its result if defined, otherwise the configured default value
- Throws:
InvalidArgumentException- If the properties string value cannot be converted into an integer.
-
getOptionalStringProperty
InvokesgetStringProperty()- Specified by:
getOptionalStringPropertyin interfacePropertyProvider- Returns:
- its result if defined, otherwise the configured default value
-
getOptionalClassListProperty
public Class<?>[] getOptionalClassListProperty(String key, Class<?>[] defaultValue) throws InvalidArgumentException InvokesgetClassListProperty()- Specified by:
getOptionalClassListPropertyin interfacePropertyProvider- Returns:
- its result if defined, otherwise the configured default value
- Throws:
InvalidArgumentException- if the property string value cannot be converted into a list of classes.
-
getOptionalFileListProperty
InvokesgetFileListProperty()- Specified by:
getOptionalFileListPropertyin interfacePropertyProvider- Returns:
- its result if defined, otherwise the configured default value
-
getEnumProperty
public <T extends Enum<T>> T getEnumProperty(Class<T> cls, String key) throws InvalidArgumentException, MissingArgumentException A property getter for enumeration type.- Specified by:
getEnumPropertyin interfacePropertyProvider- Parameters:
cls- the enumeration type of the propertykey- the key value- Returns:
- an instance of the enumeration
- Throws:
InvalidArgumentExceptionMissingArgumentException- if no such property can be found.
-
getBooleanProperty
A property getter for Boolean properties.- Specified by:
getBooleanPropertyin interfacePropertyProvider- Throws:
MissingArgumentException- If no such property can be found.
-
getClassProperty
public Class<?> getClassProperty(String key) throws MissingArgumentException, InvalidArgumentException A property getter for class properties.- Specified by:
getClassPropertyin interfacePropertyProvider- Throws:
InvalidArgumentException- if the property value cannot be converted into a valid class.MissingArgumentException- if no such property can be found.
-
getFileProperty
A property getter forFileproperties.- Specified by:
getFilePropertyin interfacePropertyProvider- Returns:
- a file object created with
File(java.lang.String) - Throws:
MissingArgumentException- if no such property can be found.
-
getIntegerProperty
A property getter for integer properties.- Specified by:
getIntegerPropertyin interfacePropertyProvider- Throws:
InvalidArgumentException- if the property value cannot be converted into an integer.MissingArgumentException- if no such property can be found.
-
getStringProperty
A property getter for string properties.- Specified by:
getStringPropertyin interfacePropertyProvider- Throws:
MissingArgumentException- if no such property can be found.
-
getClassListProperty
public Class<?>[] getClassListProperty(String key) throws MissingArgumentException, InvalidArgumentException Gets a list of classes from a given string property. Each class specifications must be separated by aFile.pathSeparator.- Specified by:
getClassListPropertyin interfacePropertyProvider- Returns:
- an array of classes.
- Throws:
InvalidArgumentException- if an entry of the string list cannot be converted into a valid class.MissingArgumentException- if no such property can be found.
-
getFileListProperty
Gets a list of files given with a string property value. The single file specifications must be separated byFile.pathSeparator.- Specified by:
getFileListPropertyin interfacePropertyProvider- Returns:
- an array of file instances.
- Throws:
MissingArgumentException- if no such property can be found.
-
isPropertySet
Description copied from interface:PropertyProviderReturns true if the property with the given key is existing and set, else returns false.- Specified by:
isPropertySetin interfacePropertyProvider- Parameters:
key- key of the property- Returns:
- true if property with key is set.
-
setProperty
Description copied from interface:PropertyProviderSet the value for an existing property. If the property does not exist, nothing is done.- Specified by:
setPropertyin interfacePropertyProvider- Parameters:
key-value-
-