morten 01/10/18 05:40:44
Modified: java/src/org/apache/xalan/xsltc/dom MultiDOM.java
Log:
Added a node-value iterator to the DOM multiplexer to allow for predicates
in combination with the document() function.
PR: bugzilla 3402
Obtained from: n/a
Submitted by: [EMAIL PROTECTED]
Reviewed by: [EMAIL PROTECTED]
Revision Changes Path
1.9 +86 -5
xml-xalan/java/src/org/apache/xalan/xsltc/dom/MultiDOM.java
Index: MultiDOM.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/dom/MultiDOM.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- MultiDOM.java 2001/10/05 09:47:56 1.8
+++ MultiDOM.java 2001/10/18 12:40:44 1.9
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: MultiDOM.java,v 1.8 2001/10/05 09:47:56 morten Exp $
+ * @(#)$Id: MultiDOM.java,v 1.9 2001/10/18 12:40:44 morten Exp $
*
* The Apache Software License, Version 1.1
*
@@ -73,6 +73,7 @@
import org.apache.xalan.xsltc.TransletOutputHandler;
import org.apache.xalan.xsltc.TransletException;
import org.apache.xalan.xsltc.runtime.Hashtable;
+import org.apache.xalan.xsltc.runtime.BasisLibrary;
public final class MultiDOM implements DOM {
private static final int NO_TYPE = DOM.FIRST_TYPE - 2;
@@ -86,6 +87,8 @@
private Hashtable _documents = new Hashtable();
+ private int _currentDOM = 0;
+
private final class AxisIterator implements NodeIterator {
// constitutive data
private final int _axis;
@@ -108,15 +111,16 @@
public NodeIterator setStartNode(final int node) {
_mask = node & SET;
+ int dom = _currentDOM = node >>> 24;
// consider caching these
if ((_type == NO_TYPE) || (_type == DOM.ELEMENT)) {
- _source = _adapters[node>>>24].getAxisIterator(_axis);
+ _source = _adapters[dom].getAxisIterator(_axis);
}
else if (_axis == Axis.CHILD) {
- _source = _adapters[node>>>24].getTypedChildren(_type);
+ _source = _adapters[dom].getTypedChildren(_type);
}
else {
- _source =
_adapters[node>>>24].getTypedAxisIterator(_axis,_type);
+ _source = _adapters[dom].getTypedAxisIterator(_axis,_type);
}
_source.setStartNode(node & CLR);
return this;
@@ -161,6 +165,83 @@
} // end of AxisIterator
+ /**************************************************************
+ * This is a specialised iterator for predicates comparing node or
+ * attribute values to variable or parameter values.
+ */
+ private final class NodeValueIterator extends NodeIteratorBase {
+
+ private NodeIterator _source;
+ private String _value;
+ private boolean _op;
+ private final boolean _isReverse;
+ private int _returnType = RETURN_PARENT;
+
+ public NodeValueIterator(NodeIterator source, int returnType,
+ String value, boolean op) {
+ _source = source;
+ _returnType = returnType;
+ _value = value;
+ _op = op;
+ _isReverse = source.isReverse();
+ }
+
+ public boolean isReverse() {
+ return _isReverse;
+ }
+
+ public NodeIterator cloneIterator() {
+ try {
+ NodeValueIterator clone = (NodeValueIterator)super.clone();
+ clone._isRestartable = false;
+ clone._source = _source.cloneIterator();
+ clone._value = _value;
+ clone._op = _op;
+ return clone.reset();
+ }
+ catch (CloneNotSupportedException e) {
+ BasisLibrary.runTimeError("Iterator clone not supported.");
+ return null;
+ }
+ }
+
+ public NodeIterator reset() {
+ _source.reset();
+ return resetPosition();
+ }
+
+ public int next() {
+
+ int node;
+ while ((node = _source.next()) != END) {
+ String val = getNodeValue(node);
+ if (_value.equals(val) == _op) {
+ if (_returnType == RETURN_CURRENT)
+ return returnNode(node);
+ else
+ return returnNode(getParent(node));
+ }
+ }
+ return END;
+ }
+
+ public NodeIterator setStartNode(int node) {
+ if (_isRestartable) {
+ _source.setStartNode(_startNode = node);
+ return resetPosition();
+ }
+ return this;
+ }
+
+ public void setMark() {
+ _source.setMark();
+ }
+
+ public void gotoMark() {
+ _source.gotoMark();
+ }
+ }
+
public MultiDOM(DOM main) {
_size = INITIAL_SIZE;
_free = 1;
@@ -236,7 +317,7 @@
public NodeIterator getNodeValueIterator(NodeIterator iterator, int type,
String value, boolean op) {
- return _adapters[0].getNodeValueIterator(iterator, type, value, op);
+ return(new NodeValueIterator(iterator, type, value, op));
}
public NodeIterator getNamespaceAxisIterator(final int axis, final int
ns) {
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]