The SAXalizer class is used to deserialize a tree of XML tags into a tree of
Java objects. Please note that this class is over 5 years old and is due for
a very major sandblasting - many comments are extremely out of date, in
addition to its using the extremely obsolete SAX1 interface. See wiki for
general comments on roadmap for this dinosaur.
Note from January '06 - this code is just getting worse and worse! More than
anything it exemplifies the all-engulphing "ball of wax" pattern where poor
design in one area simply proliferates and sucks more and more neighbouring
infrastructure down with it. Will there EVER be time to fix it... or replace
it with JiBX or comparable mature solution. Will the SAXalizer reach it's 6th
birthday alive??!
Every class that wishes to be SAXalized must implement (at least) the
interface SAXalizable, which allows the class to report the set methods it
supports for attaching subobjects to itself that correspond to XML subtags.
It may also support the interface SAXalizableAttrs in order to receive the
attributes of the XML tag it corresponds to -- if it does not, any such
attributes are thrown away.
Note that the class of a SAXalizing object may also implement the
DeSAXalizable interface. In this case, if an existing subobject is present
and can be delivered through the interface, SAXalizing subobjects will be
delivered onto the existing subobject rather than a new one created afresh.
Two "helper" base classes are called GenericSAXImpl, which allows a Java
class to store arbitary XML subtags, and SAXalizableExtraAttrs, which allows
it to store arbitrary XML attributes. Note that GenericSAXImpl itself
implements SAXalizableExtraAttrs. With these two helper classes, the line is
blurred between serializable Java objects and objects representing a DOM-like
document structure. We can even have a class which uses both styles at once;
implementing named methods for particular tags it is interested in, and
storing the rest in a "pool" of GenericSAXImpl.
Note that a useful modification of the standard use of SAXAccessMethodSpec to
specify a set method is to use "*" as the parameter for the set method
argument type. This will instruct the SAXalizer to use the exact tag name of
any subtags as the argument to the Class.forName() reflection method; the
class thus referenced must a) exist, and b) be a subclass of the actual
argument type of the set method specified.
At the bottom (err, top) of the XML tag tree we stop using the SAXalizable
interface, since there will be no further subobjects to deliver. Instead, we
use a scheme that externally encodes these object's leafiness so that we can
efficiently use primitive Java types to represent them such as String and
Date. A global registry class called SAXLeafParser stores a hashtable of
Class objects to mechanisms which can parse that type from a String. If the
SAXalizer discovers the argument type supplied through the SAXalizable
interface for a set method is registered with the SAXLeafParser, it uses that
mechanism for parsing any character data attached to the tag into a Java
object rather than continuing creating SAXalizable objects.
Note that any character data arriving for non--leaf nodes is currently
ignored. Should we ever do any true DOM-style parsing using the SAXalizer, a
new interface type will be required to deliver it.
|