[jdom-interest] Code submision: JDOM2 the dual tree implementation...

James Strachan james at metastuff.com
Thu Nov 23 10:50:28 PST 2000


I'm about to post a full implementation of the 2 tree JDOM for your review.
I've noticed that patch submissions often take a while to get though to the
list, so I thought I'd introduce it first ;-) The full source code will be a
few hours later...
 
The effect on the API is suprisingly minimal. The following standard JDOM
objects are now immutable, so can be shared across any Element and Document
instances..
    Attribute
    Entity
    Comment
    CDATA
 
There are new doubly linked, mutable versions of these...
    AttributeNode
    EntityNode
    CommentNode
    CDATANode
 
Each of these new classes implements the new Node interface which as a
method
    public interface Node {
        public Element getParent();    
    }
 
There were little typesafe methods on Element for Comment/Entity/CDATA.
Though I've added a couple of typesafe helper methods for Attribute on
Element...
 
    Element element = ...;
 
    // immutable
    Attribute attribute = element.getAttribute( "foo" );
 
    // mutable
    AttributeNode attributeNode = element.getAttributeNode( "foo" );
    attributeNode.setValue( "new value" );
    Element parent = attributeNode.getParent();
 
None of the outputters or adapters are affected by any of these changes. The
only other change is in the input package. I've renamed my previously
submitted "SAXFactory" to be "JDOMFactory". This class is now reused with
minimal change in DOMBuilder and SAXBuilder / SAXHandler.
 
There is a new JDOMFactory implementation, which I've called JDOM2Factory
for now (horrible name) which is used to build the full doubly linked tree.
 
So here's a full implementation of the 2 level tree approach for discussion.
Small impact on the API, big impact in the range of facilities offered to
developers. There are now 2 levels from which people may make their own
custom builders depending on the tradeoffs they want to make.
 
Assuming a 'JDOMFactory' of some kind was already added to standard JDOM,
the impact of this proposal is 6 new classes (1 new Node interface, 1 extra
JDOM factory and 4 mutable implementations of leaf nodes).
 
I think this makes the API richer and more powerful with minimal added
complexity.
 
<aside>
The current Element.getAttributeNode() method returns null if an Attribute
is found but it is not an instanceof AttributeNode. It might make sense to
lazily convert from immutable Attribute to mutable AttributeNode then the
following will always work providing an Attribute exists...
 
    element.getAttributeNode( "foo" ).setValue( "bar" );
</aside>
 
J.
 
James Strachan
=============
email: james at metastuff.com <mailto:james at metastuff.com> 
web: http://www.metastuff.com <http://www.metastuff.com> 



If you are not the addressee of this confidential e-mail and any
attachments, please delete it and inform the sender; unauthorised
redistribution or publication is prohibited. Views expressed are those of
the author and do not necessarily represent those of Citria Limited.



More information about the jdom-interest mailing list