How is it different from DOM?
It can be used to build an object tree, much like DOM. With DOM however the
nodes of the object model are instances of generic classes such as Node,
Element, Text, etc. Arbor builds an object tree from user defined classes.
This provides type safety and gives the developer a place to implement
custom validation logic.
The resulting structure ends up being easier to work with, and may also be
relevant outside of XML processing.
How does it work?
Introspection is used to match XML element and attributes to method names.
A convention must be followed when defining node classes. This concept
was basically stolen from Ant's
handling of taskdefs.
Generally, each element in the XML document is represented by a bean instance.
Arbor delegates the responsibility of defining allowable attributes and child
elements to each bean.
When Arbor is called, it is passed an XML input source, and an instance of a bean
that will represent the root level element in the XML document. If the element has
children elements or attributes, the appropriate methods are called on the bean.
What conventions do my beans need to follow?
When an attribute is encountered in the XML source, the current bean's set accessor
method is called with the value of the attribute as a parameter. The accessor method
is selected based on the name of the attribute. Type conversion is done based on the
parameter type of the selected accessor method.
When an child element is encountered in the XML source, a create method is called on
the current bean. The create method is selected based on the name of the attribute.
(an element named <billingAddress/> will cause the method createBillingAddress to be called)
The object that is returned by the create method, becomes the new current element.
There is one exception to the above two rules. If an element is encountered and there
is no matching create method, then Arbor will attempt to treat the body text of the
element as an attribute of the current bean. The following two sections of XML will
produce the same structure, as long as there is no createBar method on the bean that
represents foo.
Though required by the JavaBeans spec, Arbor does not need a no argument constructor.
Creation of beans is always delegated to the create methods.
What's the down side?
Well, it depends on your application. For some usages, Arbor would not be the right
choice. This is because Arbor performs it's actons based on the contence of the source
XML document, not what the application needs. Arbor takes all the data in a document
and feeds it into a set of beans. This is opposite of other approaches in which
a programmer writes code to extract needed information from XML. Arbor can save a lot of
tedious and error-prone development, but it makes your program unable to process documents
with unexpected elements or attributes.
For good or bad, there is a level of validation built into Arbor.