BACK | INDEX | EXIT | NEXT |
$JETTY_HOME/demo/webapps/jetty/WEB-INF/web-jetty.xmlThe format provides the ability to express Java API calls declaratively. That is, one can specify in XML syntax the creation of Java objects and method calls upon them.
$JETTY_HOME/etc/demo.xml.
<?xml version="1.0" encoding="ISO-8859-1"?> <Configure class="packagename.classname"> <!-- Configure clauses here --> </Configure> |
Example: File format for Jetty XML |
The contents of the file is applied to an object, which must be an instance
of the class named in the Configure
element. In the case
of Jetty, the file is applied to an instance of org.mortbay.jetty.Server
(or
org.mortbay.jetty.servlet.WebApplicationContext for web-jetty.xml
).
An attribute set method call on an object is specified with a
Set
statement. The name
element attribute
identifies the object attribute to be set. The content of the element
is used as the value to set. The name of the method call to perform is
formed by converting the first letter of the object attribute name to uppercase,
and prepending it with the word "set" :
<Set name="attrName">value</Set> |
<----
is eqivalent to ----> |
object |
A best effort attempt is made to convert
the string value to the required type of the Set. Alternately,
a type attribute may be specified: <Set name="doubleAttrName" type="double">1.2</Set>
Example: using a type specifier
New
element should be used.
A call to an arbitrary method of an 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 arguments to the call:
<Call name="methodName"> |
<---- is eqivalent to ----> |
|
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 subject of all
further configuration within the bounds of the Call
element.
After the last Arg
element, Set
,
Call
and Put
elements
can be included to act on the returned object:
<Call name="methodName"> |
<---- is eqivalent to ----> |
Object tmp = object.methodName("value"); |
Call
elements may be nested to an arbitrary
depth:
<Call name="method1"> |
<---- is eqivalent to ----> |
|
Example:
nested Call Elements If a
Call
element has both a name and class
attribute, it is treated as a call to a static method:
<Call name="method1" |
<----
is eqivalent to ----> |
package.classname1 |
To create an instance of a class, use the New
element. This can only be done as the values for Set
and
Arg
elements. For example:
<Call name="methodName"> |
<----
is eqivalent to ----> |
|
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"> |
<---- is eqivalent to ----> |
Object tmp = |
Java System Properties can be looked up and used as values
in Set
, Arg
and Put
elements. This can be used to parameterize
configuration files as in:
<Set name="resourceBase">
<SystemProperty name="jetty.home" default="."/>/docroot/
</Set>
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> |
<----
is eqivalent to ----> |
object.put("name","value"); |
XML Example: an entire Jetty XML configuration file |
BACK | INDEX | EXIT | NEXT |