Top Description Fields Constructors Methods
org.mortbay.xml

public Class XmlConfiguration

extends Object
Class Inheritance
Imports
java.io.IOException, .InputStream, .StringReader, java.lang.reflect.Constructor, .Field, .InvocationTargetException, .Method, .Modifier, java.net.InetAddress, .MalformedURLException, .URL, .UnknownHostException, java.util.HashMap, .Iterator, .Map, .Properties, org.mortbay.component.LifeCycle, org.mortbay.log.Log, org.mortbay.resource.Resource, org.mortbay.util.LazyList, .Loader, .TypeUtil, org.xml.sax.InputSource, .SAXException

Configure 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.
Author
Greg Wilkins (gregw)

Field Summary

Modifier and TypeField and Description
private static XmlParser
private static Class<T>[]
private static Class<T>[]
private XmlParser.Node
private Map<K, V>
private Map<K, V>
private static final Integer

Constructor Summary

AccessConstructor and Description
public
XmlConfiguration(URL configuration)

Constructor.

public
XmlConfiguration(String
String of XML configuration commands excluding the normal XML preamble. The String should start with a " configuration)

Constructor.

public
XmlConfiguration(InputStream
An input stream containing a complete e.g. configuration file
configuration
)

Constructor.

Method Summary

Modifier and TypeMethod and Description
private Object
public void
configure(Object
The object to be configured.
obj
)

Configure an object.

public Object

Returns:

The newly created configured object.
configure
()

Configure an object.

private void
configure(Object obj, XmlParser.Node cfg, int i)

private Object
get(Object obj, XmlParser.Node node)

public Map<K, V>
public Map<K, V>
private static synchronized void
private Object
itemValue(Object obj, Object item)

public static void
main(String[]
array of property and xml configuration filenames or Resources.
args
)

Run the XML configurations as a main application.

private Object
private Object
private Object
private Class<T>
private Object
private void
put(Object obj, XmlParser.Node node)

private Object
private void
set(Object obj, XmlParser.Node node)

public void
setIdMap(Map<K, V> map)

public void
setProperties(Map<K, V> map)

private Object
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

__parserback to summary
private static XmlParser __parser
__primitiveHoldersback to summary
private static Class<T>[] __primitiveHolders
__primitivesback to summary
private static Class<T>[] __primitives
_configback to summary
private XmlParser.Node _config
_idMapback to summary
private Map<K, V> _idMap
_propertyMapback to summary
private Map<K, V> _propertyMap
ZEROback to summary
private static final Integer ZERO

Constructor Detail

XmlConfigurationback to summary
public XmlConfiguration(URL configuration) throws SAXException, IOException

Constructor. Reads the XML configuration file.

XmlConfigurationback to summary
public XmlConfiguration(String configuration) throws SAXException, IOException

Constructor.

Parameters
configuration:String

String of XML configuration commands excluding the normal XML preamble. The String should start with a "

XmlConfigurationback to summary
public XmlConfiguration(InputStream configuration) throws SAXException, IOException

Constructor.

Parameters
configuration:InputStream

An input stream containing a complete e.g. configuration file

Method Detail

callback to summary
private Object call(Object obj, XmlParser.Node node) throws Exception
configureback to summary
public void configure(Object obj) throws Exception

Configure an object. If the object is of the approprate class, the XML configuration script is applied to the object.

Parameters
obj:Object

The object to be configured.

configureback to summary
public Object configure() throws Exception

Configure an object. If the configuration has an ID, an object is looked up by ID and it's type check. Otherwise a new object is created.

Returns:Object

The newly created configured object.

configureback to summary
private void configure(Object obj, XmlParser.Node cfg, int i) throws Exception
getback to summary
private Object get(Object obj, XmlParser.Node node) throws Exception
getIdMapback to summary
public Map<K, V> getIdMap()
getPropertiesback to summary
public Map<K, V> getProperties()
initParserback to summary
private static synchronized void initParser() throws IOException
itemValueback to summary
private Object itemValue(Object obj, Object item) throws Exception
mainback to summary
public static void main(String[] args)

Run 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 XmlConfiguration#setProperties(Map).

Each configuration file on the command line is used to create a new XmlConfiguration instance and the XmlConfiguration#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.

Parameters
args:String[]

array of property and xml configuration filenames or Resources.

newArrayback to summary
private Object newArray(Object obj, XmlParser.Node node) throws Exception
newMapback to summary
private Object newMap(Object obj, XmlParser.Node node) throws Exception
newObjback to summary
private Object newObj(Object obj, XmlParser.Node node) throws Exception
nodeClassback to summary
private Class<T> nodeClass(XmlParser.Node node) throws ClassNotFoundException
propertyObjback to summary
private Object propertyObj(Object obj, XmlParser.Node node) throws Exception
putback to summary
private void put(Object obj, XmlParser.Node node) throws Exception
refObjback to summary
private Object refObj(Object obj, XmlParser.Node node) throws Exception
setback to summary
private void set(Object obj, XmlParser.Node node) throws Exception
setIdMapback to summary
public void setIdMap(Map<K, V> map)
setPropertiesback to summary
public void setProperties(Map<K, V> map)
valueback to summary
private Object value(Object obj, XmlParser.Node node) throws Exception