FileDocCategorySizeDatePackage
MultipleNodeCounter.javaAPI DocJava SE 5 API3169Fri Aug 26 14:55:40 BST 2005com.sun.org.apache.xalan.internal.xsltc.dom

MultipleNodeCounter

public abstract class MultipleNodeCounter extends NodeCounter
author
Jacek Ambroziak
author
Santiago Pericas-Geertsen

Fields Summary
private DTMAxisIterator
_precSiblings
Constructors Summary
public MultipleNodeCounter(Translet translet, DOM document, DTMAxisIterator iterator)


      
			           
	super(translet, document, iterator);
    
Methods Summary
public java.lang.StringgetCounter()

	if (_value != Integer.MIN_VALUE) {
	    return formatNumbers(_value);
	}

	IntegerArray ancestors = new IntegerArray();

	// Gather all ancestors that do not match from pattern
	int next = _node;
	ancestors.add(next);		// include self
	while ((next = _document.getParent(next)) > END && 
	       !matchesFrom(next)) {
	    ancestors.add(next);
	}

	// Create an array of counters
	final int nAncestors = ancestors.cardinality();
	final int[] counters = new int[nAncestors]; 
	for (int i = 0; i < nAncestors; i++) {
	    counters[i] = Integer.MIN_VALUE;
	}

	// Increment array of counters according to semantics
	for (int j = 0, i = nAncestors - 1; i >= 0 ; i--, j++) {
	    final int counter = counters[j];
	    final int ancestor = ancestors.at(i);

	    if (matchesCount(ancestor)) {
		_precSiblings.setStartNode(ancestor);
		while ((next = _precSiblings.next()) != END) {
		    if (matchesCount(next)) {
			counters[j] = (counters[j] == Integer.MIN_VALUE) ? 1 
			    : counters[j] + 1;		
		    }
		}
		// Count the node itself
		counters[j] = counters[j] == Integer.MIN_VALUE
		    ? 1 
		    : counters[j] + 1;	
	    }
	}
	return formatNumbers(counters);
    
public static com.sun.org.apache.xalan.internal.xsltc.dom.NodeCountergetDefaultNodeCounter(com.sun.org.apache.xalan.internal.xsltc.Translet translet, com.sun.org.apache.xalan.internal.xsltc.DOM document, com.sun.org.apache.xml.internal.dtm.DTMAxisIterator iterator)

	return new DefaultMultipleNodeCounter(translet, document, iterator);
    
public com.sun.org.apache.xalan.internal.xsltc.dom.NodeCountersetStartNode(int node)

	_node = node;
	_nodeType = _document.getExpandedTypeID(node);
	_precSiblings = _document.getAxisIterator(PRECEDINGSIBLING);
	return this;