Package de.mid.innovator.ui
Interface PropertyProvider
-
- All Known Implementing Classes:
PropertyProviderDefault
public interface PropertyProvider
A property provider is used to access an application's arguments at runtime. It synchronizes command line arguments with Java runtime properties and provides a unified way to access, configure and parse properties. The following example code shows how to use a property provider to handle command line arguments:private static final Property[] localProps = { new PropertyCfg<String>("de.mid.myArg", "this is the description for de.mid.myArg"), new PropertyCfg<Boolean>("de.mid.myFlag", false, "this is the description for de.mid.myFlag") } static public main(String[] argv) { PropertyProvider propProv = new PropertyProviderDefault(); List<Property> tmp = Arrays.asList(localProps); propProv.providePropertyList(tmp); // further initialization ... // provide and parse command line arguments propProv.InitWithCommandLineArguments(argv); }
- Author:
- borschet
- See Also:
Property
,PropertyCfg
,PropertyProviderDefault
-
-
Method Summary
All Methods Instance Methods Abstract 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)
Tries to invokegetBooleanProperty(String)
and returns the given value, otherwise the configured default value is returned.java.lang.Class<?>[]
getOptionalClassListProperty(java.lang.String key, java.lang.Class<?>[] defaultValue)
InvokesgetClassListProperty()
java.lang.Class<?>
getOptionalClassProperty(java.lang.String key)
Tries to invokegetClassProperty(String)
<T extends java.lang.Enum<T>>
TgetOptionalEnumProperty(java.lang.Class<T> cls, java.lang.String key)
Tries to invokegetEnumProperty(Class, String)
java.io.File[]
getOptionalFileListProperty(java.lang.String key, java.io.File[] defaultValue)
InvokesgetFileListProperty()
java.io.File
getOptionalFileProperty(java.lang.String key)
Tries to invokegetFileProperty(String)
int
getOptionalIntegerProperty(java.lang.String key)
InvokesgetIntegerProperty()
java.lang.String
getOptionalStringProperty(java.lang.String key)
InvokesgetStringProperty()
java.lang.String
getStringProperty(java.lang.String key)
A property getter for string properties.void
InitWithCommandLineArguments(java.lang.String[] args)
Initializes the property provider with an 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 prop)
Adds precisely one property that can be used at runtime.void
providePropertyList(java.util.List<Property> props)
Configures a list of valid properties to be used at runtime.
-
-
-
Method Detail
-
InitWithCommandLineArguments
void InitWithCommandLineArguments(java.lang.String[] args) throws UnknownArgumentException
Initializes the property provider with an 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.- Throws:
UnknownArgumentException
- if the list of command line arguments contains a property that was not previously configured and this check is not disabled.
-
provideProperty
void provideProperty(Property prop)
Adds precisely one property that can be used at runtime.
-
providePropertyList
void providePropertyList(java.util.List<Property> props)
Configures a list of valid properties to be used at runtime.
-
getAllValidProperties
java.util.List<Property> getAllValidProperties()
- Returns:
- all previously configured properties.
-
enableValidateConfig
void enableValidateConfig()
Enables stringent validation of the configuration.- See Also:
InitWithCommandLineArguments(String[])
-
disableValidateConfig
void disableValidateConfig()
Disables stringent validation of the configuration.- See Also:
InitWithCommandLineArguments(String[])
-
getBooleanProperty
boolean getBooleanProperty(java.lang.String key) throws MissingArgumentException, InvalidArgumentException
A property getter for Boolean properties.- Throws:
MissingArgumentException
- if no such property could be found.InvalidArgumentException
-
getClassProperty
java.lang.Class<?> getClassProperty(java.lang.String key) throws MissingArgumentException, InvalidArgumentException
A property getter for class properties.- Throws:
InvalidArgumentException
- if the property value cannot be converted into a valid class.MissingArgumentException
- if no such property can be found.
-
getFileProperty
java.io.File getFileProperty(java.lang.String key) throws MissingArgumentException, InvalidArgumentException
A property getter forFile
properties.- Returns:
- A file object created with
File(java.lang.String)
. - Throws:
MissingArgumentException
- if no such property could be found.InvalidArgumentException
-
getIntegerProperty
int getIntegerProperty(java.lang.String key) throws MissingArgumentException, InvalidArgumentException
A property getter for integer properties.- Throws:
InvalidArgumentException
- if the property value cannot be converted into an integer.MissingArgumentException
- if no such property can be found.
-
getStringProperty
java.lang.String getStringProperty(java.lang.String key) throws MissingArgumentException
A property getter for string properties.- Throws:
MissingArgumentException
- if no such property can be found.
-
getEnumProperty
<T extends java.lang.Enum<T>> T getEnumProperty(java.lang.Class<T> cls, java.lang.String key) throws MissingArgumentException, InvalidArgumentException
A property getter for enumeration type.- Parameters:
cls
- the property's enumeration typekey
- the key value- Returns:
- an instance of the enumeration
- Throws:
InvalidArgumentException
MissingArgumentException
- if no such property can be found.
-
getOptionalBooleanProperty
boolean getOptionalBooleanProperty(java.lang.String key) throws InvalidArgumentException
Tries to invokegetBooleanProperty(String)
and returns the given value, otherwise the configured default value is returned.- Parameters:
key
- the argument key value- Returns:
- true, if the property's string value is "true", otherwise false
- Throws:
InvalidArgumentException
-
getOptionalClassProperty
java.lang.Class<?> getOptionalClassProperty(java.lang.String key) throws InvalidArgumentException
Tries to invokegetClassProperty(String)
- Parameters:
key
- the argument key value- Returns:
- the given value, otherwise the configured default value
- Throws:
InvalidArgumentException
- in case the given string cannot be converted into a valid class.
-
getOptionalFileProperty
java.io.File getOptionalFileProperty(java.lang.String key) throws InvalidArgumentException
Tries to invokegetFileProperty(String)
- Returns:
- the given value, otherwise the configured default value
- Throws:
InvalidArgumentException
-
getOptionalIntegerProperty
int getOptionalIntegerProperty(java.lang.String key) throws InvalidArgumentException
InvokesgetIntegerProperty()
- Returns:
- its result if defined, otherwise the configured default value
- Throws:
InvalidArgumentException
- If the property's string value cannot be converted into an integer.
-
getOptionalStringProperty
java.lang.String getOptionalStringProperty(java.lang.String key)
InvokesgetStringProperty()
- Returns:
- its result if defined, otherwise the configured default value
-
getOptionalEnumProperty
<T extends java.lang.Enum<T>> T getOptionalEnumProperty(java.lang.Class<T> cls, java.lang.String key) throws InvalidArgumentException
Tries to invokegetEnumProperty(Class, String)
- Parameters:
cls
- the property's enumeration typekey
- 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.
-
getClassListProperty
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
.- 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
java.io.File[] getFileListProperty(java.lang.String key) throws MissingArgumentException, InvalidArgumentException
Gets a list of files given with a string property value. The single file specifications must be separated byFile.pathSeparator
.- Returns:
- an array of file instances.
- Throws:
MissingArgumentException
- if no such property can be found.InvalidArgumentException
-
getOptionalClassListProperty
java.lang.Class<?>[] getOptionalClassListProperty(java.lang.String key, java.lang.Class<?>[] defaultValue) throws InvalidArgumentException
InvokesgetClassListProperty()
- 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
java.io.File[] getOptionalFileListProperty(java.lang.String key, java.io.File[] defaultValue)
InvokesgetFileListProperty()
- Returns:
- its result if defined, otherwise the configured default value
-
-