Package com.netscape.cmscore.base
Class PropConfigStore
- java.lang.Object
-
- com.netscape.cmscore.base.PropConfigStore
-
- All Implemented Interfaces:
IConfigStore
,java.lang.Cloneable
- Direct Known Subclasses:
AuthenticationConfig
,AuthManagerConfig
,AuthManagersConfig
,AuthorizationConfig
,AuthzManagerConfig
,AuthzManagersConfig
,DatabaseConfig
,EngineConfig
,LDAPAuthenticationConfig
,LDAPConfig
,LDAPConnectionConfig
,PKISocketConfig
,PreOpConfig
,SubsystemConfig
,SubsystemsConfig
,UGSubsystemConfig
public class PropConfigStore extends java.lang.Object implements IConfigStore, java.lang.Cloneable
A class represents a in-memory configuration store. 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 PropConfigStore, with longer mStoreName. IEcms.ca0.http.service0 -> mSource=PropConfigStore -> cms.ca0.http -> mSource=PropConfigStore -> cms.ca0 -> mSource=PropConfigStore -> cms -> mSource=SourceConfigStore -> Properties
The chain ends when the store name is reduced down to it's original value.- Version:
- $Revision$, $Date$
-
-
Field Summary
Fields Modifier and Type Field Description static org.slf4j.Logger
logger
protected SimpleProperties
mSource
The source data for this substoreprotected java.lang.String
mStoreName
The name of this substoreprotected static java.lang.String
PROP_SUBSTORES
protected ConfigStorage
storage
-
Constructor Summary
Constructors Modifier Constructor Description PropConfigStore()
PropConfigStore(ConfigStorage storage)
PropConfigStore(java.lang.String storeName)
Constructs a property configuration store.protected
PropConfigStore(java.lang.String name, SimpleProperties source)
Constructs a configuration store.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clear()
Clear the config store.java.lang.Object
clone()
Cloning of property configuration store.void
commit(boolean createBackup)
Store config into storage (file or LDAP).java.lang.String
get(java.lang.String name)
Retrieves a property from the configuration file.java.math.BigInteger
getBigInteger(java.lang.String name)
Retrieves big integer value.java.math.BigInteger
getBigInteger(java.lang.String name, java.math.BigInteger defval)
Retrieves integer value.boolean
getBoolean(java.lang.String name)
Retrieves boolean-based property value.boolean
getBoolean(java.lang.String name, boolean defval)
Retrieves boolean-based property value.byte[]
getByteArray(java.lang.String name)
Retrieves a byte array from the configuration file.byte[]
getByteArray(java.lang.String name, byte[] defval)
Retrieves a byte array from the configuration file.protected java.lang.String
getFullName(java.lang.String name)
Converts the substore parameters.int
getInteger(java.lang.String name)
Retrieves integer value.int
getInteger(java.lang.String name, int defval)
Retrieves integer value.java.lang.String
getName()
Returns the name of this store.java.util.Map<java.lang.String,java.lang.String>
getProperties()
Retrieves lexicographically sorted properties as a map.java.util.Enumeration<java.lang.String>
getPropertyNames()
Retrieves a list of property names.SimpleProperties
getSource()
Retrieves the source configuration store where the properties are stored.ConfigStorage
getStorage()
java.lang.String
getString(java.lang.String name)
Retrieves a property value.java.lang.String
getString(java.lang.String name, java.lang.String defval)
Retrieves a String from the configuration file.IConfigStore
getSubStore(java.lang.String name)
Retrieves a sub store.<T extends IConfigStore>
TgetSubStore(java.lang.String name, java.lang.Class<T> clazz)
java.util.Enumeration<java.lang.String>
getSubStoreNames()
Returns a list of sub store names.java.util.Enumeration<java.lang.String>
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(java.io.InputStream in)
Reads a config store from an input stream.IConfigStore
makeSubStore(java.lang.String name)
Creates a new sub store.void
printProperties()
For debugging purposes.java.lang.String
put(java.lang.String name, java.lang.String value)
Puts a property into the configuration file.void
putBigInteger(java.lang.String name, java.math.BigInteger val)
Puts a big integer value.void
putBoolean(java.lang.String name, boolean value)
Puts boolean value into the configuration store.void
putByteArray(java.lang.String name, byte[] value)
Puts byte array into this configuration store.void
putInteger(java.lang.String name, int val)
Puts an integer value.void
putString(java.lang.String name, java.lang.String value)
Puts property value into this configuration store.void
remove(java.lang.String name)
Removes a property from the configuration file.void
removeSubStore(java.lang.String name)
Removes a sub store.int
size()
Return the number of items in this substorevoid
store(java.io.OutputStream out)
Stores this config store to the specified output stream.
-
-
-
Field Detail
-
logger
public static final org.slf4j.Logger logger
-
PROP_SUBSTORES
protected static final java.lang.String PROP_SUBSTORES
- See Also:
- Constant Field Values
-
mStoreName
protected java.lang.String mStoreName
The name of this substore
-
mSource
protected SimpleProperties mSource
The source data for this substore
-
storage
protected ConfigStorage storage
-
-
Constructor Detail
-
PropConfigStore
public PropConfigStore()
-
PropConfigStore
public PropConfigStore(ConfigStorage storage)
-
PropConfigStore
public PropConfigStore(java.lang.String storeName)
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
-
PropConfigStore
protected PropConfigStore(java.lang.String name, SimpleProperties source)
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:
storeName
- store nameprop
- list of properties- Throws:
EBaseException
- failed to create configuration
-
-
Method Detail
-
getName
public java.lang.String getName()
Returns the name of this store.- Specified by:
getName
in interfaceIConfigStore
- Returns:
- store name
-
getStorage
public ConfigStorage getStorage()
-
get
public java.lang.String get(java.lang.String name)
Retrieves a property from the configuration file.- Specified by:
get
in interfaceIConfigStore
- Parameters:
name
- property name- Returns:
- property value
-
put
public java.lang.String put(java.lang.String name, java.lang.String value)
Puts a property into the configuration file. The values wont be updated to the file until save method is invoked.- Specified by:
put
in interfaceIConfigStore
- Parameters:
name
- property namevalue
- property value
-
remove
public void remove(java.lang.String name)
Removes a property from the configuration file.- Specified by:
remove
in interfaceIConfigStore
- Parameters:
name
- property name
-
keys
public java.util.Enumeration<java.lang.String> keys()
Returns an enumeration of the config store's keys, hidding the store name.- Specified by:
keys
in interfaceIConfigStore
- Returns:
- a list of keys
- See Also:
Hashtable.elements()
,Enumeration
-
getProperties
public java.util.Map<java.lang.String,java.lang.String> getProperties()
Retrieves lexicographically sorted properties as a map.- Specified by:
getProperties
in interfaceIConfigStore
- Returns:
- map
-
size
public int size()
Return the number of items in this substore- Specified by:
size
in interfaceIConfigStore
-
clear
public void clear()
Description copied from interface:IConfigStore
Clear the config store.- Specified by:
clear
in interfaceIConfigStore
-
load
public void load() throws java.lang.Exception
Description copied from interface:IConfigStore
Load config from storage storage (file or LDAP).- Specified by:
load
in interfaceIConfigStore
- Throws:
java.lang.Exception
- If an error occurs while loading.
-
commit
public void commit(boolean createBackup) throws EBaseException
Description copied from interface:IConfigStore
Store config into storage (file or LDAP).- Specified by:
commit
in interfaceIConfigStore
- Parameters:
createBackup
- true if a backup file should be created- Throws:
EBaseException
- failed to commit
-
load
public void load(java.io.InputStream in) throws java.io.IOException
Reads a config store from an input stream.- Specified by:
load
in interfaceIConfigStore
- Parameters:
in
- input stream where properties are located- Throws:
java.io.IOException
- failed to load
-
store
public void store(java.io.OutputStream out) throws java.lang.Exception
Stores this config store to the specified output stream.- Specified by:
store
in interfaceIConfigStore
- Parameters:
out
- outputstream where the properties are saved- Throws:
java.lang.Exception
-
getString
public java.lang.String getString(java.lang.String name) throws EBaseException
Retrieves a property value.- Specified by:
getString
in interfaceIConfigStore
- Parameters:
name
- property key- Returns:
- property value
- Throws:
EBaseException
- failed to retrieve value
-
getString
public java.lang.String getString(java.lang.String name, java.lang.String defval) throws EBaseException
Retrieves a String from the configuration file.- Specified by:
getString
in interfaceIConfigStore
- 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
public void putString(java.lang.String name, java.lang.String value)
Puts property value into this configuration store.- Specified by:
putString
in interfaceIConfigStore
- Parameters:
name
- property keyvalue
- property value
-
getByteArray
public byte[] getByteArray(java.lang.String name) throws EBaseException
Retrieves a byte array from the configuration file.- Specified by:
getByteArray
in interfaceIConfigStore
- Parameters:
name
- property name- Returns:
- property value
- Throws:
java.lang.IllegalArgumentException
- if name is not set or is null.EPropertyNotFound
- If the property is not presentEBaseException
- If an internal error occurred
-
getByteArray
public byte[] getByteArray(java.lang.String name, byte[] defval) throws EBaseException
Retrieves a byte array from the configuration file.- Specified by:
getByteArray
in interfaceIConfigStore
- Parameters:
name
- property namedefval
- the default byte array to return if name does not exist- Returns:
- property value
- Throws:
EBaseException
- If an internal error occurred
-
putByteArray
public void putByteArray(java.lang.String name, byte[] value)
Puts byte array into this configuration store.- Specified by:
putByteArray
in interfaceIConfigStore
- Parameters:
name
- property keyvalue
- byte array
-
getBoolean
public boolean getBoolean(java.lang.String name) throws EBaseException
Retrieves boolean-based property value.- Specified by:
getBoolean
in interfaceIConfigStore
- Parameters:
name
- property key- Returns:
- boolean value
- Throws:
EBaseException
- failed to retrieve
-
getBoolean
public boolean getBoolean(java.lang.String name, boolean defval) throws EBaseException
Retrieves boolean-based property value.- Specified by:
getBoolean
in interfaceIConfigStore
- Parameters:
name
- property keydefval
- default value- Returns:
- boolean value
- Throws:
EBaseException
- failed to retrieve
-
putBoolean
public void putBoolean(java.lang.String name, boolean value)
Puts boolean value into the configuration store.- Specified by:
putBoolean
in interfaceIConfigStore
- Parameters:
name
- property keyvalue
- property value
-
getInteger
public int getInteger(java.lang.String name) throws EBaseException
Retrieves integer value.- Specified by:
getInteger
in interfaceIConfigStore
- Parameters:
name
- property key- Returns:
- property value
- Throws:
EBaseException
- failed to retrieve value
-
getInteger
public int getInteger(java.lang.String name, int defval) throws EBaseException
Retrieves integer value.- Specified by:
getInteger
in interfaceIConfigStore
- Parameters:
name
- property keydefval
- default value- Returns:
- property value
- Throws:
EBaseException
- failed to retrieve value
-
putInteger
public void putInteger(java.lang.String name, int val)
Puts an integer value.- Specified by:
putInteger
in interfaceIConfigStore
- Parameters:
name
- property keyval
- property value- Throws:
EBaseException
- failed to retrieve value
-
getBigInteger
public java.math.BigInteger getBigInteger(java.lang.String name) throws EBaseException
Retrieves big integer value.- Specified by:
getBigInteger
in interfaceIConfigStore
- Parameters:
name
- property key- Returns:
- property value
- Throws:
EBaseException
- failed to retrieve value
-
getBigInteger
public java.math.BigInteger getBigInteger(java.lang.String name, java.math.BigInteger defval) throws EBaseException
Retrieves integer value.- Specified by:
getBigInteger
in interfaceIConfigStore
- Parameters:
name
- property keydefval
- default value- Returns:
- property value
- Throws:
EBaseException
- failed to retrieve value
-
putBigInteger
public void putBigInteger(java.lang.String name, java.math.BigInteger val)
Puts a big integer value.- Specified by:
putBigInteger
in interfaceIConfigStore
- Parameters:
name
- property keyval
- default value
-
makeSubStore
public IConfigStore makeSubStore(java.lang.String name)
Creates a new sub store.- Specified by:
makeSubStore
in interfaceIConfigStore
- Parameters:
name
- substore name- Returns:
- substore
-
removeSubStore
public void removeSubStore(java.lang.String name)
Removes a sub store.- Specified by:
removeSubStore
in interfaceIConfigStore
- Parameters:
name
- substore name
-
getSubStore
public IConfigStore getSubStore(java.lang.String name)
Retrieves a sub store. A substore contains a list of properties and substores. For example,cms.ldap.host=ds.netscape.com cms.ldap.port=389
"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,cms.ldap = kms.ldap
- Specified by:
getSubStore
in interfaceIConfigStore
- Parameters:
name
- substore name- Returns:
- substore
-
getSubStore
public <T extends IConfigStore> T getSubStore(java.lang.String name, java.lang.Class<T> clazz)
- Specified by:
getSubStore
in interfaceIConfigStore
-
getPropertyNames
public java.util.Enumeration<java.lang.String> getPropertyNames()
Retrieves a list of property names.- Specified by:
getPropertyNames
in interfaceIConfigStore
- Returns:
- a list of string-based property names
-
getSubStoreNames
public java.util.Enumeration<java.lang.String> getSubStoreNames()
Returns a list of sub store names.- Specified by:
getSubStoreNames
in interfaceIConfigStore
- Returns:
- list of substore names
-
getSource
public SimpleProperties 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
protected java.lang.String getFullName(java.lang.String name)
Converts the substore parameters.- Parameters:
name
- property name- Returns:
- fill property name
-
clone
public java.lang.Object clone()
Cloning of property configuration store.- Overrides:
clone
in classjava.lang.Object
- Returns:
- a new configuration store
-
-