Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Syntax

Tip

IOC = inversion of control
DI = dependency injection

Jetty.xml IOC/DI has long been available even before spring sprung (smile) (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:
Code Block

<New id="foo" class="com.acme.Foo"/>
// equivalent to:
// com.acme.Foo foo = new com.acme.Foo();
// instantiates with the default constructor then persists the object

<Ref id="foo"/>
// references that object

<Call id="bar" class="com.acme.MyStaticObjectFactory" name="createObject"/>
// equivalent to:
// com.acme.MyStaticObjectFactory.createObject();
// call the static method and the returned object is persisted

<Configure id="Server" class="org.mortbay.jetty.Server">
// ..
// configure this object
// tags like Set, Get, and Call are addressed to this object
</Configure>
/** The id is persisted in a hashmap so that more than one jetty.xml can configure the same object.
    e.g java -jar start.jar etc/jetty.xml etc/jetty-ssl.xml etc/jetty-plus.xml */

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.

...

Jetty xml files are parsed by the org.mortbay.util.XmlConfiguration class using the configure.dtd descriptor.

Anchor
Configure
Configure

<Configure> Element

This is the root element that specifies the class of object that is to be configured:

...

The Configure element can contain the New, Set, _Put, Call or Ref elements.

Anchor
Set
Set

<Set> Element

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. 

...

Code Block
xml
xml
<Set name="xyz">
 . . .
</Set>

Anchor
Get
Get

<Get> Element

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 with a class attribute is treated as a static get method or field.

Anchor
Put
Put

<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.

Code Block
xml
xml
  <Put name="admin">admin</Put>

Anchor
Call
Call

<Call> Element

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.

...

Panel
Code Block
xml
xml
borderWidth0
<Call class="com.acme.Foo" name="setString">
  <Arg>somestring</Arg>
</Call>

Is equivalent to:

Code Block
borderWidth0
  com.acme.Foo.setString("somestring");

Anchor
Arg
Arg

<Arg> Element

This element defines a positional argument for the Call element.  The optional type attribute can force the type of the value.

...

The Ref tag here points to a previously created object with an id parameter.

Anchor
New
New

<New> Element

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.

...

Panel
Code Block
xml
xml
<New id="myobject" class="com.acme.MyClass">
  <Arg>value1</Arg><Set name="Test">Value2</Set>
</New>

This is equivalent to:

Code Block
Object o = new com.acme.MyClass("value1");
o.setTest("value2");

Anchor
Ref
Ref

<Ref> Element

This element allows a previously created object to be referenced by unique name.

...

Alternatively, the Ref element can be used as the value of an Arg or Set element:

Code Block
xml
xml
  <Set name="someMethod"><Ref id="myobj"/></Set>

Anchor
Array
Array

<Array> Element

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.

Panel
Code Block
xml
xml
borderWidth0
<Array type="java.lang.String">
  <Item>value0</Item>
  <Item><New class="java.lang.String"><Arg>value1</Arg></New></Item>
</Array>

This is equivalent to

Code Block
borderWidth0
String[] a = new String[]{"value0", new String("value1")};

Anchor
Map
Map

<Map> Element

This element allows the creation of a new HashMap and to populate it with (key,value) pairs.

Panel
Code Block
xml
xml
borderWidth0
<Map>
  <Entry>
   <Item>keyName</Item>
   <Item><New class="java.lang.String"><Arg>value1</Arg></New></Item>
  </Entry>
</Map>

This is equivalent to

Code Block
borderWidth0
java.util.Map map = new java.util.HashMap();
map.put("keyName", "value1"};

Anchor
Item
Item

<Item> Element

This element defines an entry for the Array or Map Entry elements. The optional type attribute can force the type of the value.

...

Code Block
xml
xml
<Item>
  <New class="org.mortbay.jetty.nio.SelectChannelConnector">
    <Set name="port">8080</Set>
    <Set name="maxIdleTime">30000</Set>
    <Set name="Acceptors">10</Set>
 </New>
</Item>

Anchor
SystemProperty
SystemProperty

<SystemProperty> Element

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.
   

...

Contact the core Jetty developers at www.webtide.com
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