org.apache.xalan.transformer
Class NodeSorter

java.lang.Object
  extended by org.apache.xalan.transformer.NodeSorter

public class NodeSorter
extends java.lang.Object

This class can sort vectors of DOM nodes according to a select pattern.


Nested Class Summary
(package private)  class NodeSorter.NodeCompareElem
          This class holds the value(s) from executing the given node against the sort key(s).
 
Field Summary
(package private)  XPathContext m_execContext
          Current XPath context
(package private)  java.util.Vector m_keys
          Vector of NodeSortKeys
 
Constructor Summary
NodeSorter(XPathContext p)
          Construct a NodeSorter, passing in the XSL TransformerFactory so it can know how to get the node data according to the proper whitespace rules.
 
Method Summary
(package private)  int compare(NodeSorter.NodeCompareElem n1, NodeSorter.NodeCompareElem n2, int kIndex, XPathContext support)
          Return the results of a compare of two nodes.
(package private)  void mergesort(java.util.Vector a, java.util.Vector b, int l, int r, XPathContext support)
          This implements a standard Mergesort, as described in Robert Sedgewick's Algorithms book.
 void sort(DTMIterator v, java.util.Vector keys, XPathContext support)
          Given a vector of nodes, sort each node according to the criteria in the keys.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_execContext

XPathContext m_execContext
Current XPath context


m_keys

java.util.Vector m_keys
Vector of NodeSortKeys

Constructor Detail

NodeSorter

public NodeSorter(XPathContext p)
Construct a NodeSorter, passing in the XSL TransformerFactory so it can know how to get the node data according to the proper whitespace rules.

Parameters:
p - Xpath context to use
Method Detail

sort

public void sort(DTMIterator v,
                 java.util.Vector keys,
                 XPathContext support)
          throws javax.xml.transform.TransformerException
Given a vector of nodes, sort each node according to the criteria in the keys.

Parameters:
v - an vector of Nodes.
keys - a vector of NodeSortKeys.
support - XPath context to use
Throws:
javax.xml.transform.TransformerException

compare

int compare(NodeSorter.NodeCompareElem n1,
            NodeSorter.NodeCompareElem n2,
            int kIndex,
            XPathContext support)
      throws javax.xml.transform.TransformerException
Return the results of a compare of two nodes. TODO: Optimize compare -- cache the getStringExpr results, key by m_selectPat + hash of node.

Parameters:
n1 - First node to use in compare
n2 - Second node to use in compare
kIndex - Index of NodeSortKey to use for sort
support - XPath context to use
Returns:
The results of the compare of the two nodes.
Throws:
javax.xml.transform.TransformerException

mergesort

void mergesort(java.util.Vector a,
               java.util.Vector b,
               int l,
               int r,
               XPathContext support)
         throws javax.xml.transform.TransformerException
This implements a standard Mergesort, as described in Robert Sedgewick's Algorithms book. This is a better sort for our purpose than the Quicksort because it maintains the original document order of the input if the order isn't changed by the sort.

Parameters:
a - First vector of nodes to compare
b - Second vector of nodes to compare
l - Left boundary of partition
r - Right boundary of partition
support - XPath context to use
Throws:
javax.xml.transform.TransformerException