Package lazyj
Class ExtProperties
java.lang.Object
java.util.Observable
lazyj.ExtProperties
- All Implemented Interfaces:
Observer
- Direct Known Subclasses:
DBProperties
,FallbackProperties
Utility class to process enhanced .properties file.
Such a file can have a special "include" key, which is a list of comma-separated file names (without the .properties extension) relative to the same base folder.
Each value can contain constructions like:
Such a file can have a special "include" key, which is a list of comma-separated file names (without the .properties extension) relative to the same base folder.
Each value can contain constructions like:
${other_key}
, to include the value of another key in that place
- Since:
- 2006-09-29
- Author:
- costing
-
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor, creates a configuration dictionary that has no file backing.Load the configuration from an InputStream (such as the one returned byClassLoader.getResourceAsStream(String)
ExtProperties
(String sBaseConfigDir, String sConfigFilename) Load the contents of a .properties file from the sConfDir path.ExtProperties
(String sBaseConfigDir, String sConfigFilename, ExtProperties superProperties) Load the contents of a .properties file from the sConfDir path.ExtProperties
(String sBaseConfigDir, String sConfigFilename, ExtProperties superProperties, boolean ignoreMissingIncludes) Load the contents of a .properties file from the sConfDir path.ExtProperties
(Properties inherit) Copy constructor -
Method Summary
Modifier and TypeMethodDescriptionvoid
addPropertyChangeListener
(String key, PropertyChangeListener listener) Listen for particular changes in the setvoid
Method to clear the cache in order to force the evaluation of the keys once again.boolean
Parse an option to return the boolean value.Get the name of the file that was loaded.double
Get the double value for a key.int
Get the integer value for a key.long
Get the long value for a key.Get a Properties view of this object.Get the String value for a given key.Get the String value for a given key, returning the given default value if the key is not defined.Get the String value for a given key, returning the given default value if the key is not defined.boolean
Check if the configuration object is read only or can accept modifications to itvoid
Make this dictionary read-only, to prevent writes from other pieces of code that see this object.parseOption
(String sKey, String sValue, String sDefault, boolean bProcessQueries) Parse a value to include other keysvoid
reload()
Re-read the same configuration file.void
removePropertyChangeListener
(String key, PropertyChangeListener listener) void
Modify an entry of the dictionary.void
setAutoReload
(long lReload) Make this object check for changes in the base file and reload the contents when it changes.int
size()
Get the number of elements in this dictionarytoString()
Get some debugging info for this objectSplit a value by "," and return a Vector of String parts.void
update
(Observable o, Object arg) Implementation of theObserver
interface.Methods inherited from class java.util.Observable
addObserver, clearChanged, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers, setChanged
-
Constructor Details
-
ExtProperties
public ExtProperties()Default constructor, creates a configuration dictionary that has no file backing. -
ExtProperties
Load the configuration from an InputStream (such as the one returned byClassLoader.getResourceAsStream(String)
- Parameters:
is
- input stream to read from- Throws:
IOException
- in case of problems while reading from the stream
-
ExtProperties
Load the contents of a .properties file from the sConfDir path.- Parameters:
sBaseConfigDir
- base folder for the configuration filessConfigFilename
- file to load, without the ".properties" extension, that will be automatically added
-
ExtProperties
Load the contents of a .properties file from the sConfDir path. If the pSuper parameter is not null then the values from the given ExtProperties are inherited. Any key defined in this class will override any inherited key.- Parameters:
sBaseConfigDir
- base folder for all the configuration filessConfigFilename
- file to load (without the ".properties" extension)superProperties
- other configuration to use as default (the keys from the current file will override the ones given as defaults)
-
ExtProperties
public ExtProperties(String sBaseConfigDir, String sConfigFilename, ExtProperties superProperties, boolean ignoreMissingIncludes) Load the contents of a .properties file from the sConfDir path. If the pSuper parameter is not null then the values from the given ExtProperties are inherited. Any key defined in this class will override any inherited key.- Parameters:
sBaseConfigDir
- base folder for all the configuration filessConfigFilename
- file to load (without the ".properties" extension)superProperties
- other configuration to use as default (the keys from the current file will override the ones given as defaults)ignoreMissingIncludes
- whether or not to ignore missing include files
-
ExtProperties
Copy constructor- Parameters:
inherit
- key-value pairs to copy
-
-
Method Details
-
size
public int size()Get the number of elements in this dictionary- Returns:
- number of entries
-
setAutoReload
public void setAutoReload(long lReload) Make this object check for changes in the base file and reload the contents when it changes.- Parameters:
lReload
-
-
getConfigFileName
Get the name of the file that was loaded. It will return the full path to the file name, eg. the base folder + file name + ".properties".- Returns:
- the file name that was loaded
-
reload
public void reload()Re-read the same configuration file. Also clears the cache of parsed keys. -
makeReadOnly
public void makeReadOnly()Make this dictionary read-only, to prevent writes from other pieces of code that see this object. -
parseOption
Parse a value to include other keys- Parameters:
sKey
- the key that is parsedsValue
- original valuesDefault
- default value, in case of an error in parsingbProcessQueries
- whether or not to execute database queries / cache lookups- Returns:
- the processed value
-
gets
Get the String value for a given key. If the key is not defined then the empty string is returned. Queries will be processed.- Parameters:
sKey
- the key to get the value for- Returns:
- the value
- See Also:
-
gets
Get the String value for a given key, returning the given default value if the key is not defined. Queries will be processed.- Parameters:
sKey
- the key to get the value forsDefault
- default value to return in case the key is not defined- Returns:
- the value
- See Also:
-
gets
Get the String value for a given key, returning the given default value if the key is not defined. The value that is returned is also stored in a cache so that future requests to the same key will return the value from the cache. This also means that if the key is not defined then the given default value will be cached and returned the next time this function is called.null
values are not cached.- Parameters:
sKey
- the key to get the value forsDefault
- default value to return in case the key is not defined.bProcessQueries
- flag to process or not process the database/memory cache queries- Returns:
- value for this key
-
getb
Parse an option to return the boolean value. It returns true if the value starts with t,T,y,Y or 1 and false if the value starts with f,F,n,N or 0. In any other case it returns the given default value.- Parameters:
sKey
- the key to get the value forbDefault
- default value- Returns:
- a boolean
-
geti
Get the integer value for a key. Returns the given default value if the key is not defined or the value is not an integer representation.- Parameters:
sKey
- the key to get the value foriDefault
- default value- Returns:
- an integer
-
getl
Get the long value for a key. Returns the given default value if the key is not defined or the value is not a long reprezentation.- Parameters:
sKey
- the key to get the value forlDefault
- default value- Returns:
- a long
-
getd
Get the double value for a key. Returns the given default value if the key is not defined or the value is not a double reprezentation.- Parameters:
sKey
- the key to get the value fordDefault
- default value- Returns:
- a double
-
toVector
Split a value by "," and return a Vector of String parts.- Parameters:
sKey
- the key to get the values for- Returns:
- a Vector of String parts
-
clearCache
public void clearCache()Method to clear the cache in order to force the evaluation of the keys once again. -
toString
Get some debugging info for this object -
isReadOnly
public boolean isReadOnly()Check if the configuration object is read only or can accept modifications to it- Returns:
true
if changes are blocked
-
set
Modify an entry of the dictionary.- Parameters:
sKey
- key to changesValue
- new value
-
getProperties
Get a Properties view of this object. This will force a parsing of all the defined keys.- Returns:
- a Properties view of this object
-
addPropertyChangeListener
Listen for particular changes in the set- Parameters:
key
- a particular property key to subscribe to, ornull
to receive all updateslistener
- object to notify
-
removePropertyChangeListener
- Parameters:
key
-listener
-
-
update
Implementation of theObserver
interface. Since this object can monitor the original file for changes, it will be notified by a call to this method when this happens.
-