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

public class ConfigStore extends Object implements Cloneable
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.
  • Field Details

    • logger

      public static final org.slf4j.Logger logger
    • PROP_SUBSTORES

      protected static final String PROP_SUBSTORES
      See Also:
    • mStoreName

      protected String mStoreName
      The name of this substore
    • mSource

      protected SimpleProperties mSource
      The source data for this substore
    • storage

      protected ConfigStorage storage
  • Constructor Details

    • ConfigStore

      public ConfigStore()
    • ConfigStore

      public ConfigStore(ConfigStorage storage)
    • ConfigStore

      public ConfigStore(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
    • ConfigStore

      protected ConfigStore(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:
      name - store name
      source - list of properties
      Throws:
      EBaseException - failed to create configuration
  • Method Details

    • getName

      public String getName()
      Returns the name of this store.
      Returns:
      store name
    • getStorage

      public ConfigStorage getStorage()
    • get

      public String get(String name)
      Retrieves a property from the configuration file.
      Parameters:
      name - property name
      Returns:
      property value
    • put

      public String put(String name, String value)
      Puts a property into the configuration file. The values wont be updated to the file until save method is invoked.
      Parameters:
      name - property name
      value - property value
    • remove

      public void remove(String name)
      Removes a property from the configuration file.
      Parameters:
      name - property name
    • keys

      public Enumeration<String> keys()
      Returns an enumeration of the config store's keys, hidding the store name.
      Returns:
      a list of keys
      See Also:
    • getProperties

      public Map<String,String> 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

      public void load() throws Exception
      Load config from storage storage (file or LDAP).
      Throws:
      Exception - If an error occurs while loading.
    • commit

      public void commit(boolean createBackup) throws EBaseException
      Store config into storage (file or LDAP).
      Parameters:
      createBackup - true if a backup file should be created
      Throws:
      EBaseException - failed to commit
    • load

      public void load(InputStream in) throws IOException
      Reads a config store from an input stream.
      Parameters:
      in - input stream where properties are located
      Throws:
      IOException - failed to load
    • store

      public void store(OutputStream out) throws Exception
      Stores this config store to the specified output stream.
      Parameters:
      out - outputstream where the properties are saved
      Throws:
      Exception
    • getString

      public String getString(String name) throws EBaseException
      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 present
      EBaseException - If an internal error occurred
    • getString

      public String getString(String name, String defval) throws EBaseException
      Retrieves the value of a given property as a string or the given default value if the property is not present.
      Parameters:
      name - property name
      defval - the default object to return if name does not exist
      Returns:
      property value
      Throws:
      EBaseException - If an internal error occurred
    • putString

      public void putString(String name, String value)
      Puts property value into this configuration store.
      Parameters:
      name - property key
      value - property value
    • getByteArray

      public byte[] getByteArray(String name) throws EBaseException
      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 present
      IllegalArgumentException - if name is not set or is null.
      EBaseException
    • getByteArray

      public byte[] getByteArray(String name, byte[] defval) throws EBaseException
      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 property
      defval - 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

      public void putByteArray(String name, byte[] value)
      Puts byte array into this configuration store.
      Parameters:
      name - property key
      value - byte array
    • getBoolean

      public boolean getBoolean(String name) throws EBaseException
      Retrieves the given property as a boolean.
      Parameters:
      name - property key
      Returns:
      boolean value
      Throws:
      EPropertyNotFound - If the property is not present
      EBaseException - failed to retrieve
    • getBoolean

      public boolean getBoolean(String name, boolean defval) throws EBaseException
      Retrieves the given property as a boolean.
      Parameters:
      name - property key
      defval - default value
      Returns:
      boolean value
      Throws:
      EBaseException - failed to retrieve
    • putBoolean

      public void putBoolean(String name, boolean value)
      Puts boolean value into the configuration store.
      Parameters:
      name - property key
      value - property value
    • getInteger

      public int getInteger(String name) throws EBaseException
      Retrieves integer value.
      Parameters:
      name - The property name
      Returns:
      The property value as an integer
      Throws:
      EPropertyNotFound - If property is not found
      EBaseException - If an internal error occurred
    • getInteger

      public int getInteger(String name, int defval) throws EBaseException
      Retrieves integer value.
      Parameters:
      name - property key
      defval - default value
      Returns:
      property value
      Throws:
      EBaseException - failed to retrieve value
    • putInteger

      public void putInteger(String name, int val)
      Puts an integer value.
      Parameters:
      name - property key
      val - property value
    • getBigInteger

      public BigInteger getBigInteger(String name) throws EBaseException
      Retrieves the given property as a big integer.
      Parameters:
      name - property key
      Returns:
      property value
      Throws:
      EPropertyNotFound - If property is not found
      EBaseException - failed to retrieve value
    • getBigInteger

      public BigInteger getBigInteger(String name, BigInteger defval) throws EBaseException
      Retrieves the given property as a big integer.
      Parameters:
      name - property key
      defval - default value
      Returns:
      property value
      Throws:
      EBaseException - failed to retrieve value
    • putBigInteger

      public void putBigInteger(String name, BigInteger val)
      Puts a big integer value.
      Parameters:
      name - property key
      val - property value
    • makeSubStore

      public ConfigStore makeSubStore(String name)
      Creates a nested sub-store with the specified name.
      Parameters:
      name - The name of the sub-store
      Returns:
      The sub-store created
    • removeSubStore

      public void removeSubStore(String name)
      Removes a sub store including all properties and sub-stores under this sub-store.
      Parameters:
      name - substore name
    • getSubStore

      public ConfigStore getSubStore(String name)
      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

      public <T extends ConfigStore> T getSubStore(String name, Class<T> clazz)
    • getPropertyNames

      public Enumeration<String> getPropertyNames()
      Retrieves a list of property names.
      Returns:
      a list of string-based property names
    • getSubStoreNames

      public Enumeration<String> getSubStoreNames()
      Returns a list of sub store names.
      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 String getFullName(String name)
      Converts the substore parameters.
      Parameters:
      name - property name
      Returns:
      fill property name
    • clone

      public Object clone()
      Cloning of property configuration store.
      Overrides:
      clone in class Object
      Returns:
      a new configuration store