private support for your internal/customer projects ... custom extensions and distributions ... versioned snapshots for indefinite support ... scalability guidance for your apps and Ajax/Comet projects ... development services from 1 day to full product delivery
Syntax
|
IOC = inversion of control |
Jetty.xml IOC/DI has long been available even before spring sprung
(springframework)
Almost anything you can do programmatically can be done on jetty.xml, so long as it
does not require loops.
The entire functionality is covered by two classes:
1. org.mortbay.xml.XmlConfiguration
2. org.mortbay.xml.XmlParser
Attributes
id
This simply means that you want to reference an object for later use.
Jetty persists the object in a java.util.HashMap<String,Object>
Most common use cases:
class
The value is the fully qualified class name of an object.
Used in three tags:
1. #Configure
2. #New
3. #Call
name
Generally used to specify the name of the property/method of an object.
Also used to specify the name of a System property
Used on the ff tags:
1. #Set
2. #Get
3. #Call
4. #SystemProperty
type
Used to specify the type of an #Array tag.
The value is the fully qualified class name of an object.
Used only in one tag:
1. #Array
default
Used to specify the default value of a System property if it does not exist.
Used only in one tag:
1. #SystemProperty
configure.dtd
This is the document type descriptor which specifies a straightforward mapping of xml elements to the java api.
The first lines in a jetty xml configuration file must reference this dtd as follows:
Java objects are configured by a sequence of <New>, <Set>, <Put> and <Call> elements. Here is a small example to give you the flavour of it:
<Set name="Test">value</Set> |
== |
obj.setTest("value"); |
<Put name="Test">value</Put> |
== |
obj.put("Test","value"); |
<Call name="test"><Arg>value</Arg></Call> |
== |
obj.test("value"); |
<New class="com.acme.MyStuff"><Arg/></New> |
== |
new com.acme.MyStuff(); |
Values are coerced to match method arguments on a best effort approach, but explicit types may also be specified.
Jetty xml files are parsed by the org.mortbay.util.XmlConfiguration class using the configure.dtd descriptor.
<Configure> Element
This is the root element that specifies the class of object that is to be configured:
Alternatively, if the object already exists and has an id, then it can be referenced in the Configure element like so:
The Configure element can contain the New, Set, _Put, Call or Ref elements.
More Examples
<Set> Element
Sets an object property. One argument
Used in conjunction with #Configure, #New, #Ref, #Call.
This element maps to a call to a set method on the current object. The name and optional type attributes are used to select the set method. If the name given is xxx, then a setXxx method is used, or the xxx field is used of setXxx cannot be found.
A Set element can contain value text and/or the value elements Call, New and SystemProperty. If no value type is specified, then white space is trimmed out of the value. If it contains multiple value elements they are added as strings before being converted to any specified type.
A Set with a class attribute is treated as a static set method invocation.
More Examples
<Get> Element
Returns the object's property.
This element maps to a call to a get method of field on the current object. The name attribute is used to select the get method. If the name given is xxx, then a getXxx method is used, or the xxx field is used of setXxx cannot be found.
A Get element can contain Set, Put and/or Call elements which act on the object returned by the get call.
A Get with a class attribute is treated as a static get method or field.
More Examples
<Put> Element
This element maps to a call to a put method on the current object, which must implement the Map interface. The name attribute is used as the put key and the optional type attribute can force the type of the value.
A Put element can contain value text and/or the value elements Call, New and SystemProperty. If no value type is specified, the white space is trimmed out of the value. If it contains multiple value elements, they are added as strings before being converted to any specified type.
<Call> Element
Calls an object method.
The method could be an instance method or a static method.
This element maps to an arbitrary call to a method on the current object. The name attribute and Arg elements are used to select the method.
A Call element can contain a sequence of Arg elements followed by a sequence of Set, Put and/or Call elements which act on any object returned by the original call:
This is equivalent to:
A Call with a class attribute is treated as a static call:
Is equivalent to:
More Examples
<Arg> Element
An argument of a method or a constructor.
Used in conjunction with #New and #Call.
This element defines a positional argument for the Call element. The optional type attribute can force the type of the value.
An Arg element can contain value text and/or the value elements Call, New and SystemProperty. If no value type is specified, then white space is trimmed out of the value. If it contains multiple value elements they are added as strings before being converted to any specified type.
The Ref tag here points to a previously created object with an id parameter.
More Examples
<New> Element
Equivalent to the "new" in java.
Instantiates an object.
This element allows the creation of a new object as part of a value of a Set, Put or Arg element. The class attribute determines the type of the new object and the contained Arg elements are used to select the constructor for the new object. A New element may have an id parameter which gives a unique name to the object which can be referenced later by Ref elements.
A New element can contain a sequence of Arg elements followed bya sequence of Set, Put and/or Call elements which act on the new object:
This is equivalent to:
More Examples
<Ref> Element
This element allows a previously created object to be referenced by unique name.
A Ref element can contain a sequence of Set, Put and/or Call elements which act on the referenced object:
Alternatively, the Ref element can be used as the value of an Arg or Set element:
<Array> Element
An object array.
This element allows the creation of a new array as part of a value of a Set, Put or Arg element. The type attribute determines the type of the new array and the contained Item elements are used for each element of the array.
This is equivalent to
More Examples
<Map> Element
This element allows the creation of a new HashMap and to populate it with (key,value) pairs.
This is equivalent to
<Item> Element
An element of an array.
Used only in conjuction with #Array
This element defines an entry for the Array or Map Entry elements. The optional type attribute can force the type of the value.
An Item element can contain value text and/or the value elements Call, New and SystemProperty. If no value type is specified, then white space is trimmed out of the value. If it contains multiple value elements they are added as strings before being converted to any specified type.
<SystemProperty> Element
Gets the value of a system property.
This element allows JVM System properties to be retrieved as part of the value of a Set, Put or Arg element. The name attribute specifies the property name and the optional default argument provides a default value.
This is equivalent to: