Package com.jk.core.config
Class JKConfig
java.lang.Object
com.jk.core.config.JKConfig
This class provides an implementation of the configurations and provides ways
to access and manage the properties of these configurations.
- Version:
- 1.0
- Author:
- Dr. Jalal H. Kiswani
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static JKConfig
Represents the default configuration instance.protected static boolean
Represents a boolean value to show whether this object been initialized or not.protected static List<JKConfigListener>
Represents the configuration listeners. -
Constructor Summary
ConstructorsConstructorDescriptionJKConfig()
This constructor creates a new instance of theJKConfig
class.JKConfig
(Properties prop) This constructor creates a new instance of theJKConfig
class. -
Method Summary
Modifier and TypeMethodDescriptionstatic void
addListner
(JKConfigListener listener) This method add a new configuration listener to the internal configuration listeners list.void
addProperties
(Properties properties) This method adds all the properties specified to the configuration properties.void
close()
This method closes thisJKConfig
object and clears all the information and data stored within it.static JKConfig
get()
This method is used to access the default configuration instance.static JKConfig
This method returns the default configuration instance, if its null, it initiate it first before returning it.static List<JKConfigListener>
This method gets the list of configuration listeners list.getPassword
(String name) This method gets the property value that is associated with the property name specified, then returns the decrypted value.getPassword
(String name, String defaultPassword) This method gets the property value that is associated with the property name specified, then returns the decrypted value.getProperties
(String prefix) This method gets the configuration properties of theJKConfig
object.getProperty
(String name) This method gets the specified property value.getProperty
(String name, String defaultValue) This method gets the specifies property value, or the default value in case the property had a null value.boolean
getPropertyAsBoolean
(String name) This method gets the property value as boolean, using a default value offalse
.boolean
getPropertyAsBoolean
(String name, boolean defaultValue) This method gets the property value as boolean.getPropertyAsDate
(String name, Date defaultValue) This method gets the property value as date.double
getPropertyAsDouble
(String name, double defaultValue) This method gets the property value as double.int
getPropertyAsInteger
(String name) This method gets the property value as integer with a default value of0
int
getPropertyAsInteger
(String name, int defaultValue) This method gets the property value as integer.getPropertyAsTime
(String property) This method gets the property value as time.getPropertyAsTime
(String property, LocalTime defaultTime) This method gets the property value as time.This method gets a string associated with the given configuration property name with a default value ofnull
This method gets a string associated with the given configuration property name.static void
init()
This method initiate the default configuration instance by specifying all its needed attributes, while properly documenting the steps with the configuration logger.static boolean
This method checks whether thisJKConfig
object is initiated or not.protected static Properties
This method adds the configuration properties stored on cloud foundry..protected static Map
loadFromFile
(String fileName) This method loads up the file specified by the given URL.protected static Properties
This method adds the configuration properties stored on a smart cloud environment variables.static void
This is the main method that tests the methods available in theJKConfig
class.protected static Properties
processPreConfigToLoadConfig
(Properties allProperties) This method takes a set of pre-configured properties and performs processing to load additional configuration properties.static Properties
readConfigFromLocalFolder
(String appConfigFileName, File localPath) This method reads the configuration stored in a local file..static void
reset()
This method resets thisJKConfig
object by clearing all the data and information stored within it and resetting it to its initiated state.static void
setDefaultInstance
(JKConfig defaultInstance) This method replaces the default configuration instance with the specified instance.void
setPassword
(String name, String value) This method encrypt the property value provided before adding it with the rest of the configuration properties.void
setProperty
(String key, String value) This method sets a property, this will replace any previously set values.void
This method sets a property, this will replace any previously set values.This method returns all the current configuration properties of theJKConfig
object asProperties
object.toString()
Returns a string representation of the object.
-
Field Details
-
defaultInstance
Represents the default configuration instance. -
listeners
Represents the configuration listeners. -
initilized
protected static boolean initilizedRepresents a boolean value to show whether this object been initialized or not.
-
-
Constructor Details
-
JKConfig
public JKConfig()This constructor creates a new instance of theJKConfig
class.It creates an empty instance without any configurations.
-
JKConfig
This constructor creates a new instance of theJKConfig
class.It uses the specified properties as the configuration properties of the initiated object.
- Parameters:
prop
- Specifies the object configuration properties.
-
-
Method Details
-
getDefaultInstance
This method returns the default configuration instance, if its null, it initiate it first before returning it.- Returns:
- the default configuration instance.
-
init
public static void init()This method initiate the default configuration instance by specifying all its needed attributes, while properly documenting the steps with the configuration logger. -
loadFromFile
This method loads up the file specified by the given URL.- Parameters:
fileName
- Specifies the URL of the file needed to be loaded.- Returns:
- the properties read in the loaded file. returns an empty map if the given URL doesn't point to a valid location.
-
processPreConfigToLoadConfig
This method takes a set of pre-configured properties and performs processing to load additional configuration properties.- Parameters:
allProperties
- Specifies The pre-configured properties to be processed.- Returns:
- a new
Properties
object containing the pre-configured properties
-
readConfigFromLocalFolder
This method reads the configuration stored in a local file..- Parameters:
appConfigFileName
- Specifies the local file name that holds the configuration properties.localPath
- Specifies the local file path.- Returns:
- a new
Properties
object containing the configuration specified in the local file.
-
getProperty
This method gets the specified property value.- Parameters:
name
- Specifies the name of the property.- Returns:
- the property that was associated with the specified name.
-
getProperty
This method gets the specifies property value, or the default value in case the property had a null value.- Parameters:
name
- Specifies the name of the property.defaultValue
- Specifies the default value of the property.- Returns:
- the property value that is associated with the specified name. Returns the property default value if the property name points to a null property. returns null if there's no property with the specified name.
-
getPropertyAsInteger
This method gets the property value as integer.- Parameters:
name
- Specifies the property name.defaultValue
- Specifies the property default value.- Returns:
- the property value as an integer.
- See Also:
-
getPropertyAsDouble
This method gets the property value as double.- Parameters:
name
- Specifies the property name.defaultValue
- Specifies the property default value.- Returns:
- the property value as a double.
- See Also:
-
getPropertyAsBoolean
This method gets the property value as boolean, using a default value offalse
.- Parameters:
name
- Specifies the property name.- Returns:
- the property value as boolean.
- See Also:
-
getPropertyAsBoolean
This method gets the property value as boolean.- Parameters:
name
- Specifies the property name.defaultValue
- Specifies the property default value.- Returns:
- the property value as boolean.
- See Also:
-
getPropertyAsDate
This method gets the property value as date.- Parameters:
name
- Specifies the property name.defaultValue
- Specifies the property default value.- Returns:
- the property value as a date.
- See Also:
-
toString
Returns a string representation of the object. -
toProperties
This method returns all the current configuration properties of theJKConfig
object asProperties
object.This method ignores all the properties that have null values.
- Returns:
- configuration properties which this object is currently configured to.
-
setString
This method sets a property, this will replace any previously set values.This is implicitly a call to
clearProperty(name)
,addProperty(name, value)
.- Parameters:
name
- Specifies the property name.value
- Specifies the property value.- See Also:
-
clearProperty(key)
addProperty(key, value)
-
setPassword
This method encrypt the property value provided before adding it with the rest of the configuration properties.This will replace any previously set values.
- Parameters:
name
- Specifies the name of the property.value
- Specifies the property value to be encrypted.- See Also:
-
getString
This method gets a string associated with the given configuration property name. If the property name doesn't map to an existing object, the defaultValue is returned.- Parameters:
name
- Specifies the property name.defaultValue
- Specifies the property default value.- Returns:
- the string which the property name is associated with, or the default value if the property name specified doesn't map to an existing entry.
-
getPassword
This method gets the property value that is associated with the property name specified, then returns the decrypted value.This method uses a
null
password to decrypt the value.- Parameters:
name
- Specifies the property name.- Returns:
- the decrypted value associated with the property name.
-
getPassword
This method gets the property value that is associated with the property name specified, then returns the decrypted value.This method uses the provided password to decrypt the value.
- Parameters:
name
- Specifies the property name.defaultPassword
- Specifies the property default password used for decrypting the value.- Returns:
- the decrypted value.
-
loadFromFrameworkEnvironmentVariables
This method adds the configuration properties stored on a smart cloud environment variables.- Returns:
- a new
Properties
object containing the configuration specified in the smart cloud environment variables..
-
loadFromCloudFoundry
This method adds the configuration properties stored on cloud foundry..- Returns:
- a new
Properties
object containing the configuration specified in the smart cloud environment variables.
-
main
This is the main method that tests the methods available in theJKConfig
class.- Parameters:
args
- The command-line arguments.
-
getPropertyAsInteger
This method gets the property value as integer with a default value of0
- Parameters:
name
- Specifies the property name.- Returns:
- the specified property value as integer
- See Also:
-
getString
This method gets a string associated with the given configuration property name with a default value ofnull
- Parameters:
name
- Specifies the property name.- Returns:
- a string associated with the specified property name.
-
setDefaultInstance
This method replaces the default configuration instance with the specified instance.- Parameters:
defaultInstance
- Specifies the new default configuration instance.
-
reset
public static void reset()This method resets thisJKConfig
object by clearing all the data and information stored within it and resetting it to its initiated state. -
close
public void close()This method closes thisJKConfig
object and clears all the information and data stored within it.This method doesn't revert the object to its initiate state, to do that, check
reset()
instead. -
addListner
This method add a new configuration listener to the internal configuration listeners list.- Parameters:
listener
- Specifies the new listener to be added.
-
getListeners
This method gets the list of configuration listeners list.- Returns:
- a list view of the configuration listeners.
-
get
This method is used to access the default configuration instance.- Returns:
- the default configuration instance.
-
addProperties
This method adds all the properties specified to the configuration properties.This will replace the properties that share the same property name.
- Parameters:
properties
- Specifies the properties to be added to the configuration.
-
setProperty
This method sets a property, this will replace any previously set values.This is implicitly a call to
clearProperty(key)
,addProperty(key, value)
.- Parameters:
key
- Specifies the property name.value
- Specifies the property value.- See Also:
-
clearProperty(key)
addProperty(key, value)
-
getPropertyAsTime
This method gets the property value as time.- Parameters:
property
- Specifies the property.- Returns:
- the property value as time.
-
getPropertyAsTime
This method gets the property value as time. returns the default time value if the property value is null.- Parameters:
property
- Specifies the property.defaultTime
- Specifies the default property value as time- Returns:
- the property value as time. or the default time value if the property value is null.
-
isInitilized
public static boolean isInitilized()This method checks whether thisJKConfig
object is initiated or not.- Returns:
- true, if is initiated, false, otherwise.
-
getProperties
This method gets the configuration properties of theJKConfig
object.- Parameters:
prefix
- Specifies the properties prefix.- Returns:
- the properties stored within the
JKConfig
object.
-