<?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure 1.1//EN" "http://jetty.mortbay.org/configure_1_1.dtd"> <Configure class="packagename.classname"> <!-- class specified here--> <!-- Configure clauses here --> </Configure>The following examples will leave out the XML headers for clarity.
The XML file is applied to an object, which must an instance of the class named in the
Configure
element. For Jetty configuration, the file is applied to an
instance of org.mortbay.jetty.Server (or org.mortbay.jetty.servlet.WebApplicationContext for
web-jetty.xml).
Set Element
An attribute set method may be called on the configure object with a Set
elements. The name
element attribute identifies the object attribute to be set. The content of the element is used as the value to set:
<Set name="attrName">value</Set>This is equivalent to the java code
object.setAttrName(value);
.
A best effort attempt is made to convert the string value to the required type of the Set. Alternately
a a type attribute may be specified
<Set name="doubleAttrName" type="double">1.2</Set>Types understood are: String, Character, Short, Byte, Integer, Long, Boolean, Float, Double, char, short, byte, int, long, boolean, float, double, URL, InetAddress and InetAddrPort. For types other than these, a
New
element should be used (see below).
Call Element
A call to an arbitrary method of the config object can be made with a Call
element.
The name
element attribute identifies the method and the content of the element can be zero or more Arg
elements that provide the arguements to the call:
<Call name="methodName"> <Arg type="int">1</Arg> <Arg type="String">value2</Arg> </Call>This is equivalent to the java code
object.methodName(Integer.parseInt("1"),"value2");
. The values of the Arg
elements are treated as a String if no type is specified. Arbitrary
argument types can be passed using a New
element as the argument value.
If the method call returns an object, it becomes the configuration object within the bounds of the
Call
element. After the last argument element Set
, Call
and
Put
elements can be included to act on the returned object:
<Call name="methodName"> <Arg>value</Arg> <Set name="attr">value</Set> <Call name="method"/> </Call>This is equivalent to the java code:
Object tmp = object.methodName("value"); tmp.setAttr("value"); tmp.method();The
Call
elements may be nested to an arbitrary depth:
<Call name="method1"> <Call name="method2"> <Call name="method3"> </Call> </Call> </Call>Which is equivalent to the java code
object.method1().method2().method3()
.
If a Call
element has both a name and class attribute, it is treated as a call to
a static method.
New Element
Values for Set
and Arg
elements may be supplied by a nested
New
element:
<Call name="methodName"> <Arg><New class"MyClass1"/></Arg> <Set name="attr"><New class="MyClass2"/></Set> </Call>Which is equivalent to the java code
object.methodName(new MyClass1()).setAttr(new MyClass2())
.
The New
element may itself contain Arg
elements to be
passed to the new call and Set
, Call
and
Put
elements which act on the newly created object:
<Set name="attr1"> <New class="MyClass1"> <Arg>value</Arg> <Set name="attr2"><New class="MyClass2"/></Set> </New> </Set>Which is equivalent to the java code:
Object tmp=new MyClass1("value"); tmp.setAttr2(new MyClass2()); object.setAttr1(tmp);
Put Element
A call to a method witht the signature Object put(Object name, Object value)
can be called with the Put
element:
<Put name="name">value</Put>Which is equivalent to the java code
object.put("name","value");
.
SystemProperty Element
Java System Properties can be looked up and used as values in Set
, Arg
and
Put
elements. This can be used to parameterize config files:
<Set name="resourceBase"> <SystemProperty name="jetty.home" default="."/>/docroot/ </Set>