Class XmlConfiguration
Configures objects from XML.
This class reads an XML file conforming to the configure.dtd DTD and uses it to configure and object by calling set, put or other methods on the object.
The actual XML file format may be changed (eg to spring XML) by implementing the
ConfigurationProcessorFactory
interface 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.
The configuration can be parameterised with properties that are looked up via the
Property XML element and set on the configuration via the map returned from
getProperties()
The configuration can create and lookup beans by ID. If multiple configurations are used, then it
is good practise to copy the entries from the getIdMap()
of a configuration to the next
configuration so that they can share an ID space for beans.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static class
private static class
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final Class<?>[]
private static final Iterable<ConfigurationProcessorFactory>
private static final Pool<XmlConfiguration.ConfigurationParser>
private static final Class<?>[]
private static final Class<?>[]
private final String
private final Resource
private ConfigurationProcessor
static final Comparator<Executable>
private static final Logger
-
Constructor Summary
ConstructorsConstructorDescriptionXmlConfiguration
(InputStream configuration) Deprecated.use Constructor which has location informationXmlConfiguration
(String configuration) Deprecated.use Constructor which has location informationXmlConfiguration
(URL configuration) Deprecated.useXmlConfiguration(org.eclipse.jetty.util.resource.Resource)
instead due to escaping issuesXmlConfiguration
(Resource resource) Reads and parses the XML configuration file. -
Method Summary
Modifier and TypeMethodDescriptionApplies the XML configuration script.Applies the XML configuration script to the given object.getIdMap()
Get the map of ID String to Objects that is used to hold and lookup any objects by ID.private static List<XmlParser.Node>
getNodes
(XmlParser.Node node, String elementName) (package private) XmlConfiguration.ConfigurationParser
Get the map of properties used by the Property XML element to parametrize configuration.void
initializeDefaults
(Object object) Initialize a new Object defaults.static void
Runs the XML configurations as a main application.static String
normalizeURI
(String uri) private void
setConfig
(XmlParser.Node config) void
setJettyStandardIdsAndProperties
(Object server, Resource webapp) Set the standard IDs and properties expected in a jetty XML file: RefId Server Property jetty.home Property jetty.home.uri Property jetty.base Property jetty.base.uri Property jetty.webapps Property jetty.webapps.uritoString()
-
Field Details
-
LOG
-
__primitives
-
__boxedPrimitives
-
__supportedCollections
-
__factoryLoader
-
__parsers
-
EXECUTABLE_COMPARATOR
-
_idMap
-
_propertyMap
-
_location
-
_dtd
-
_processor
-
-
Constructor Details
-
XmlConfiguration
Reads and parses the XML configuration file.- Parameters:
resource
- the Resource to the XML configuration- Throws:
IOException
- if the configuration could not be readSAXException
- if the configuration could not be parsed
-
XmlConfiguration
Deprecated.useXmlConfiguration(org.eclipse.jetty.util.resource.Resource)
instead due to escaping issuesReads and parses the XML configuration file.- Parameters:
configuration
- the URL of the XML configuration- Throws:
IOException
- if the configuration could not be readSAXException
- if the configuration could not be parsed
-
XmlConfiguration
Deprecated.use Constructor which has location informationReads and parses the XML configuration string.- Parameters:
configuration
- String of XML configuration commands excluding the normal XML preamble. The String should start with a "<Configure ....>" element.- Throws:
IOException
- if the configuration could not be readSAXException
- if the configuration could not be parsed
-
XmlConfiguration
Deprecated.use Constructor which has location informationReads and parses the XML configuration stream.- Parameters:
configuration
- An input stream containing a complete configuration file- Throws:
IOException
- if the configuration could not be readSAXException
- if the configuration could not be parsed
-
-
Method Details
-
setJettyStandardIdsAndProperties
Set the standard IDs and properties expected in a jetty XML file:- RefId Server
- Property jetty.home
- Property jetty.home.uri
- Property jetty.base
- Property jetty.base.uri
- Property jetty.webapps
- Property jetty.webapps.uri
- Parameters:
server
- The Server object to setwebapp
- The webapps Resource
-
normalizeURI
-
getParser
XmlConfiguration.ConfigurationParser getParser() -
toString
-
setConfig
-
getIdMap
Get the map of ID String to Objects that is used to hold and lookup any objects by ID.A New, Get or Call XML element may have an id attribute which will cause the resulting object to be placed into this map. A Ref XML element will lookup an object from this map.
When chaining configuration files, it is good practise to copy the ID entries from the ID map to the map of the next configuration, so that they may share an ID space
- Returns:
- A modifiable map of ID strings to Objects
-
getProperties
Get the map of properties used by the Property XML element to parametrize configuration.- Returns:
- A modifiable map of properties.
-
configure
Applies the XML configuration script to the given object.- Parameters:
obj
- The object to be configured, which must be of a type or super type of the class attribute of the <Configure> element.- Returns:
- the configured object
- Throws:
Exception
- if the configuration fails
-
configure
Applies the XML configuration script. If the root element of the configuration has an ID, an object is looked up by ID and its type checked against the root element's type. Otherwise a new object of the type specified by the root element is created.- Returns:
- The newly created configured object.
- Throws:
Exception
- if the configuration fails
-
initializeDefaults
Initialize a new Object defaults.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.- Parameters:
object
- the object to initialize defaults on
-
getNodes
-
main
Runs the XML configurations as a main application. The command line is used to obtain properties files (must be named '*.properties') and XmlConfiguration files.Any property file on the command line is added to a combined Property instance that is passed to each configuration file via
getProperties()
.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 ofLifeCycle
, then it is started.Any IDs created in a configuration are passed to the next configuration file on the command line using
getIdMap()
. This allows objects with IDs created in one config file to be referenced in subsequent config files on the command line.
-