Class PropConfigStore

    • 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>
      T
      getSubStore​(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 substore
      void store​(java.io.OutputStream out)
      Stores this config store to the specified output stream.
      • Methods inherited from class java.lang.Object

        equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • logger

        public static final org.slf4j.Logger logger
      • mStoreName

        protected java.lang.String mStoreName
        The name of this substore
    • 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:
        name - store name
        source - 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 interface IConfigStore
        Returns:
        store name
      • get

        public java.lang.String get​(java.lang.String name)
        Retrieves a property from the configuration file.

        Specified by:
        get in interface IConfigStore
        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 interface IConfigStore
        Parameters:
        name - property name
        value - property value
      • remove

        public void remove​(java.lang.String name)
        Removes a property from the configuration file.
        Specified by:
        remove in interface IConfigStore
        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 interface IConfigStore
        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 interface IConfigStore
        Returns:
        map
      • size

        public int size()
        Return the number of items in this substore
        Specified by:
        size in interface IConfigStore
      • clear

        public void clear()
        Description copied from interface: IConfigStore
        Clear the config store.
        Specified by:
        clear in interface IConfigStore
      • 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 interface IConfigStore
        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 interface IConfigStore
        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 interface IConfigStore
        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 interface IConfigStore
        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 interface IConfigStore
        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 interface IConfigStore
        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​(java.lang.String name,
                              java.lang.String value)
        Puts property value into this configuration store.
        Specified by:
        putString in interface IConfigStore
        Parameters:
        name - property key
        value - property value
      • getByteArray

        public byte[] getByteArray​(java.lang.String name)
                            throws EBaseException
        Retrieves a byte array from the configuration file.

        Specified by:
        getByteArray in interface IConfigStore
        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 present
        EBaseException - 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 interface IConfigStore
        Parameters:
        name - property name
        defval - 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 interface IConfigStore
        Parameters:
        name - property key
        value - byte array
      • getBoolean

        public boolean getBoolean​(java.lang.String name)
                           throws EBaseException
        Retrieves boolean-based property value.
        Specified by:
        getBoolean in interface IConfigStore
        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 interface IConfigStore
        Parameters:
        name - property key
        defval - 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 interface IConfigStore
        Parameters:
        name - property key
        value - property value
      • getInteger

        public int getInteger​(java.lang.String name)
                       throws EBaseException
        Retrieves integer value.
        Specified by:
        getInteger in interface IConfigStore
        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 interface IConfigStore
        Parameters:
        name - property key
        defval - 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 interface IConfigStore
        Parameters:
        name - property key
        val - 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 interface IConfigStore
        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 interface IConfigStore
        Parameters:
        name - property key
        defval - 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 interface IConfigStore
        Parameters:
        name - property key
        val - default value
      • makeSubStore

        public IConfigStore makeSubStore​(java.lang.String name)
        Creates a new sub store.

        Specified by:
        makeSubStore in interface IConfigStore
        Parameters:
        name - substore name
        Returns:
        substore
      • removeSubStore

        public void removeSubStore​(java.lang.String name)
        Removes a sub store.

        Specified by:
        removeSubStore in interface IConfigStore
        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 interface IConfigStore
        Parameters:
        name - substore name
        Returns:
        substore
      • getPropertyNames

        public java.util.Enumeration<java.lang.String> getPropertyNames()
        Retrieves a list of property names.
        Specified by:
        getPropertyNames in interface IConfigStore
        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 interface IConfigStore
        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 class java.lang.Object
        Returns:
        a new configuration store