public class XmlConfiguration extends Object
The actual XML file format may be changed (eg to spring XML) by implementing the ConfigurationProcessorFactory
interfaces to be found by the
ServiceLoader
by using the DTD and first tag element in the file. Note that DTD will be null if validation is off.
Constructor and Description |
---|
XmlConfiguration(InputStream configuration)
Reads and parses the XML configuration stream.
|
XmlConfiguration(String configuration)
Reads and parses the XML configuration string.
|
XmlConfiguration(URL configuration)
Reads and parses the XML configuration file.
|
Modifier and Type | Method and Description |
---|---|
Object |
configure()
Applies the XML configuration script.
|
Object |
configure(Object obj)
Applies the XML configuration script to the given object.
|
Map<String,Object> |
getIdMap() |
Map<String,String> |
getProperties() |
void |
initializeDefaults(Object object)
Initialize a new Object defaults.
|
static void |
main(String[] args)
Run the XML configurations as a main application.
|
void |
setIdMap(Map<String,Object> map)
Deprecated.
use
getIdMap() .put(...) |
void |
setProperties(Map<String,String> map)
Deprecated.
use
getProperties() .putAll(...) |
public XmlConfiguration(URL configuration) throws SAXException, IOException
configuration
- the URL of the XML configurationIOException
- if the configuration could not be readSAXException
- if the configuration could not be parsedpublic XmlConfiguration(String configuration) throws SAXException, IOException
configuration
- String of XML configuration commands excluding the normal XML preamble.
The String should start with a "<Configure ....>" element.IOException
- if the configuration could not be readSAXException
- if the configuration could not be parsedpublic XmlConfiguration(InputStream configuration) throws SAXException, IOException
configuration
- An input stream containing a complete configuration fileIOException
- if the configuration could not be readSAXException
- if the configuration could not be parsed@Deprecated public void setIdMap(Map<String,Object> map)
getIdMap()
.put(...)map
- the ID map@Deprecated public void setProperties(Map<String,String> map)
getProperties()
.putAll(...)map
- the properties mappublic Object configure(Object obj) throws Exception
obj
- The object to be configured, which must be of a type or super type
of the class attribute of the <Configure> element.Exception
- if the configuration failspublic Object configure() throws Exception
Exception
- if the configuration failspublic void initializeDefaults(Object object)
This method must be called by any ConfigurationProcessor
when it
creates a new instance of an object before configuring it, so that a derived
XmlConfiguration class may inject default values.
object
- public static void main(String[] args) throws Exception
Any property file on the command line is added to a combined Property instance that is passed to each configuration file via
setProperties(Map)
.
Each configuration file on the command line is used to create a new XmlConfiguration instance and the configure()
method is used
to create the configured object. If the resulting object is an instance of LifeCycle
, then it is started.
Any IDs created in a configuration are passed to the next configuration file on the command line using getIdMap()
and setIdMap(Map)
.
This allows objects with IDs created in one config file to be referenced in subsequent config files on the command line.
Copyright © 1995-2013 Mort Bay Consulting. All Rights Reserved.