All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.enhydra.xml.lazydom.package.html Maven / Gradle / Ivy

The newest version!





    package: org.enhydra.xml.lazydom - DOM used when the majority of the DOM is never modified.
    
    
    


org.enhydra.xml.lazydom implements a DOM used for templates that is expanded in a lazy manner. It is developed for XMLC, where the majority of the DOM is never modified.

The are really two DOMs for a given document instance: the template representation, which is shared by all instances and the expanded representation, which contains DOM Node objects that have been accessed via the standard DOM API. Untouched nodes are left unexpanded (virtual). This maps nicely to the standard XMLC usage of directly accessing inner subtrees of the DOM via access methods. A subtree can be expanded without expanding its parent, so this usage is very efficient. A lazy-DOM aware formatter traverses the document without expanding nodes.

Each node in the template is assigned a unique numeric node id, which is carried over to the instance DOM node when instantiated. The node id is used to index a table pointing into the template DOM and table of instanced nodes in the instance-DOM.

The Lazy DOM is implemented as DOM Node objects derived from a the Xerces DOM implementation. Each derived node implements LazyNode and overrides the methods that access or modify the DOM tree links. These methods will cause the linked nodes to be expanded on first access. The parent, children, and attributes can be expanded independently. To keep things simple, all of the children of a node will be expanded when one is accessed. The attributes of an element are also expanded as a group. However, this expansion is not recursive, only the immediate linked nodes are expanded. Only Element nodes can be expanded without their parent being expanded.

This DOM also stores pre-formatted text for nodes. The pre-formatted text is either CharacterData text with entity references expanded or the opening tags of an Element, including attributes. The use of pre-formatted text avoids expensive character-level operations when outputing a DOM.

Constructing derived DOMs based on the Lazy DOM is straight-forward. A document class should extend LazyDocument and override

LazyElement createElement(int nodeId) throws DOMException;
The derived Element classes should extend LazyElement and provide a constructor that passes through a template. All Lazy DOM nodes have a single constructor that takes both a a template of the same type and the parameters needed to construct the node without a template. Either the template or the other arguments should be null. This approached is used to make it easier to build derived nodes.





© 2015 - 2025 Weber Informatics LLC | Privacy Policy