Package com.netscape.cmscore.base
Class ConfigStore
java.lang.Object
com.netscape.cmscore.base.ConfigStore
- All Implemented Interfaces:
Cloneable
- Direct Known Subclasses:
AuthenticationConfig
,AuthManagerConfig
,AuthManagersConfig
,AuthorizationConfig
,AuthzManagerConfig
,AuthzManagersConfig
,DatabaseConfig
,EngineConfig
,JssSubsystemConfig
,LDAPAuthenticationConfig
,LDAPConfig
,LDAPConnectionConfig
,PKISocketConfig
,PreOpConfig
,PublishingConfig
,PublishingMapperConfig
,PublishingPublisherConfig
,PublishingRuleConfig
,RandomConfig
,SSLConfig
,SubsystemConfig
,SubsystemsConfig
,UGSubsystemConfig
A class represents a in-memory configuration store.
A configuration store is an abstraction of a hierarchical store
to keep arbitrary data indexed by string names.
In the following example:
The top config store has parameters param1 and sub-stores configStore1 and configStore2.
The following illustrates how a config store is used. Note this class takes advantage of the recursive nature of property names. The current property prefix is kept in mStoreName and the mSource usually points back to another occurance of the same ConfigStore, with longer mStoreName. IE The chain ends when the store name is reduced down to it's original value.
The following illustrates how a config store is used. Note this class takes advantage of the recursive nature of property names. The current property prefix is kept in mStoreName and the mSource usually points back to another occurance of the same ConfigStore, with longer mStoreName. IE The chain ends when the store name is reduced down to it's original value.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final org.slf4j.Logger
protected SimpleProperties
The source data for this substoreprotected String
The name of this substoreprotected static final String
protected ConfigStorage
-
Constructor Summary
ConstructorsModifierConstructorDescriptionConfigStore
(ConfigStorage storage) ConfigStore
(String storeName) Constructs a property configuration store.protected
ConfigStore
(String name, SimpleProperties source) Constructs a configuration store. -
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
Clear the config store.clone()
Cloning of property configuration store.void
commit
(boolean createBackup) Store config into storage (file or LDAP).Retrieves a property from the configuration file.getBigInteger
(String name) Retrieves the given property as a big integer.getBigInteger
(String name, BigInteger defval) Retrieves the given property as a big integer.boolean
getBoolean
(String name) Retrieves the given property as a boolean.boolean
getBoolean
(String name, boolean defval) Retrieves the given property as a boolean.byte[]
getByteArray
(String name) Retrieves a byte array from the configuration file.byte[]
getByteArray
(String name, byte[] defval) Retrieves the value of a property as a byte array, using the given default value if property is not present.protected String
getFullName
(String name) Converts the substore parameters.int
getInteger
(String name) Retrieves integer value.int
getInteger
(String name, int defval) Retrieves integer value.getName()
Returns the name of this store.Retrieves lexicographically sorted properties as a map.Retrieves a list of property names.Retrieves the source configuration store where the properties are stored.Retrieves the value of the given property as a string.Retrieves the value of a given property as a string or the given default value if the property is not present.getSubStore
(String name) Retrieves a sub store.<T extends ConfigStore>
TgetSubStore
(String name, Class<T> clazz) Returns a list of sub store names.keys()
Returns an enumeration of the config store's keys, hidding the store name.void
load()
Load config from storage storage (file or LDAP).void
load
(InputStream in) Reads a config store from an input stream.makeSubStore
(String name) Creates a nested sub-store with the specified name.void
For debugging purposes.Puts a property into the configuration file.void
putBigInteger
(String name, BigInteger val) Puts a big integer value.void
putBoolean
(String name, boolean value) Puts boolean value into the configuration store.void
putByteArray
(String name, byte[] value) Puts byte array into this configuration store.void
putInteger
(String name, int val) Puts an integer value.void
Puts property value into this configuration store.void
Removes a property from the configuration file.void
removeSubStore
(String name) Removes a sub store including all properties and sub-stores under this sub-store.int
size()
Return the number of items in this substorevoid
store
(OutputStream out) Stores this config store to the specified output stream.
-
Field Details
-
logger
public static final org.slf4j.Logger logger -
PROP_SUBSTORES
- See Also:
-
mStoreName
The name of this substore -
mSource
The source data for this substore -
storage
-
-
Constructor Details
-
ConfigStore
public ConfigStore() -
ConfigStore
-
ConfigStore
Constructs a property configuration store. This must be a brand new store without properties. The subclass must be a SourceConfigStore.- Parameters:
storeName
- property store name- Throws:
EBaseException
- failed to create configuration
-
ConfigStore
Constructs a configuration store. The constructor is a helper class for substores. Source is the one that stores all the parameters. Each substore only store a substore name, and a reference to the source.- Parameters:
name
- store namesource
- list of properties- Throws:
EBaseException
- failed to create configuration
-
-
Method Details
-
getName
Returns the name of this store.- Returns:
- store name
-
getStorage
-
get
Retrieves a property from the configuration file.- Parameters:
name
- property name- Returns:
- property value
-
put
Puts a property into the configuration file. The values wont be updated to the file until save method is invoked.- Parameters:
name
- property namevalue
- property value
-
remove
Removes a property from the configuration file.- Parameters:
name
- property name
-
keys
Returns an enumeration of the config store's keys, hidding the store name.- Returns:
- a list of keys
- See Also:
-
getProperties
Retrieves lexicographically sorted properties as a map.- Returns:
- map
-
size
public int size()Return the number of items in this substore -
clear
public void clear()Clear the config store. -
load
Load config from storage storage (file or LDAP).- Throws:
Exception
- If an error occurs while loading.
-
commit
Store config into storage (file or LDAP).- Parameters:
createBackup
- true if a backup file should be created- Throws:
EBaseException
- failed to commit
-
load
Reads a config store from an input stream.- Parameters:
in
- input stream where properties are located- Throws:
IOException
- failed to load
-
store
Stores this config store to the specified output stream.- Parameters:
out
- outputstream where the properties are saved- Throws:
Exception
-
getString
Retrieves the value of the given property as a string.- Parameters:
name
- The name of the property to get- Returns:
- The value of the property as a String
- Throws:
EPropertyNotFound
- If the property is not presentEBaseException
- If an internal error occurred
-
getString
Retrieves the value of a given property as a string or the given default value if the property is not present.- Parameters:
name
- property namedefval
- the default object to return if name does not exist- Returns:
- property value
- Throws:
EBaseException
- If an internal error occurred
-
putString
Puts property value into this configuration store.- Parameters:
name
- property keyvalue
- property value
-
getByteArray
Retrieves a byte array from the configuration file.- Parameters:
name
- property name- Returns:
- The property value as a byte array
- Throws:
EPropertyNotFound
- If the property is not presentIllegalArgumentException
- if name is not set or is null.EBaseException
-
getByteArray
Retrieves the value of a property as a byte array, using the given default value if property is not present.- Parameters:
name
- The name of the propertydefval
- The default value if the property is not present.- Returns:
- The property value as a byte array.
- Throws:
EBaseException
- If an internal error occurred
-
putByteArray
Puts byte array into this configuration store.- Parameters:
name
- property keyvalue
- byte array
-
getBoolean
Retrieves the given property as a boolean.- Parameters:
name
- property key- Returns:
- boolean value
- Throws:
EPropertyNotFound
- If the property is not presentEBaseException
- failed to retrieve
-
getBoolean
Retrieves the given property as a boolean.- Parameters:
name
- property keydefval
- default value- Returns:
- boolean value
- Throws:
EBaseException
- failed to retrieve
-
putBoolean
Puts boolean value into the configuration store.- Parameters:
name
- property keyvalue
- property value
-
getInteger
Retrieves integer value.- Parameters:
name
- The property name- Returns:
- The property value as an integer
- Throws:
EPropertyNotFound
- If property is not foundEBaseException
- If an internal error occurred
-
getInteger
Retrieves integer value.- Parameters:
name
- property keydefval
- default value- Returns:
- property value
- Throws:
EBaseException
- failed to retrieve value
-
putInteger
Puts an integer value.- Parameters:
name
- property keyval
- property value
-
getBigInteger
Retrieves the given property as a big integer.- Parameters:
name
- property key- Returns:
- property value
- Throws:
EPropertyNotFound
- If property is not foundEBaseException
- failed to retrieve value
-
getBigInteger
Retrieves the given property as a big integer.- Parameters:
name
- property keydefval
- default value- Returns:
- property value
- Throws:
EBaseException
- failed to retrieve value
-
putBigInteger
Puts a big integer value.- Parameters:
name
- property keyval
- property value
-
makeSubStore
Creates a nested sub-store with the specified name.- Parameters:
name
- The name of the sub-store- Returns:
- The sub-store created
-
removeSubStore
Removes a sub store including all properties and sub-stores under this sub-store.- Parameters:
name
- substore name
-
getSubStore
Retrieves a sub store. A substore contains a list of properties and substores. For example, "ldap" is a substore in above example. If the substore property itself is set, this method will treat the value as a reference. For example,- Parameters:
name
- substore name- Returns:
- substore
-
getSubStore
-
getPropertyNames
Retrieves a list of property names.- Returns:
- a list of string-based property names
-
getSubStoreNames
Returns a list of sub store names.- Returns:
- list of substore names
-
getSource
Retrieves the source configuration store where the properties are stored.- Returns:
- source configuration store
-
printProperties
public void printProperties()For debugging purposes. Prints properties of this substore. -
getFullName
Converts the substore parameters.- Parameters:
name
- property name- Returns:
- fill property name
-
clone
Cloning of property configuration store.
-