|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.norconex.commons.lang.config.ConfigurationUtil
public final class ConfigurationUtil
Utility methods when dealing with configuration files.
Method Summary | ||
---|---|---|
static void |
assertWriteRead(IXMLConfigurable xmlConfiurable)
Convenience class for testing that a IXMLConfigurable instance
can be written, and read into an new instance that is equal as per
Object.equals(Object) . |
|
static XMLConfiguration |
getXmlAt(HierarchicalConfiguration node,
String key)
This method is the same as HierarchicalConfiguration.configurationAt(String) , except that
it first checks if the key exists before attempting to retrieve it,
and returns null on missing keys instead of an
IllegalArgumentException |
|
static
|
newInstance(HierarchicalConfiguration node)
Creates a new instance of the class represented by the "class" attribute on the given node. |
|
static
|
newInstance(HierarchicalConfiguration node,
boolean supportXMLConfigurable)
Creates a new instance of the class represented by the "class" attribute on the given node. |
|
static
|
newInstance(HierarchicalConfiguration node,
String key)
Creates a new instance of the class represented by the "class" attribute on the sub-node of the node argument, matching the key provided. |
|
static
|
newInstance(HierarchicalConfiguration node,
String key,
boolean supportXMLConfigurable)
Creates a new instance of the class represented by the "class" attribute on the sub-node of the node argument, matching the key provided. |
|
static
|
newInstance(HierarchicalConfiguration node,
String key,
T defaultObject)
Creates a new instance of the class represented by the "class" attribute on the sub-node of the node argument, matching the key provided. |
|
static
|
newInstance(HierarchicalConfiguration node,
String key,
T defaultObject,
boolean supportXMLConfigurable)
Creates a new instance of the class represented by the "class" attribute on the sub-node of the node argument, matching the key provided. |
|
static
|
newInstance(HierarchicalConfiguration node,
T defaultObject)
Creates a new instance of the class represented by the "class" attribute on the given node. |
|
static
|
newInstance(HierarchicalConfiguration node,
T defaultObject,
boolean supportXMLConfigurable)
Creates a new instance of the class represented by the "class" attribute on the given node. |
|
static Reader |
newReader(HierarchicalConfiguration node)
Creates a new Reader from a XMLConfiguration . |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static <T> T newInstance(HierarchicalConfiguration node)
IXMLConfigurable
, the object
created will be automatically populated by invoking the
IXMLConfigurable.loadFromXML(Reader)
method,
passing it the node XML automatically populated.
node
- the node representing the class to instantiate.
ConfigurationException
- if instance cannot be created/populatedpublic static <T> T newInstance(HierarchicalConfiguration node, boolean supportXMLConfigurable)
IXMLConfigurable
and
supportXMLConfigurable
is true, the object created
will be automatically populated by invoking the
IXMLConfigurable.loadFromXML(Reader)
method,
passing it the node XML automatically populated.
node
- the node representing the class to instantiate.supportXMLConfigurable
- automatically populates the object from XML
if it is implementing IXMLConfigurable
.
ConfigurationException
- if instance cannot be created/populatedpublic static <T> T newInstance(HierarchicalConfiguration node, T defaultObject)
IXMLConfigurable
, the object
created will be automatically populated by invoking the
IXMLConfigurable.loadFromXML(Reader)
method,
passing it the node XML automatically populated.
node
- the node representing the class to instantiate.defaultObject
- if returned object is null or undefined,
returns this default object.
ConfigurationException
- if instance cannot be created/populatedpublic static <T> T newInstance(HierarchicalConfiguration node, T defaultObject, boolean supportXMLConfigurable)
IXMLConfigurable
and
supportXMLConfigurable
is true, the object created
will be automatically populated by invoking the
IXMLConfigurable.loadFromXML(Reader)
method,
passing it the node XML automatically populated.
node
- the node representing the class to instantiate.defaultObject
- if returned object is null or undefined,
returns this default object.supportXMLConfigurable
- automatically populates the object from XML
if it is implementing IXMLConfigurable
.
ConfigurationException
- if instance cannot be created/populatedpublic static <T> T newInstance(HierarchicalConfiguration node, String key)
IXMLConfigurable
, the object
created will be automatically populated by invoking the
IXMLConfigurable.loadFromXML(Reader)
method,
passing it the node XML automatically populated.
node
- the node representing the class to instantiate.key
- sub-node name/hierarchical path
ConfigurationException
- if instance cannot be created/populatedpublic static <T> T newInstance(HierarchicalConfiguration node, String key, boolean supportXMLConfigurable)
IXMLConfigurable
and
supportXMLConfigurable
is true, the object created
will be automatically populated by invoking the
IXMLConfigurable.loadFromXML(Reader)
method,
passing it the node XML automatically populated.
node
- the node representing the class to instantiate.key
- sub-node name/hierarchical pathsupportXMLConfigurable
- automatically populates the object from XML
if it is implementing IXMLConfigurable
.
ConfigurationException
- if instance cannot be created/populatedpublic static <T> T newInstance(HierarchicalConfiguration node, String key, T defaultObject)
IXMLConfigurable
, the object
created will be automatically populated by invoking the
IXMLConfigurable.loadFromXML(Reader)
method,
passing it the node XML automatically populated.
node
- the node representing the class to instantiate.defaultObject
- if returned object is null or undefined,
returns this default object.key
- sub-node name/hierarchical path
ConfigurationException
- if instance cannot be created/populatedpublic static <T> T newInstance(HierarchicalConfiguration node, String key, T defaultObject, boolean supportXMLConfigurable)
IXMLConfigurable
and
supportXMLConfigurable
is true, the object created
will be automatically populated by invoking the
IXMLConfigurable.loadFromXML(Reader)
method,
passing it the node XML automatically populated.
node
- the node representing the class to instantiate.defaultObject
- if returned object is null or undefined,
returns this default object.key
- sub-node name/hierarchical pathsupportXMLConfigurable
- automatically populates the object from XML
if it is implementing IXMLConfigurable
.
ConfigurationException
- if instance cannot be created/populatedpublic static Reader newReader(HierarchicalConfiguration node) throws IOException
Reader
from a XMLConfiguration
.
Do not forget to close the reader instance when you are done with it.
node
- the xml configuration to convert to a reader instance.
ConfigurationException
- cannot read configuration
IOException
- cannot read configurationpublic static XMLConfiguration getXmlAt(HierarchicalConfiguration node, String key)
HierarchicalConfiguration.configurationAt(String)
, except that
it first checks if the key exists before attempting to retrieve it,
and returns null
on missing keys instead of an
IllegalArgumentException
node
- the tree to extract a sub tree fromkey
- the key that selects the sub tree
public static void assertWriteRead(IXMLConfigurable xmlConfiurable) throws IOException
IXMLConfigurable
instance
can be written, and read into an new instance that is equal as per
Object.equals(Object)
.
xmlConfiurable
- the instance to test if it writes/read properly
IOException
- Cannot read/write
ConfigurationException
- Cannot load configuration
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |