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 thePropertyProvider
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:
Property
,PropertyCfg
,PropertyProvider
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.Map<java.lang.String,Property>
confMap
The list of all configured properties.protected java.util.Map<java.lang.String,java.lang.String>
propertyMap
The 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 void
disableValidateConfig()
Disables stringent validation of the configuration.void
enableValidateConfig()
Enables stringent validation of the configuration.java.util.List<Property>
getAllValidProperties()
boolean
getBooleanProperty(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.File
getFileProperty(java.lang.String key)
A property getter forFile
properties.int
getIntegerProperty(java.lang.String key)
A property getter for integer properties.boolean
getOptionalBooleanProperty(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.File
getOptionalFileProperty(java.lang.String key)
InvokesgetFileProperty(String)
int
getOptionalIntegerProperty(java.lang.String key)
InvokesgetIntegerProperty()
java.lang.String
getOptionalStringProperty(java.lang.String key)
InvokesgetStringProperty()
protected java.lang.String
getRawPropertyString(java.lang.String key)
Searches the localpropertyMap
or tries to locate a system propertyjava.lang.String
getStringProperty(java.lang.String key)
A property getter for string properties.void
InitWithCommandLineArguments(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.void
provideProperty(Property p)
Adds precisely one property that can be used at runtime.void
providePropertyList(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:
providePropertyList
in interfacePropertyProvider
-
provideProperty
public void provideProperty(Property p)
Adds precisely one property that can be used at runtime.- Specified by:
provideProperty
in interfacePropertyProvider
-
enableValidateConfig
public void enableValidateConfig()
Enables stringent validation of the configuration.- Specified by:
enableValidateConfig
in interfacePropertyProvider
- See Also:
InitWithCommandLineArguments(String[])
-
disableValidateConfig
public void disableValidateConfig()
Disables stringent validation of the configuration.- Specified by:
disableValidateConfig
in interfacePropertyProvider
- See Also:
InitWithCommandLineArguments(String[])
-
getAllValidProperties
public java.util.List<Property> getAllValidProperties()
- Specified by:
getAllValidProperties
in interfacePropertyProvider
- Returns:
- all previously configured properties
-
InitWithCommandLineArguments
public void InitWithCommandLineArguments(java.lang.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:
InitWithCommandLineArguments
in 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:
getOptionalBooleanProperty
in 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 InvalidArgumentException
InvokesgetClassProperty(String)
- Specified by:
getOptionalClassProperty
in 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 InvalidArgumentException
InvokesgetEnumProperty(Class, String)
- Specified by:
getOptionalEnumProperty
in 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:
getOptionalFileProperty
in interfacePropertyProvider
- Returns:
- the given value, otherwise the configured default value
-
getOptionalIntegerProperty
public int getOptionalIntegerProperty(java.lang.String key) throws InvalidArgumentException
InvokesgetIntegerProperty()
- Specified by:
getOptionalIntegerProperty
in 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:
getOptionalStringProperty
in 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 InvalidArgumentException
InvokesgetClassListProperty()
- Specified by:
getOptionalClassListProperty
in 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:
getOptionalFileListProperty
in interfacePropertyProvider
- Returns:
- its result if defined, otherwise the configured default value
-
getRawPropertyString
protected java.lang.String getRawPropertyString(java.lang.String key)
Searches the localpropertyMap
or 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, MissingArgumentException
A property getter for enumeration type.- Specified by:
getEnumProperty
in interfacePropertyProvider
- Parameters:
cls
- the enumeration type of the propertykey
- the key value- Returns:
- an instance of the enumeration
- Throws:
InvalidArgumentException
MissingArgumentException
- if no such property can be found.
-
getBooleanProperty
public boolean getBooleanProperty(java.lang.String key) throws MissingArgumentException
A property getter for Boolean properties.- Specified by:
getBooleanProperty
in interfacePropertyProvider
- Throws:
MissingArgumentException
- If no such property can be found.
-
getClassProperty
public java.lang.Class<?> getClassProperty(java.lang.String key) throws MissingArgumentException, InvalidArgumentException
A property getter for class properties.- Specified by:
getClassProperty
in 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 MissingArgumentException
A property getter forFile
properties.- Specified by:
getFileProperty
in 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, InvalidArgumentException
A property getter for integer properties.- Specified by:
getIntegerProperty
in 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 MissingArgumentException
A property getter for string properties.- Specified by:
getStringProperty
in interfacePropertyProvider
- Throws:
MissingArgumentException
- if no such property can be found.
-
getClassListProperty
public java.lang.Class<?>[] getClassListProperty(java.lang.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:
getClassListProperty
in 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 MissingArgumentException
Gets a list of files given with a string property value. The single file specifications must be separated byFile.pathSeparator
.- Specified by:
getFileListProperty
in interfacePropertyProvider
- Returns:
- an array of file instances.
- Throws:
MissingArgumentException
- if no such property can be found.
-
-