Class ConfigBase<T extends ConfigBase>
- java.lang.Object
-
- org.bedework.util.config.ConfigBase<T>
-
- 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 Listprops; Also collection getters require a name for the collection element
@ConfInfo(collectionElementName = "prop")
public ListgetProps() { 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 ConfigBaseimplements MyConf { ... } - Author:
- Mike Douglass
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description ConfigBase()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description <L extends List>
LaddListProperty(L list, String name, String val)intcompareTo(ConfigBase that)ConfigBasefromXml(InputStream is)XML root element must have type attributeConfigBasefromXml(InputStream is, Class cl)XML root element must have type attribute if cl is nullConfigBasefromXml(Element rootEl, Class cl)XML root element must have type attributelonggetLastChanged()org.bedework.util.logging.BwLoggergetLogger()StringgetName()Name for the configuration.StringgetProperty(Collection<String> col, String name)Get a property stored as a String name = valinthashCode()voidmarkChanged()voidremoveProperty(Collection<String> col, String name)Remove a property stored as a String name = val<L extends List>
LsetListProperty(L list, String name, String val)Set a propertyvoidsetName(String val)static PropertiestoProperties(List<String> vals)StringtoString()voidtoStringSegment(org.bedework.util.misc.ToString ts)Add our stuff to the StringBuildervoidtoXml(Writer wtr)Output to a writer-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.bedework.util.logging.Logged
audit, debug, debug, enableAuditLogger, enableErrorLogger, enableMetricsLogger, error, error, error, getLogLevel, info, isAuditLoggerEnabled, isErrorLoggerEnabled, isMetricsDebugEnabled, isMetricsLoggerEnabled, metrics, setLoggerClass, setLoggerClass, trace, trace, warn
-
-
-
-
Field Detail
-
ns
public static final String ns
The default namespace for the XML elements.- See Also:
- Constant Field Values
-
-
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
-
compareTo
public int compareTo(ConfigBase that)
- Specified by:
compareToin interfaceComparable<T extends ConfigBase>
-
addListProperty
public <L extends List> L addListProperty(L list, String name, String val)
- Parameters:
list-name- of propertyval-- 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+valname- 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 nullname- of propertyval- 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
-
toXml
public void toXml(Writer wtr) throws ConfigException
Output to a writer- Parameters:
wtr-- Throws:
ConfigException
-
fromXml
public ConfigBase fromXml(InputStream is) throws ConfigException
XML root element must have type attribute- Parameters:
is- an input stream- Returns:
- parsed notification or null
- Throws:
ConfigException- on error
-
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 streamcl- 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 documentcl- class of object or null- Returns:
- parsed notification or null
- Throws:
ConfigException- on error
-
getLogger
public org.bedework.util.logging.BwLogger getLogger()
- Specified by:
getLoggerin interfaceorg.bedework.util.logging.Logged
-
-