public class XmlConfigurationContext extends Object implements ConfigurationContext, ResourceSource
ConfigurationContext
obtaining ConfigurationItem
instances
from a single XML file.
This reduces the number of files required for unit testing.
Constructor and Description |
---|
XmlConfigurationContext(Object offsetObject,
String singleXmlFileName)
Obtains the
ConfigurationContext contained in the XML file found
in the package of the offset object. |
Modifier and Type | Method and Description |
---|---|
void |
addTag(String tagName,
String tagReplaceValue)
Adds tag replacement of the raw XML text before it is parsed and divided
into
ConfigurationItem instances. |
ConfigurationItem |
createConfigurationItem(String relativeLocation,
InputStream configuration)
Creates a new
ConfigurationItem at the relative location. |
void |
deleteConfigurationItem(String relativeLocation)
Deletes the
ConfigurationItem at the relative location. |
ConfigurationItem |
getConfigurationItem(String relativeLocation)
Obtains the
ConfigurationItem at the relative location. |
String |
getLocation()
Obtains the location for this
ConfigurationContext . |
boolean |
isReadOnly()
Indicates if the configuration is read-only.
|
InputStream |
sourceResource(String location)
Attempts to source the resource.
|
public XmlConfigurationContext(Object offsetObject, String singleXmlFileName) throws Exception
ConfigurationContext
contained in the XML file found
in the package of the offset object.offsetObject
- Offset object identifying the package containing the XML file.
This is typically the TestCase
class.singleXmlFileName
- Name of the XML file.Exception
- If fails to initialise.public void addTag(String tagName, String tagReplaceValue)
ConfigurationItem
instances.tagName
- Name of the tag. This will replace ${tagName}
text with the tag replace value.tagReplaceValue
- Value to replace the tag with.public InputStream sourceResource(String location)
ResourceSource
sourceResource
in interface ResourceSource
location
- Location of the resource.InputStream
to the content of the resource or
null
if not able to source the resource.public String getLocation()
ConfigurationContext
Obtains the location for this ConfigurationContext
.
This value is used in the equality of ConfigurationContext
instances.
getLocation
in interface ConfigurationContext
ConfigurationContext
.public ConfigurationItem getConfigurationItem(String relativeLocation) throws Exception
ConfigurationContext
ConfigurationItem
at the relative location.getConfigurationItem
in interface ConfigurationContext
relativeLocation
- Relative location of the ConfigurationItem
to obtain.ConfigurationItem
.Exception
- If can not obtain a ConfigurationItem
at the relative
location.public boolean isReadOnly()
ConfigurationContext
isReadOnly
in interface ConfigurationContext
true
should the configuration be read-only.public ConfigurationItem createConfigurationItem(String relativeLocation, InputStream configuration) throws Exception
ConfigurationContext
ConfigurationItem
at the relative location.createConfigurationItem
in interface ConfigurationContext
relativeLocation
- Relative location of the ConfigurationItem
to create.configuration
- Configuration for the ConfigurationItem
.ConfigurationItem
.Exception
- If fails to create the ConfigurationItem
.ReadOnlyConfigurationException
- Should the underlying implementation be read-only.public void deleteConfigurationItem(String relativeLocation) throws Exception, ReadOnlyConfigurationException
ConfigurationContext
ConfigurationItem
at the relative location.deleteConfigurationItem
in interface ConfigurationContext
relativeLocation
- Relative location of the ConfigurationItem
to delete.Exception
- If can not delete the ConfigurationItem
at the
relative location.ReadOnlyConfigurationException
- Should the underlying implementation be read-only.Copyright © 2005–2016. All rights reserved.