Package de.mid.innovator.ui
Class PropertyProviderDefault
- java.lang.Object
-
- de.mid.innovator.ui.PropertyProviderDefault
-
- All Implemented Interfaces:
PropertyProvider
public class PropertyProviderDefault extends java.lang.Object implements PropertyProvider
The class is a default implementation of thePropertyProviderinterface 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:
Property,PropertyCfg,PropertyProvider
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.Map<java.lang.String,Property>confMapThe list of all configured properties.protected java.util.Map<java.lang.String,java.lang.String>propertyMapThe locally stored properties.
-
Constructor Summary
Constructors Constructor Description PropertyProviderDefault()The default constructor which creates an empty property provider.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voiddisableValidateConfig()Disables stringent validation of the configuration.voidenableValidateConfig()Enables stringent validation of the configuration.java.util.List<Property>getAllValidProperties()booleangetBooleanProperty(java.lang.String key)A property getter for Boolean properties.java.lang.Class<?>[]getClassListProperty(java.lang.String key)Gets a list of classes from a given string property.java.lang.Class<?>getClassProperty(java.lang.String key)A property getter for class properties.<T extends java.lang.Enum<T>>
TgetEnumProperty(java.lang.Class<T> cls, java.lang.String key)A property getter for enumeration type.java.io.File[]getFileListProperty(java.lang.String key)Gets a list of files given with a string property value.java.io.FilegetFileProperty(java.lang.String key)A property getter forFileproperties.intgetIntegerProperty(java.lang.String key)A property getter for integer properties.booleangetOptionalBooleanProperty(java.lang.String key)InvokesgetBooleanProperty(String)java.lang.Class<?>[]getOptionalClassListProperty(java.lang.String key, java.lang.Class<?>[] defaultValue)InvokesgetClassListProperty()java.lang.Class<?>getOptionalClassProperty(java.lang.String key)InvokesgetClassProperty(String)<T extends java.lang.Enum<T>>
TgetOptionalEnumProperty(java.lang.Class<T> cls, java.lang.String key)InvokesgetEnumProperty(Class, String)java.io.File[]getOptionalFileListProperty(java.lang.String key, java.io.File[] defaultValue)InvokesgetFileListProperty()java.io.FilegetOptionalFileProperty(java.lang.String key)InvokesgetFileProperty(String)intgetOptionalIntegerProperty(java.lang.String key)InvokesgetIntegerProperty()java.lang.StringgetOptionalStringProperty(java.lang.String key)InvokesgetStringProperty()protected java.lang.StringgetRawPropertyString(java.lang.String key)Searches the localpropertyMapor tries to locate a system propertyjava.lang.StringgetStringProperty(java.lang.String key)A property getter for string properties.voidInitWithCommandLineArguments(java.lang.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.voidprovideProperty(Property p)Adds precisely one property that can be used at runtime.voidprovidePropertyList(java.util.List<Property> validProps)Configures a list of valid properties to be used at runtime.
-
-
-
Field Detail
-
propertyMap
protected java.util.Map<java.lang.String,java.lang.String> propertyMap
The locally stored properties.
-
confMap
protected java.util.Map<java.lang.String,Property> confMap
The list of all configured properties.
-
-
Method Detail
-
providePropertyList
public void providePropertyList(java.util.List<Property> validProps)
Configures a list of valid properties to be used at runtime.- Specified by:
providePropertyListin interfacePropertyProvider
-
provideProperty
public void provideProperty(Property p)
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:
InitWithCommandLineArguments(String[])
-
disableValidateConfig
public void disableValidateConfig()
Disables stringent validation of the configuration.- Specified by:
disableValidateConfigin interfacePropertyProvider- See Also:
InitWithCommandLineArguments(String[])
-
getAllValidProperties
public java.util.List<Property> getAllValidProperties()
- Specified by:
getAllValidPropertiesin interfacePropertyProvider- Returns:
- all previously configured properties
-
InitWithCommandLineArguments
public void InitWithCommandLineArguments(java.lang.String[] commandLineArguments) throws UnknownArgumentExceptionInitializes 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
public boolean getOptionalBooleanProperty(java.lang.String key)
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
public java.lang.Class<?> getOptionalClassProperty(java.lang.String key) throws InvalidArgumentExceptionInvokesgetClassProperty(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 java.lang.Enum<T>> T getOptionalEnumProperty(java.lang.Class<T> cls, java.lang.String key) throws InvalidArgumentExceptionInvokesgetEnumProperty(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
public java.io.File getOptionalFileProperty(java.lang.String key)
InvokesgetFileProperty(String)- Specified by:
getOptionalFilePropertyin interfacePropertyProvider- Returns:
- the given value, otherwise the configured default value
-
getOptionalIntegerProperty
public int getOptionalIntegerProperty(java.lang.String key) throws InvalidArgumentExceptionInvokesgetIntegerProperty()- 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
public java.lang.String getOptionalStringProperty(java.lang.String key)
InvokesgetStringProperty()- Specified by:
getOptionalStringPropertyin interfacePropertyProvider- Returns:
- its result if defined, otherwise the configured default value
-
getOptionalClassListProperty
public java.lang.Class<?>[] getOptionalClassListProperty(java.lang.String key, java.lang.Class<?>[] defaultValue) throws InvalidArgumentExceptionInvokesgetClassListProperty()- 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
public java.io.File[] getOptionalFileListProperty(java.lang.String key, java.io.File[] defaultValue)InvokesgetFileListProperty()- Specified by:
getOptionalFileListPropertyin interfacePropertyProvider- Returns:
- its result if defined, otherwise the configured default value
-
getRawPropertyString
protected java.lang.String getRawPropertyString(java.lang.String key)
Searches the localpropertyMapor tries to locate a system property- Returns:
- a string value for the given key or null
-
getEnumProperty
public <T extends java.lang.Enum<T>> T getEnumProperty(java.lang.Class<T> cls, java.lang.String key) throws InvalidArgumentException, MissingArgumentExceptionA 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
public boolean getBooleanProperty(java.lang.String key) throws MissingArgumentExceptionA property getter for Boolean properties.- Specified by:
getBooleanPropertyin interfacePropertyProvider- Throws:
MissingArgumentException- If no such property can be found.
-
getClassProperty
public java.lang.Class<?> getClassProperty(java.lang.String key) throws MissingArgumentException, InvalidArgumentExceptionA 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
public java.io.File getFileProperty(java.lang.String key) throws MissingArgumentExceptionA 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
public int getIntegerProperty(java.lang.String key) throws MissingArgumentException, InvalidArgumentExceptionA 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
public java.lang.String getStringProperty(java.lang.String key) throws MissingArgumentExceptionA property getter for string properties.- Specified by:
getStringPropertyin interfacePropertyProvider- Throws:
MissingArgumentException- if no such property can be found.
-
getClassListProperty
public java.lang.Class<?>[] getClassListProperty(java.lang.String key) throws MissingArgumentException, InvalidArgumentExceptionGets 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
public java.io.File[] getFileListProperty(java.lang.String key) throws MissingArgumentExceptionGets 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.
-
-