FileDocCategorySizeDatePackage
NodeSortRecord.javaAPI DocJava SE 6 API8339Tue Jun 10 00:22:32 BST 2008com.sun.org.apache.xalan.internal.xsltc.dom

NodeSortRecord

public abstract class NodeSortRecord extends Object
Base class for sort records containing application specific sort keys

Fields Summary
public static final int
COMPARE_STRING
public static final int
COMPARE_NUMERIC
public static final int
COMPARE_ASCENDING
public static final int
COMPARE_DESCENDING
private static final Collator
DEFAULT_COLLATOR
A reference to a collator. May be updated by subclass if the stylesheet specifies a different language (will be updated iff _locale is updated).
protected Collator
_collator
A reference to the first Collator
protected Collator[]
_collators
protected Locale
_locale
A locale field that might be set by an instance of a subclass.
protected CollatorFactory
_collatorFactory
protected SortSettings
_settings
private DOM
_dom
private int
_node
private int
_last
private int
_scanned
private Object[]
_values
Constructors Summary
public NodeSortRecord(int node)
This constructor is run by a call to ClassLoader in the makeNodeSortRecord method in the NodeSortRecordFactory class. Since we cannot pass any parameters to the constructor in that case we just set the default values here and wait for new values through initialize().

 // Contains Comparable  objects

                                                     
       
	_node = node;
    
public NodeSortRecord()

        this(0);
    
Methods Summary
public final intcompareDocOrder(com.sun.org.apache.xalan.internal.xsltc.dom.NodeSortRecord other)

	return _node - other._node;
    
public intcompareTo(com.sun.org.apache.xalan.internal.xsltc.dom.NodeSortRecord other)
Compare this sort element to another. The first level is checked first, and we proceed to the next level only if the first level keys are identical (and so the key values may not even be extracted from the DOM) !!!!MUST OPTIMISE - THIS IS REALLY, REALLY SLOW!!!!

	int cmp, level;
        int[] sortOrder = _settings.getSortOrders();
        int levels = _settings.getSortOrders().length;
        int[] compareTypes = _settings.getTypes();

	for (level = 0; level < levels; level++) {
	    // Compare the two nodes either as numeric or text values
	    if (compareTypes[level] == COMPARE_NUMERIC) {
		final Double our = numericValue(level);
		final Double their = other.numericValue(level);
		cmp = our.compareTo(their);
	    }
	    else {
		final Comparable our = stringValue(level);
		final Comparable their = other.stringValue(level);
		cmp = our.compareTo(their);
	    }
	    
	    // Return inverse compare value if inverse sort order
	    if (cmp != 0) {
		return sortOrder[level] == COMPARE_DESCENDING ? 0 - cmp : cmp;
	    }
	}
	// Compare based on document order if all sort keys are equal
	return(_node - other._node);
    
public abstract java.lang.StringextractValueFromDOM(com.sun.org.apache.xalan.internal.xsltc.DOM dom, int current, int level, com.sun.org.apache.xalan.internal.xsltc.runtime.AbstractTranslet translet, int last)
Extract the sort value for a level of this key.

public java.text.Collator[]getCollator()
Returns the array of Collators used for text comparisons in this object. May be overridden by inheriting classes

	return _collators;
    
public final intgetNode()
Returns the node for this sort object

	return _node;
    
public final voidinitialize(int node, int last, com.sun.org.apache.xalan.internal.xsltc.DOM dom, com.sun.org.apache.xalan.internal.xsltc.dom.SortSettings settings)
This method allows the caller to set the values that could not be passed to the default constructor.

	_dom = dom;
	_node = node;
	_last = last;
        _settings = settings;

        int levels = settings.getSortOrders().length;
	_values = new Object[levels];
  
        String colFactClassname = null;
        try {
            // -- W. Eliot Kimber (eliot@isogen.com)
            colFactClassname = 
                System.getProperty("com.sun.org.apache.xalan.internal.xsltc.COLLATOR_FACTORY");
        }
        catch (SecurityException e) {
            // If we can't read the propery, just use default collator
        }

        if (colFactClassname != null) {
            try {
                Object candObj = ObjectFactory.findProviderClass(
                    colFactClassname, ObjectFactory.findClassLoader(), true);
                _collatorFactory = (CollatorFactory)candObj;
            } catch (ClassNotFoundException e) {
                throw new TransletException(e);
            }
            Locale[] locales = settings.getLocales();
            _collators = new Collator[levels];
            for (int i = 0; i < levels; i++){
                _collators[i] = _collatorFactory.getCollator(locales[i]);
            }
            _collator = _collators[0];
        } else {
    	    _collators = settings.getCollators();
            _collator = _collators[0];
        }
    
private final java.lang.DoublenumericValue(int level)

	// Get value from our vector if possible
	if (_scanned <= level) {
            AbstractTranslet translet = _settings.getTranslet();

	    // Get value from DOM if accessed for the first time
	    final String str = extractValueFromDOM(_dom, _node, level,
						   translet, _last);
	    Double num;
	    try {
		num = new Double(str);
	    }
	    // Treat number as NaN if it cannot be parsed as a double
	    catch (NumberFormatException e) {
		num = new Double(Double.NEGATIVE_INFINITY);
	    }
	    _values[_scanned++] = num;
	    return(num);
	}
	return((Double)_values[level]);
    
private final java.lang.ComparablestringValue(int level)
Get the string or numeric value of a specific level key for this sort element. The value is extracted from the DOM if it is not already in our sort key vector.

    	// Get value from our array if possible
    	if (_scanned <= level) {
            AbstractTranslet translet = _settings.getTranslet();
            Locale[] locales = _settings.getLocales();
            String[] caseOrder = _settings.getCaseOrders();

    	    // Get value from DOM if accessed for the first time
    	    final String str = extractValueFromDOM(_dom, _node, level,
    						   translet, _last);
    	    final Comparable key =
                StringComparable.getComparator(str, locales[level],
                                               _collators[level],
                                               caseOrder[level]);
    	    _values[_scanned++] = key;
    	    return(key);
    	}
    	return((Comparable)_values[level]);