Class ConfigBase<T extends ConfigBase>

  • Type Parameters:
    T -
    All Implemented Interfaces:
    Serializable, Comparable<T>, org.bedework.util.logging.Logged
    Direct Known Subclasses:
    HibernateConfigBase

    public class ConfigBase<T extends ConfigBase>
    extends Object
    implements org.bedework.util.logging.Logged, Comparable<T>, Serializable
    This class is used as a basis for configuration of system modules. The classes extending this MUST be annotated appropriately with ConfInfo and require setters and getters for all configuration fields.

    The class itself requires an element name annotation
    @ConfInfo(elementName="example-conf", type="defining-class")

    The type parameter is optional. If not specified the annotated class is the defining class otherwise it is the named class or interface

    The defining class specifies the getters and setters for the configuration fields. The actual class may have other getters and setters but these will not be dumped or restored.

    Collection fields MUST be either Set or List and the element class MUST be specified. For example:
    private List props;

    Also collection getters require a name for the collection element
    @ConfInfo(collectionElementName = "prop")
    public List getProps() {

    The ConfInfo annotation @ConfInfo(dontSave = true) allows for getters and setters of values used internally only.

    The dumped XML will have start elements with a type attribute. The value of that attribute is the actual class being dumped/restored.

    An example:

       public interface MyConf extends Serializable {
         ...
         void setMaxLength(final Integer val);
         ...
        @MBeanInfo("Max length")
         Integer getLength();
         ...
       }
    
       @ConfInfo(elementName = "my-conf",
               type = "my.package.MyConf")
      public class MyConfImpl extends ConfigBase
            implements MyConf {
        ...
      }
     
    Author:
    Mike Douglass
    See Also:
    Serialized Form
    • Constructor Detail

      • ConfigBase

        public ConfigBase()
    • Method Detail

      • setName

        public void setName​(String val)
        Parameters:
        val - the name
      • getName

        public String getName()
        Name for the configuration.
        Returns:
        String
      • markChanged

        public void markChanged()
      • getLastChanged

        public long getLastChanged()
      • toStringSegment

        public void toStringSegment​(org.bedework.util.misc.ToString ts)
        Add our stuff to the StringBuilder
        Parameters:
        ts - ToString for result
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
      • addListProperty

        public <L extends List> L addListProperty​(L list,
                                                  String name,
                                                  String val)
        Parameters:
        list -
        name - of property
        val -
        Returns:
        possibly newly created list
      • getProperty

        public String getProperty​(Collection<String> col,
                                  String name)
        Get a property stored as a String name = val
        Parameters:
        col - of property name+val
        name - of property
        Returns:
        value or null
      • removeProperty

        public void removeProperty​(Collection<String> col,
                                   String name)
        Remove a property stored as a String name = val
        Parameters:
        col -
        name - of property
      • setListProperty

        public <L extends List> L setListProperty​(L list,
                                                  String name,
                                                  String val)
        Set a property
        Parameters:
        list - the list - possibly null
        name - of property
        val - of property
        Returns:
        possibly newly created list
      • toProperties

        public static Properties toProperties​(List<String> vals)
        Parameters:
        vals - to be converted to a Properties object
        Returns:
        the Properties
      • fromXml

        public ConfigBase fromXml​(InputStream is,
                                  Class cl)
                           throws ConfigException
        XML root element must have type attribute if cl is null
        Parameters:
        is - an input stream
        cl - class of object or null
        Returns:
        parsed notification or null
        Throws:
        ConfigException - on error
      • fromXml

        public ConfigBase fromXml​(Element rootEl,
                                  Class cl)
                           throws ConfigException
        XML root element must have type attribute
        Parameters:
        rootEl - - root of parsed document
        cl - class of object or null
        Returns:
        parsed notification or null
        Throws:
        ConfigException - on error
      • getLogger

        public org.bedework.util.logging.BwLogger getLogger()
        Specified by:
        getLogger in interface org.bedework.util.logging.Logged